]>
jfr.im git - irc/gameservirc.git/blob - gameserv/config.cpp
11 int load_config_file(char *config
);
12 void unload_config_file();
14 /* Random Configuration Stuff Goes Here until I code it to load from a .conf file :)*/
16 char *s_GameServ
; // GameServ's nickname
17 char *gshost
; // GameServ's Hostname
18 char *gsident
; // GameServ's ident/username
19 char *servername
; // GameServ's Server
20 char *c_Forest
; // Forest channel
21 char *c_ForestTopic
; // Forest Channel Topic
22 char *adminpass
; // Administrator password
23 char *welcomemsg
; // Welcome Message
24 char *ignoreserverslist
; // Servernames to ignore
25 char *nsname
; // NickServ's name
26 char *nspass
; // GameServ's NickServ Password
28 int welcomedelay
; // Welcome Message Delay
29 int updateperiod
; // Seconds until another player database update
30 int forestfights
; // Forest fights per day
31 int maxafightdistance
; // Max levels above a player they can fight player->player
32 int maxbfightdistance
; // Max levels below a player they can fight player->player
33 int maxidletime
; // Max time (in seconds) a player can be idle for
34 int idlecheckperiod
; // Period for checking every player's idle time
35 int level1expire
; // Days for level 1 players to expire
36 int defaultexpire
; // Days for other levels to expire
37 int maxitems
; // Maximum amount of items a player can carry
38 unsigned int maxnicklen
; // Maximum length a nickname can be
39 long refreshperiod
; // Period for refreshing players
40 long rolloverperiod
; // Period for rolling over forest fights
41 long configflags
; // Holds the binary representation of some boolean values
42 long maxforestfights
; // Maximum amount of forest fights to roll over
43 long numrolloverfights
; // Number of forest fights to roll over
46 // Remote server stuff. This is used for the outgoing connection gameserv needs to make
48 char *remoteserver
; // Server to connect to
49 char *localhost
; // Hostname of the local address to bind to
50 int remoteport
; // Port to connect to on remoteserver
51 char *remotepass
; // Password for the server link
53 char *storeitemdata
; // File to store the items available in the store
54 char *tavernitemdata
; // File to store the items available in the tavern
55 char *itemdata
; // File to store the items in
56 char *playerdata
; // File to store player data in
57 char *dragondata
; // File to store current dragon data in
58 char *masterdata
; // File to store the master data in
59 char *newsdata
; // File to store news data in
60 char *pidfile
; // Process ID file
63 char *gsnum
= "[]AAA"; // GameServ Numeric
66 void unload_config_file()
79 delete [] c_ForestTopic
;
81 delete [] remoteserver
;
89 delete [] storeitemdata
;
91 delete [] tavernitemdata
;
101 delete [] welcomemsg
;
104 if (ignoreserverslist
)
105 delete [] ignoreserverslist
;
116 int load_config_file(char *config
)
118 char *buf
, *directive
, *value
;
120 #define numdirectives 41
122 unload_config_file();
129 DIRECTIVE directives
[numdirectives
];
131 directives
[0].desc
= "s_GameServ - GameServ Nickname";
132 directives
[1].desc
= "GSHOST - GameServ Hostname";
133 directives
[2].desc
= "GSIDENT - GameServ Ident";
134 directives
[3].desc
= "SERVERNAME - Pseudo Server's Name";
135 directives
[4].desc
= "C_FOREST - Forest Channel";
136 directives
[5].desc
= "C_FORESTTOPIC - Topic for the Forest Channel";
137 directives
[6].desc
= "REMOTESERVER - Server for gameserv to connect to (ip or hostname)";
138 directives
[7].desc
= "REMOTEPORT - Port on the remote server to connect to";
139 directives
[8].desc
= "REMOTEPASS - Password on the remote server";
140 directives
[9].desc
= "PLAYERDATA - File to store the player saves in";
141 directives
[10].desc
= "SAVEDNOTICE - True/False as to wether or not to tell the forest "\
142 "channel that the player database has been saved";
143 directives
[11].desc
= "ADMINPASS - Password to identify as an admin with";
144 directives
[12].desc
= "WELCOMEDELAY - Delay (in seconds) to wait before welcoming new users to the network";
145 directives
[13].desc
= "FORESTFIGHTS - Number of forest fights players get every day";
146 directives
[14].desc
= "UPDATEPERIOD - Number of seconds between every player data save";
147 directives
[15].desc
= "PIDFILE - Filename to store the gameserv process ID in";
148 directives
[16].desc
= "MAXAFIGHTDISTANCE - The maximum number of levels above you "\
149 "that you can fight player->player";
150 directives
[17].desc
= "MAXBFIGHTDISTANCE - The maximum number of levels below you "\
151 "that you can fight player->player";
152 directives
[18].desc
= "MAXIDLETIME - The maximum amount of time (in seconds) "\
153 "that a player can be idle before something happens";
154 directives
[19].desc
= "IDLECHECKPERIOD - The period (in seconds) in which the entire "\
155 "players list will be checked for idlers. See also: "\
157 directives
[20].desc
= "LISTENONC_FOREST - True/False as to "\
158 "whether or not to listen for forest "\
159 "commands on the forest channel";
160 directives
[21].desc
= "NEWSDATA - File to store daily news in";
161 directives
[22].desc
= "REFRESHPERIOD - Period (in seconds) to "\
163 directives
[23].desc
= "LEVEL1EXPIRE - Amount of days until a "\
164 "level 1 player's account is deleted due to "\
166 directives
[24].desc
= "DEFAULTEXPIRE - Amount of days until a "\
167 "level 2 and above player's account is "\
168 "deleted due to inactivity";
169 directives
[25].desc
= "USENICKSERV - True/False as to wether or not "\
170 "GameServ should identify with NickServ";
171 directives
[26].desc
= "NSNAME - Your network's NickServ nickname";
172 directives
[27].desc
= "NSPASS - GameServ's NickServ Password";
173 directives
[28].desc
= "DRAGONDATA - File to store the current "\
175 directives
[29].desc
= "MASTERDATA - File to store the level master stats in";
176 directives
[30].desc
= "ITEMDATA - File to store the items in";
177 directives
[31].desc
= "TAVERNITEMDATA - File in which to store the items that are available in the tavern";
178 directives
[32].desc
= "MAXITEMS - Maximum number of items a player can carry";
179 directives
[33].desc
= "STOREITEMDATA - File in which to store the items that are available in the store";
180 directives
[34].desc
= "LOCALHOST - Local hostname or IP to bind to when connecting to the remote server";
181 directives
[35].desc
= "ROLLOVERFORESTFIGHTS - True/False as to wether or not to roll over forest fights "\
183 directives
[36].desc
= "MAXFORESTFIGHTS - Maximum amount of forest fights to roll over";
184 directives
[37].desc
= "ROLLOVERPERIOD - Period (in seconds) to rollover forest fights";
185 directives
[38].desc
= "NUMROLLOVERFIGHTS - Number of forest fights to roll over";
186 directives
[39].desc
= "FAIRFIGHTS - True/False as to whether or not to check for fair fights";
187 directives
[40].desc
= "MAXNICKLEN - Maximum length a nickname can be";
191 for (int count
= 0; count
< numdirectives
; count
++)
193 directives
[count
].done
= false;
200 log("Error opening %s", config
);
201 cerr
<< "Error opening " << config
<< endl
;
205 buf
= new char[1024];
207 while (infile
.getline(buf
, 1024, '\n'))
210 log("Config file entry buf: %s", buf
);
213 if (buf
[0] == '#' || buf
[0] == ' ' || buf
[0] == '\0' || buf
[0] == '\n' || buf
[0] == '\r')
216 directive
= strtok(buf
, " ");
218 if (stricmp(directive
, "DIE") == 0)
220 value
= strtok(NULL
, "");
221 log("You should read the entire %s file!", config
);
222 cerr
<< "You should read the entire " << config
<< " file!"
227 if (stricmp(directive
, "S_GAMESERV") == 0)
229 value
= strtok(NULL
, " ");
230 s_GameServ
= new char[strlen(value
) + 1];
231 strcpy(s_GameServ
, value
);
232 directives
[0].done
= true;
234 else if (stricmp(directive
, "GSHOST") == 0)
236 value
= strtok(NULL
, " ");
237 gshost
= new char[strlen(value
) + 1];
238 strcpy(gshost
, value
);
239 directives
[1].done
= true;
241 else if (stricmp(directive
, "GSIDENT") == 0)
243 value
= strtok(NULL
, " ");
244 gsident
= new char[strlen(value
) + 1];
245 strcpy(gsident
, value
);
246 directives
[2].done
= true;
248 else if (stricmp(directive
, "SERVERNAME") == 0)
250 value
= strtok(NULL
, " ");
251 servername
= new char[strlen(value
) + 1];
252 strcpy(servername
, value
);
253 directives
[3].done
= true;
255 else if (stricmp(directive
, "C_FOREST") == 0)
257 value
= strtok(NULL
, " ");
258 c_Forest
= new char[strlen(value
) + 1];
259 strcpy(c_Forest
, value
);
260 directives
[4].done
= true;
262 else if (stricmp(directive
, "C_FORESTTOPIC") == 0)
264 value
= strtok(NULL
, "");
265 c_ForestTopic
= new char[strlen(value
) + 1];
266 strcpy(c_ForestTopic
, value
);
267 directives
[5].done
= true;
269 else if (stricmp(directive
, "REMOTESERVER") == 0)
271 value
= strtok(NULL
, " ");
272 remoteserver
= new char[strlen(value
) + 1];
273 strcpy(remoteserver
, value
);
274 directives
[6].done
= true;
276 else if (stricmp(directive
, "REMOTEPORT") == 0)
278 value
= strtok(NULL
, " ");
279 remoteport
= stringtoint(value
);
280 directives
[7].done
= true;
282 else if (stricmp(directive
, "REMOTEPASS") == 0)
284 value
= strtok(NULL
, " ");
285 remotepass
= new char[strlen(value
) + 1];
286 strcpy(remotepass
, value
);
287 directives
[8].done
= true;
289 else if (stricmp(directive
, "PLAYERDATA") == 0)
291 value
= strtok(NULL
, "");
292 playerdata
= new char[strlen(value
) + 1];
293 strcpy(playerdata
, value
);
294 directives
[9].done
= true;
296 else if (stricmp(directive
, "SAVEDNOTICE") == 0)
298 value
= strtok(NULL
, " ");
299 if (stricmp(value
, "TRUE") == 0)
301 directives
[10].done
= true;
303 else if (stricmp(directive
, "ADMINPASS") == 0)
305 value
= strtok(NULL
, "");
306 adminpass
= new char[strlen(value
) + 1];
307 strcpy(adminpass
, value
);
308 directives
[11].done
= true;
310 else if (stricmp(directive
, "WELCOMEDELAY") == 0)
312 value
= strtok(NULL
, " ");
313 welcomedelay
= stringtoint(value
);
314 directives
[12].done
= true;
316 else if (stricmp(directive
, "FORESTFIGHTS") == 0)
318 value
= strtok(NULL
, " ");
319 forestfights
= stringtoint(value
);
320 directives
[13].done
= true;
322 else if (stricmp(directive
, "UPDATEPERIOD") == 0)
324 value
= strtok(NULL
, " ");
325 updateperiod
= stringtoint(value
);
326 directives
[14].done
= true;
328 else if (stricmp(directive
, "PIDFILE") == 0)
330 value
= strtok(NULL
, " ");
331 pidfile
= new char[strlen(value
) + 1];
332 strcpy(pidfile
, value
);
333 directives
[15].done
= true;
335 else if (stricmp(directive
, "MAXAFIGHTDISTANCE") == 0)
337 value
= strtok(NULL
, " ");
338 maxafightdistance
= stringtoint(value
);
339 directives
[16].done
= true;;
341 else if (stricmp(directive
, "MAXBFIGHTDISTANCE") == 0)
343 value
= strtok(NULL
, " ");
344 maxbfightdistance
= stringtoint(value
);
345 directives
[17].done
= true;
347 else if (stricmp(directive
, "MAXIDLETIME") == 0)
349 value
= strtok(NULL
, " ");
350 maxidletime
= stringtoint(value
);
351 directives
[18].done
= true;
353 else if (stricmp(directive
, "IDLECHECKPERIOD") == 0)
355 value
= strtok(NULL
, " ");
356 idlecheckperiod
= stringtoint(value
);
357 directives
[19].done
= true;
359 else if (stricmp(directive
, "LISTENONC_FOREST") == 0)
361 value
= strtok(NULL
, " ");
362 if(stricmp(value
, "TRUE") == 0)
367 directives
[20].done
= true;
369 else if (stricmp(directive
, "NEWSDATA") == 0)
371 value
= strtok(NULL
, " ");
372 newsdata
= new char [strlen(value
) + 1];
373 strcpy(newsdata
, value
);
374 directives
[21].done
= true;
376 else if (stricmp(directive
, "REFRESHPERIOD") == 0)
378 value
= strtok(NULL
, " ");
379 refreshperiod
= stringtoint(value
);
380 directives
[22].done
= true;
382 else if (stricmp(directive
, "LEVEL1EXPIRE") == 0)
384 value
= strtok(NULL
, " ");
385 level1expire
= stringtoint(value
);
386 directives
[23].done
= true;
388 else if (stricmp(directive
, "DEFAULTEXPIRE") == 0)
390 value
= strtok(NULL
, " ");
391 defaultexpire
= stringtoint(value
);
392 directives
[24].done
= true;
394 else if (stricmp(directive
, "USENICKSERV") == 0)
396 value
= strtok(NULL
, " ");
397 if (stricmp(value
, "TRUE") == 0)
402 directives
[25].done
= true;
404 else if (stricmp(directive
, "NSNAME") == 0)
406 value
= strtok(NULL
, " ");
407 nsname
= new char[strlen(value
) + 1];
408 strcpy(nsname
, value
);
409 directives
[26].done
= true;
411 else if (stricmp(directive
, "NSPASS") == 0)
413 value
= strtok(NULL
, " ");
414 nspass
= new char[strlen(value
) + 1];
415 strcpy(nspass
, value
);
416 directives
[27].done
= true;
418 else if (stricmp(directive
, "DRAGONDATA") == 0)
420 value
= strtok(NULL
, "");
421 dragondata
= new char[strlen(value
) + 1];
422 strcpy(dragondata
, value
);
423 directives
[28].done
= true;
425 else if (stricmp(directive
, "MASTERDATA") == 0)
427 value
= strtok(NULL
, "");
428 masterdata
= new char[strlen(value
) + 1];
429 strcpy(masterdata
, value
);
430 directives
[29].done
= true;
432 else if (stricmp(directive
, "ITEMDATA") == 0)
434 value
= strtok(NULL
, "");
435 itemdata
= new char[strlen(value
) + 1];
436 strcpy(itemdata
, value
);
437 directives
[30].done
= true;
439 else if (stricmp(directive
, "TAVERNITEMDATA") == 0)
441 value
= strtok(NULL
, "");
442 tavernitemdata
= new char[strlen(value
) + 1];
443 strcpy(tavernitemdata
, value
);
444 directives
[31].done
= true;
446 else if (stricmp(directive
, "MAXITEMS") == 0)
448 value
= strtok(NULL
, " ");
449 maxitems
= stringtoint(value
);
450 directives
[32].done
= true;
452 else if (stricmp(directive
, "STOREITEMDATA") == 0)
454 value
= strtok(NULL
, "");
455 storeitemdata
= new char[strlen(value
) + 1];
456 strcpy(storeitemdata
, value
);
457 directives
[33].done
= true;
459 else if (stricmp(directive
, "LOCALHOST") == 0)
461 value
= strtok(NULL
, " ");
462 localhost
= new char[strlen(value
) + 1];
463 strcpy(localhost
, value
);
464 directives
[34].done
= true;
466 else if (stricmp(directive
, "ROLLOVERFORESTFIGHTS") == 0)
468 value
= strtok(NULL
, " ");
469 if (stricmp(value
, "TRUE") == 0)
471 setRolloverForestFights();
475 directives
[36].done
= true;
476 directives
[37].done
= true;
477 directives
[38].done
= true;
479 directives
[35].done
= true;
481 else if (stricmp(directive
, "MAXFORESTFIGHTS") == 0)
483 value
= strtok(NULL
, " ");
484 maxforestfights
= stringtoint(value
);
485 directives
[36].done
= true;
487 else if (stricmp(directive
, "ROLLOVERPERIOD") == 0)
489 value
= strtok(NULL
, " ");
490 rolloverperiod
= stringtoint(value
);
491 directives
[37].done
= true;
493 else if (stricmp(directive
, "NUMROLLOVERFIGHTS") == 0)
495 value
= strtok(NULL
, "");
496 numrolloverfights
= stringtoint(value
);
497 directives
[38].done
= true;
499 else if (stricmp(directive
, "FAIRFIGHTS") == 0)
501 value
= strtok(NULL
, " ");
502 if (stricmp(value
, "TRUE") == 0)
504 directives
[39].done
= true;
506 else if (stricmp(directive
, "MAXNICKLEN") == 0)
508 value
= strtok(NULL
, " ");
509 maxnicklen
= stringtoint(value
);
510 directives
[40].done
= true;
512 else if (stricmp(directive
, "WELCOMEMSG") == 0)
514 // This directive is optional
515 value
= strtok(NULL
, "");
516 welcomemsg
= new char[strlen(value
) + 1];
517 strcpy(welcomemsg
, value
);
520 else if (stricmp(directive
, "USEPRIVMSG") == 0)
522 // This directive is optional
525 else if (stricmp(directive
, "BOPER") == 0)
527 // This directive is optional
530 else if (stricmp(directive
, "IGNORESERVERS") == 0)
532 // This directive is optional
533 value
= strtok(NULL
, "");
534 ignoreserverslist
= new char[strlen(value
) + 1];
535 strcpy(ignoreserverslist
, value
);
540 log("Unknown Directive. Buffer: %s", buf
);
541 cerr
<< "Unknown " << config
<< " directive. Buffer: "
551 for (int count2
= 0; count2
< numdirectives
; count2
++)
553 if (!directives
[count2
].done
)
555 cerr
<< "Missing config directive: " << directives
[count2
].desc
<< endl
;