42 name =
"Starshatter ";
43 admin_name =
"system";
44 admin_pass =
"manager";
51 session_timeout = 300;
93 strcpy_s(filename,
"server.cfg");
96 ::fopen_s(&f, filename,
"rb");
99 ::fseek(f, 0, SEEK_END);
101 ::fseek(f, 0, SEEK_SET);
103 block =
new(__FILE__,__LINE__) BYTE[blocklen+1];
106 ::fread(block, blocklen, 1, f);
115 Parser parser(
new(__FILE__,__LINE__)
BlockReader((
const char*) block, blocklen));
119 Print(
"ERROR: could not parse '%s'.\n", filename);
125 if (!file_type || file_type->
value() !=
"SERVER_CONFIG") {
126 Print(
"WARNING: invalid '%s' file. Using defaults\n", filename);
144 else if (def->
name()->
value() ==
"admin_name") {
145 GetDefText(instance->admin_name, def, filename);
148 else if (def->
name()->
value() ==
"admin_pass") {
149 GetDefText(instance->admin_pass, def, filename);
152 else if (def->
name()->
value() ==
"game_pass") {
153 GetDefText(instance->game_pass, def, filename);
156 else if (def->
name()->
value() ==
"mission") {
160 else if (def->
name()->
value() ==
"auth_level") {
171 else if (level ==
"standard" || level ==
"std")
174 else if (level ==
"secure")
183 else if (def->
name()->
value() ==
"admin_port") {
185 if (port > 1024 && port < 48000)
186 instance->admin_port = (WORD) port;
189 else if (def->
name()->
value() ==
"lobby_port") {
191 if (port > 1024 && port < 48000)
192 instance->lobby_port = (WORD) port;
195 else if (def->
name()->
value() ==
"game_port") {
197 if (port > 1024 && port < 48000)
198 instance->game_port = (WORD) port;
201 else if (def->
name()->
value() ==
"game_type") {
209 else if (type ==
"private")
216 else if (def->
name()->
value() ==
"poolsize") {
220 else if (def->
name()->
value() ==
"session_timeout") {
225 Print(
"WARNING: unknown label '%s' in '%s'\n",
229 Print(
"WARNING: term ignored in '%s'\n", filename);
247 fopen_s(&f,
"server.cfg",
"w");
249 fprintf(f,
"SERVER_CONFIG\n\n");
250 fprintf(f,
"name: \"%s\"\n", instance->name.
data());
251 fprintf(f,
"admin_name: \"%s\"\n", instance->admin_name.
data());
252 fprintf(f,
"admin_pass: \"%s\"\n", instance->admin_pass.
data());
253 fprintf(f,
"game_pass: \"%s\"\n", instance->game_pass.
data());
255 fprintf(f,
"admin_port: %d\n", instance->admin_port);
256 fprintf(f,
"lobby_port: %d\n", instance->lobby_port);
257 fprintf(f,
"game_port: %d\n", instance->game_port);
259 switch (instance->game_type) {
261 fprintf(f,
"game_type: LAN\n");
265 fprintf(f,
"game_type: private\n");
270 fprintf(f,
"game_type: public\n");
274 switch (instance->auth_level) {
276 fprintf(f,
"auth_level: minimal\n");
281 fprintf(f,
"auth_level: standard\n");
285 fprintf(f,
"auth_level: secure\n");
290 fprintf(f,
"poolsize: %d\n", instance->poolsize);
291 fprintf(f,
"session_timeout: %d\n", instance->session_timeout);
293 if (mission.
length() > 0) {
294 fprintf(f,
"\nmission: \"%s\"\n", instance->mission.
data());
304 NetServerConfig::Clean(
const char* s)
306 if (!s || !*s)
return Text();
309 char* buff =
new(__FILE__,__LINE__)
char[len+1];
310 ZeroMemory(buff, len+1);
314 for (
int i = 0; i < len; i++) {
317 if (c >= 32 && c < 127)
330 NetServerConfig::LoadBanList()
338 strcpy_s(filename,
"banned.cfg");
341 ::fopen_s(&f, filename,
"rb");
344 ::fseek(f, 0, SEEK_END);
346 ::fseek(f, 0, SEEK_SET);
348 block =
new(__FILE__,__LINE__) BYTE[blocklen+1];
351 ::fread(block, blocklen, 1, f);
360 Parser parser(
new(__FILE__,__LINE__)
BlockReader((
const char*) block, blocklen));
361 Term* term = parser.ParseTerm();
364 Print(
"ERROR: could not parse '%s'.\n", filename);
370 if (!file_type || file_type->
value() !=
"BANNED_CONFIG") {
371 Print(
"WARNING: invalid '%s' file.\n", filename);
383 term = parser.ParseTerm();
391 banned_names.
append(
new(__FILE__,__LINE__)
Text(name));
394 else if (def->
name()->
value() ==
"addr") {
402 Print(
"WARNING: term ignored in '%s'\n", filename);
419 Text* user_name =
new(__FILE__,__LINE__)
Text(user->
Name());
421 banned_addrs.
append(user_addr);
422 banned_names.
append(user_name);
425 fopen_s(&f,
"banned.cfg",
"w");
427 fprintf(f,
"BANNED_CONFIG\n\n");
432 fprintf(f,
"addr: 0x%08x // %d.%d.%d.%d\n",
445 fprintf(f,
"name: \"%s\"\n", name->
data());
461 return banned_addrs.
contains(&user_addr) ||