MCPcopy Create free account
hub / github.com/TASEmulators/fceux / LoadConfigFile

Function LoadConfigFile

fceux-server/server.cpp:110–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108CONFIG ServerConfig;
109
110int LoadConfigFile(const char *fn)
111{
112 FILE *fp;
113 ServerConfig.Port = ServerConfig.MaxClients = ServerConfig.ConnectTimeout = ServerConfig.FrameDivisor = ~0;
114 if(fp=fopen(fn,"rb"))
115 {
116 char buf[256];
117 while(fgets(buf, 256, fp) != NULL)
118 {
119 if(!strncasecmp(buf,"maxclients",strlen("maxclients")))
120 sscanf(buf,"%*s %d",&ServerConfig.MaxClients);
121 else if(!strncasecmp(buf,"connecttimeout",strlen("connecttimeout")))
122 sscanf(buf,"%*s %d",&ServerConfig.ConnectTimeout);
123 else if(!strncasecmp(buf,"framedivisor",strlen("framedivisor")))
124 sscanf(buf,"%*s %d",&ServerConfig.FrameDivisor);
125 else if(!strncasecmp(buf,"port",strlen("port")))
126 sscanf(buf,"%*s %d",&ServerConfig.Port);
127 else if(!strncasecmp(buf,"password",strlen("password")))
128 {
129 char *pass = 0;
130 sscanf(buf,"%*s %as",&pass);
131 if(pass)
132 {
133 struct md5_context md5;
134 ServerConfig.Password = (uint8 *)malloc(16);
135 md5_starts(&md5);
136 md5_update(&md5,(uint8*)pass,strlen(pass));
137 md5_finish(&md5,ServerConfig.Password);
138 puts("Password required to log in.");
139 }
140 }
141 }
142 }
143 else
144 {
145 printf("Cannot load configuration file %s.\n", fn);
146 return(0);
147 }
148
149 if(~0 == (ServerConfig.Port & ServerConfig.MaxClients & ServerConfig.ConnectTimeout & ServerConfig.FrameDivisor))
150 {
151 puts("Incomplete configuration file");
152 return(0);
153 }
154 //printf("%d,%d,%d\n",ServerConfig.MaxClients,ServerConfig.ConnectTimeout,ServerConfig.FrameDivisor);
155 printf("Using configuration file located at %s\n", fn);
156 return(1);
157}
158
159static ClientEntry *Clients;
160static GameEntry *Games;

Callers 1

mainFunction · 0.85

Calls 3

md5_startsFunction · 0.70
md5_updateFunction · 0.70
md5_finishFunction · 0.70

Tested by

no test coverage detected