| 108 | CONFIG ServerConfig; |
| 109 | |
| 110 | int 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 | |
| 159 | static ClientEntry *Clients; |
| 160 | static GameEntry *Games; |
no test coverage detected