]>
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
61 char *scriptdir
; // Directory to store scripts in
64 char *gsnum
= "[]AAA"; // GameServ Numeric
67 void unload_config_file()
80 delete [] c_ForestTopic
;
82 delete [] remoteserver
;
90 delete [] storeitemdata
;
92 delete [] tavernitemdata
;
102 delete [] welcomemsg
;
105 if (ignoreserverslist
)
106 delete [] ignoreserverslist
;
119 int load_config_file(char *config
)
121 char *buf
, *directive
, *value
;
123 #define numdirectives 42
125 unload_config_file();
132 DIRECTIVE directives
[numdirectives
];
134 directives
[0].desc
= "s_GameServ - GameServ Nickname";
135 directives
[1].desc
= "GSHOST - GameServ Hostname";
136 directives
[2].desc
= "GSIDENT - GameServ Ident";
137 directives
[3].desc
= "SERVERNAME - Pseudo Server's Name";
138 directives
[4].desc
= "C_FOREST - Forest Channel";
139 directives
[5].desc
= "C_FORESTTOPIC - Topic for the Forest Channel";
140 directives
[6].desc
= "REMOTESERVER - Server for gameserv to connect to (ip or hostname)";
141 directives
[7].desc
= "REMOTEPORT - Port on the remote server to connect to";
142 directives
[8].desc
= "REMOTEPASS - Password on the remote server";
143 directives
[9].desc
= "PLAYERDATA - File to store the player saves in";
144 directives
[10].desc
= "SAVEDNOTICE - True/False as to wether or not to tell the forest "\
145 "channel that the player database has been saved";
146 directives
[11].desc
= "ADMINPASS - Password to identify as an admin with";
147 directives
[12].desc
= "WELCOMEDELAY - Delay (in seconds) to wait before welcoming new users to the network";
148 directives
[13].desc
= "FORESTFIGHTS - Number of forest fights players get every day";
149 directives
[14].desc
= "UPDATEPERIOD - Number of seconds between every player data save";
150 directives
[15].desc
= "PIDFILE - Filename to store the gameserv process ID in";
151 directives
[16].desc
= "MAXAFIGHTDISTANCE - The maximum number of levels above you "\
152 "that you can fight player->player";
153 directives
[17].desc
= "MAXBFIGHTDISTANCE - The maximum number of levels below you "\
154 "that you can fight player->player";
155 directives
[18].desc
= "MAXIDLETIME - The maximum amount of time (in seconds) "\
156 "that a player can be idle before something happens";
157 directives
[19].desc
= "IDLECHECKPERIOD - The period (in seconds) in which the entire "\
158 "players list will be checked for idlers. See also: "\
160 directives
[20].desc
= "LISTENONC_FOREST - True/False as to "\
161 "whether or not to listen for forest "\
162 "commands on the forest channel";
163 directives
[21].desc
= "NEWSDATA - File to store daily news in";
164 directives
[22].desc
= "REFRESHPERIOD - Period (in seconds) to "\
166 directives
[23].desc
= "LEVEL1EXPIRE - Amount of days until a "\
167 "level 1 player's account is deleted due to "\
169 directives
[24].desc
= "DEFAULTEXPIRE - Amount of days until a "\
170 "level 2 and above player's account is "\
171 "deleted due to inactivity";
172 directives
[25].desc
= "USENICKSERV - True/False as to wether or not "\
173 "GameServ should identify with NickServ";
174 directives
[26].desc
= "NSNAME - Your network's NickServ nickname";
175 directives
[27].desc
= "NSPASS - GameServ's NickServ Password";
176 directives
[28].desc
= "DRAGONDATA - File to store the current "\
178 directives
[29].desc
= "MASTERDATA - File to store the level master stats in";
179 directives
[30].desc
= "ITEMDATA - File to store the items in";
180 directives
[31].desc
= "TAVERNITEMDATA - File in which to store the items that are available in the tavern";
181 directives
[32].desc
= "MAXITEMS - Maximum number of items a player can carry";
182 directives
[33].desc
= "STOREITEMDATA - File in which to store the items that are available in the store";
183 directives
[34].desc
= "LOCALHOST - Local hostname or IP to bind to when connecting to the remote server";
184 directives
[35].desc
= "ROLLOVERFORESTFIGHTS - True/False as to wether or not to roll over forest fights "\
186 directives
[36].desc
= "MAXFORESTFIGHTS - Maximum amount of forest fights to roll over";
187 directives
[37].desc
= "ROLLOVERPERIOD - Period (in seconds) to rollover forest fights";
188 directives
[38].desc
= "NUMROLLOVERFIGHTS - Number of forest fights to roll over";
189 directives
[39].desc
= "FAIRFIGHTS - True/False as to whether or not to check for fair fights";
190 directives
[40].desc
= "MAXNICKLEN - Maximum length a nickname can be";
191 directives
[41].desc
= "SCRIPTDIR - Directory to store scripts in";
195 for (int count
= 0; count
< numdirectives
; count
++)
197 directives
[count
].done
= false;
204 log("Error opening %s", config
);
205 cerr
<< "Error opening " << config
<< endl
;
209 buf
= new char[1024];
211 while (infile
.getline(buf
, 1024, '\n'))
214 log("Config file entry buf: %s", buf
);
217 if (buf
[0] == '#' || buf
[0] == ' ' || buf
[0] == '\0' || buf
[0] == '\n' || buf
[0] == '\r')
220 directive
= strtok(buf
, " ");
222 if (stricmp(directive
, "DIE") == 0)
224 value
= strtok(NULL
, "");
225 log("You should read the entire %s file!", config
);
226 cerr
<< "You should read the entire " << config
<< " file!"
231 if (stricmp(directive
, "S_GAMESERV") == 0)
233 value
= strtok(NULL
, " ");
234 s_GameServ
= new char[strlen(value
) + 1];
235 strcpy(s_GameServ
, value
);
236 directives
[0].done
= true;
238 else if (stricmp(directive
, "GSHOST") == 0)
240 value
= strtok(NULL
, " ");
241 gshost
= new char[strlen(value
) + 1];
242 strcpy(gshost
, value
);
243 directives
[1].done
= true;
245 else if (stricmp(directive
, "GSIDENT") == 0)
247 value
= strtok(NULL
, " ");
248 gsident
= new char[strlen(value
) + 1];
249 strcpy(gsident
, value
);
250 directives
[2].done
= true;
252 else if (stricmp(directive
, "SERVERNAME") == 0)
254 value
= strtok(NULL
, " ");
255 servername
= new char[strlen(value
) + 1];
256 strcpy(servername
, value
);
257 directives
[3].done
= true;
259 else if (stricmp(directive
, "C_FOREST") == 0)
261 value
= strtok(NULL
, " ");
262 c_Forest
= new char[strlen(value
) + 1];
263 strcpy(c_Forest
, value
);
264 directives
[4].done
= true;
266 else if (stricmp(directive
, "C_FORESTTOPIC") == 0)
268 value
= strtok(NULL
, "");
269 c_ForestTopic
= new char[strlen(value
) + 1];
270 strcpy(c_ForestTopic
, value
);
271 directives
[5].done
= true;
273 else if (stricmp(directive
, "REMOTESERVER") == 0)
275 value
= strtok(NULL
, " ");
276 remoteserver
= new char[strlen(value
) + 1];
277 strcpy(remoteserver
, value
);
278 directives
[6].done
= true;
280 else if (stricmp(directive
, "REMOTEPORT") == 0)
282 value
= strtok(NULL
, " ");
283 remoteport
= stringtoint(value
);
284 directives
[7].done
= true;
286 else if (stricmp(directive
, "REMOTEPASS") == 0)
288 value
= strtok(NULL
, " ");
289 remotepass
= new char[strlen(value
) + 1];
290 strcpy(remotepass
, value
);
291 directives
[8].done
= true;
293 else if (stricmp(directive
, "PLAYERDATA") == 0)
295 value
= strtok(NULL
, "");
296 playerdata
= new char[strlen(value
) + 1];
297 strcpy(playerdata
, value
);
298 directives
[9].done
= true;
300 else if (stricmp(directive
, "SAVEDNOTICE") == 0)
302 value
= strtok(NULL
, " ");
303 if (stricmp(value
, "TRUE") == 0)
305 directives
[10].done
= true;
307 else if (stricmp(directive
, "ADMINPASS") == 0)
309 value
= strtok(NULL
, "");
310 adminpass
= new char[strlen(value
) + 1];
311 strcpy(adminpass
, value
);
312 directives
[11].done
= true;
314 else if (stricmp(directive
, "WELCOMEDELAY") == 0)
316 value
= strtok(NULL
, " ");
317 welcomedelay
= stringtoint(value
);
318 directives
[12].done
= true;
320 else if (stricmp(directive
, "FORESTFIGHTS") == 0)
322 value
= strtok(NULL
, " ");
323 forestfights
= stringtoint(value
);
324 directives
[13].done
= true;
326 else if (stricmp(directive
, "UPDATEPERIOD") == 0)
328 value
= strtok(NULL
, " ");
329 updateperiod
= stringtoint(value
);
330 directives
[14].done
= true;
332 else if (stricmp(directive
, "PIDFILE") == 0)
334 value
= strtok(NULL
, " ");
335 pidfile
= new char[strlen(value
) + 1];
336 strcpy(pidfile
, value
);
337 directives
[15].done
= true;
339 else if (stricmp(directive
, "MAXAFIGHTDISTANCE") == 0)
341 value
= strtok(NULL
, " ");
342 maxafightdistance
= stringtoint(value
);
343 directives
[16].done
= true;;
345 else if (stricmp(directive
, "MAXBFIGHTDISTANCE") == 0)
347 value
= strtok(NULL
, " ");
348 maxbfightdistance
= stringtoint(value
);
349 directives
[17].done
= true;
351 else if (stricmp(directive
, "MAXIDLETIME") == 0)
353 value
= strtok(NULL
, " ");
354 maxidletime
= stringtoint(value
);
355 directives
[18].done
= true;
357 else if (stricmp(directive
, "IDLECHECKPERIOD") == 0)
359 value
= strtok(NULL
, " ");
360 idlecheckperiod
= stringtoint(value
);
361 directives
[19].done
= true;
363 else if (stricmp(directive
, "LISTENONC_FOREST") == 0)
365 value
= strtok(NULL
, " ");
366 if(stricmp(value
, "TRUE") == 0)
371 directives
[20].done
= true;
373 else if (stricmp(directive
, "NEWSDATA") == 0)
375 value
= strtok(NULL
, " ");
376 newsdata
= new char [strlen(value
) + 1];
377 strncpy(newsdata
, value
, sizeof(newsdata
));
378 directives
[21].done
= true;
380 else if (stricmp(directive
, "REFRESHPERIOD") == 0)
382 value
= strtok(NULL
, " ");
383 refreshperiod
= stringtoint(value
);
384 directives
[22].done
= true;
386 else if (stricmp(directive
, "LEVEL1EXPIRE") == 0)
388 value
= strtok(NULL
, " ");
389 level1expire
= stringtoint(value
);
390 directives
[23].done
= true;
392 else if (stricmp(directive
, "DEFAULTEXPIRE") == 0)
394 value
= strtok(NULL
, " ");
395 defaultexpire
= stringtoint(value
);
396 directives
[24].done
= true;
398 else if (stricmp(directive
, "USENICKSERV") == 0)
400 value
= strtok(NULL
, " ");
401 if (stricmp(value
, "TRUE") == 0)
406 directives
[25].done
= true;
408 else if (stricmp(directive
, "NSNAME") == 0)
410 value
= strtok(NULL
, " ");
411 nsname
= new char[strlen(value
) + 1];
412 strncpy(nsname
, value
, sizeof(nsname
));
413 directives
[26].done
= true;
415 else if (stricmp(directive
, "NSPASS") == 0)
417 value
= strtok(NULL
, " ");
418 nspass
= new char[strlen(value
) + 1];
419 strncpy(nspass
, value
, sizeof(nspass
));
420 directives
[27].done
= true;
422 else if (stricmp(directive
, "DRAGONDATA") == 0)
424 value
= strtok(NULL
, "");
425 dragondata
= new char[strlen(value
) + 1];
426 strncpy(dragondata
, value
, sizeof(dragondata
));
427 directives
[28].done
= true;
429 else if (stricmp(directive
, "MASTERDATA") == 0)
431 value
= strtok(NULL
, "");
432 masterdata
= new char[strlen(value
) + 1];
433 strncpy(masterdata
, value
, sizeof(masterdata
));
434 directives
[29].done
= true;
436 else if (stricmp(directive
, "ITEMDATA") == 0)
438 value
= strtok(NULL
, "");
439 itemdata
= new char[strlen(value
) + 1];
440 strncpy(itemdata
, value
, sizeof(itemdata
));
441 directives
[30].done
= true;
443 else if (stricmp(directive
, "TAVERNITEMDATA") == 0)
445 value
= strtok(NULL
, "");
446 tavernitemdata
= new char[strlen(value
) + 1];
447 strncpy(tavernitemdata
, value
, sizeof(tavernitemdata
));
448 directives
[31].done
= true;
450 else if (stricmp(directive
, "MAXITEMS") == 0)
452 value
= strtok(NULL
, " ");
453 maxitems
= stringtoint(value
);
454 directives
[32].done
= true;
456 else if (stricmp(directive
, "STOREITEMDATA") == 0)
458 value
= strtok(NULL
, "");
459 storeitemdata
= new char[strlen(value
) + 1];
460 strncpy(storeitemdata
, value
, sizeof(storeitemdata
));
461 directives
[33].done
= true;
463 else if (stricmp(directive
, "LOCALHOST") == 0)
465 value
= strtok(NULL
, " ");
466 localhost
= new char[strlen(value
) + 1];
467 strncpy(localhost
, value
, sizeof(localhost
));
468 directives
[34].done
= true;
470 else if (stricmp(directive
, "ROLLOVERFORESTFIGHTS") == 0)
472 value
= strtok(NULL
, " ");
473 if (stricmp(value
, "TRUE") == 0)
475 setRolloverForestFights();
479 directives
[36].done
= true;
480 directives
[37].done
= true;
481 directives
[38].done
= true;
483 directives
[35].done
= true;
485 else if (stricmp(directive
, "MAXFORESTFIGHTS") == 0)
487 value
= strtok(NULL
, " ");
488 maxforestfights
= stringtoint(value
);
489 directives
[36].done
= true;
491 else if (stricmp(directive
, "ROLLOVERPERIOD") == 0)
493 value
= strtok(NULL
, " ");
494 rolloverperiod
= stringtoint(value
);
495 directives
[37].done
= true;
497 else if (stricmp(directive
, "NUMROLLOVERFIGHTS") == 0)
499 value
= strtok(NULL
, "");
500 numrolloverfights
= stringtoint(value
);
501 directives
[38].done
= true;
503 else if (stricmp(directive
, "FAIRFIGHTS") == 0)
505 value
= strtok(NULL
, " ");
506 if (stricmp(value
, "TRUE") == 0)
508 directives
[39].done
= true;
510 else if (stricmp(directive
, "MAXNICKLEN") == 0)
512 value
= strtok(NULL
, " ");
513 maxnicklen
= stringtoint(value
);
514 directives
[40].done
= true;
516 else if (stricmp(directive
, "SCRIPTDIR") == 0)
518 value
= strtok(NULL
, "");
519 scriptdir
= new char [strlen(value
)];
520 strncpy(scriptdir
, value
, sizeof(scriptdir
));
521 directives
[41].done
= true;
523 else if (stricmp(directive
, "WELCOMEMSG") == 0)
525 // This directive is optional
526 value
= strtok(NULL
, "");
527 welcomemsg
= new char[strlen(value
) + 1];
528 strncpy(welcomemsg
, value
, sizeof(welcomemsg
));
531 else if (stricmp(directive
, "USEPRIVMSG") == 0)
533 // This directive is optional
536 else if (stricmp(directive
, "BOPER") == 0)
538 // This directive is optional
541 else if (stricmp(directive
, "IGNORESERVERS") == 0)
543 // This directive is optional
544 value
= strtok(NULL
, "");
545 ignoreserverslist
= new char[strlen(value
) + 1];
546 strncpy(ignoreserverslist
, value
, sizeof(ignoreserverslist
));
551 log("Unknown Directive. Buffer: %s", buf
);
552 cerr
<< "Unknown " << config
<< " directive. Buffer: "
562 for (int count2
= 0; count2
< numdirectives
; count2
++)
564 if (!directives
[count2
].done
)
566 cerr
<< "Missing config directive: " << directives
[count2
].desc
<< endl
;