]>
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 long refreshperiod
; // Period for refreshing players
39 long rolloverperiod
; // Period for rolling over forest fights
40 long configflags
; // Holds the binary representation of some boolean values
41 long maxforestfights
; // Maximum amount of forest fights to roll over
42 long numrolloverfights
; // Number of forest fights to roll over
44 // Remote server stuff. This is used for the outgoing connection gameserv needs to make
46 char *remoteserver
; // Server to connect to
47 char *localhost
; // Hostname of the local address to bind to
48 int remoteport
; // Port to connect to on remoteserver
49 char *remotepass
; // Password for the server link
51 char *storeitemdata
; // File to store the items available in the store
52 char *tavernitemdata
; // File to store the items available in the tavern
53 char *itemdata
; // File to store the items in
54 char *playerdata
; // File to store player data in
55 char *dragondata
; // File to store current dragon data in
56 char *masterdata
; // File to store the master data in
57 char *newsdata
; // File to store news data in
58 char *pidfile
; // Process ID file
61 char *gsnum
= "[]AAA"; // GameServ Numeric
64 void unload_config_file()
77 delete [] c_ForestTopic
;
79 delete [] remoteserver
;
87 delete [] storeitemdata
;
89 delete [] tavernitemdata
;
102 if (ignoreserverslist
)
103 delete [] ignoreserverslist
;
114 int load_config_file(char *config
)
116 char *buf
, *directive
, *value
;
118 #define numdirectives 40
120 unload_config_file();
127 DIRECTIVE directives
[numdirectives
];
129 directives
[0].desc
= "s_GameServ - GameServ Nickname";
130 directives
[1].desc
= "GSHOST - GameServ Hostname";
131 directives
[2].desc
= "GSIDENT - GameServ Ident";
132 directives
[3].desc
= "SERVERNAME - Pseudo Server's Name";
133 directives
[4].desc
= "C_FOREST - Forest Channel";
134 directives
[5].desc
= "C_FORESTTOPIC - Topic for the Forest Channel";
135 directives
[6].desc
= "REMOTESERVER - Server for gameserv to connect to (ip or hostname)";
136 directives
[7].desc
= "REMOTEPORT - Port on the remote server to connect to";
137 directives
[8].desc
= "REMOTEPASS - Password on the remote server";
138 directives
[9].desc
= "PLAYERDATA - File to store the player saves in";
139 directives
[10].desc
= "SAVEDNOTICE - True/False as to wether or not to tell the forest "\
140 "channel that the player database has been saved";
141 directives
[11].desc
= "ADMINPASS - Password to identify as an admin with";
142 directives
[12].desc
= "WELCOMEDELAY - Delay (in seconds) to wait before welcoming new users to the network";
143 directives
[13].desc
= "FORESTFIGHTS - Number of forest fights players get every day";
144 directives
[14].desc
= "UPDATEPERIOD - Number of seconds between every player data save";
145 directives
[15].desc
= "PIDFILE - Filename to store the gameserv process ID in";
146 directives
[16].desc
= "MAXAFIGHTDISTANCE - The maximum number of levels above you "\
147 "that you can fight player->player";
148 directives
[17].desc
= "MAXBFIGHTDISTANCE - The maximum number of levels below you "\
149 "that you can fight player->player";
150 directives
[18].desc
= "MAXIDLETIME - The maximum amount of time (in seconds) "\
151 "that a player can be idle before something happens";
152 directives
[19].desc
= "IDLECHECKPERIOD - The period (in seconds) in which the entire "\
153 "players list will be checked for idlers. See also: "\
155 directives
[20].desc
= "LISTENONC_FOREST - True/False as to "\
156 "whether or not to listen for forest "\
157 "commands on the forest channel";
158 directives
[21].desc
= "NEWSDATA - File to store daily news in";
159 directives
[22].desc
= "REFRESHPERIOD - Period (in seconds) to "\
161 directives
[23].desc
= "LEVEL1EXPIRE - Amount of days until a "\
162 "level 1 player's account is deleted due to "\
164 directives
[24].desc
= "DEFAULTEXPIRE - Amount of days until a "\
165 "level 2 and above player's account is "\
166 "deleted due to inactivity";
167 directives
[25].desc
= "USENICKSERV - True/False as to wether or not "\
168 "GameServ should identify with NickServ";
169 directives
[26].desc
= "NSNAME - Your network's NickServ nickname";
170 directives
[27].desc
= "NSPASS - GameServ's NickServ Password";
171 directives
[28].desc
= "DRAGONDATA - File to store the current "\
173 directives
[29].desc
= "MASTERDATA - File to store the level master stats in";
174 directives
[30].desc
= "ITEMDATA - File to store the items in";
175 directives
[31].desc
= "TAVERNITEMDATA - File in which to store the items that are available in the tavern";
176 directives
[32].desc
= "MAXITEMS - Maximum number of items a player can carry";
177 directives
[33].desc
= "STOREITEMDATA - File in which to store the items that are available in the store";
178 directives
[34].desc
= "LOCALHOST - Local hostname or IP to bind to when connecting to the remote server";
179 directives
[35].desc
= "ROLLOVERFORESTFIGHTS - True/False as to wether or not to roll over forest fights "\
181 directives
[36].desc
= "MAXFORESTFIGHTS - Maximum amount of forest fights to roll over";
182 directives
[37].desc
= "ROLLOVERPERIOD - Period (in seconds) to rollover forest fights";
183 directives
[38].desc
= "NUMROLLOVERFIGHTS - Number of forest fights to roll over";
184 directives
[39].desc
= "FAIRFIGHTS - True/False as to whether or not to check for fair fights";
188 for (int count
= 0; count
< numdirectives
; count
++)
190 directives
[count
].done
= false;
197 log("Error opening %s", config
);
198 cerr
<< "Error opening " << config
<< endl
;
202 buf
= new char[1024];
204 while (infile
.getline(buf
, 1024, '\n'))
207 log("Config file entry buf: %s", buf
);
210 if (buf
[0] == '#' || buf
[0] == ' ' || buf
[0] == '\0' || buf
[0] == '\n' || buf
[0] == '\r')
213 directive
= strtok(buf
, " ");
215 if (stricmp(directive
, "DIE") == 0)
217 value
= strtok(NULL
, "");
218 log("You should read the entire %s file!", config
);
219 cerr
<< "You should read the entire " << config
<< " file!"
224 if (stricmp(directive
, "S_GAMESERV") == 0)
226 value
= strtok(NULL
, " ");
227 s_GameServ
= new char[strlen(value
) + 1];
228 strcpy(s_GameServ
, value
);
229 directives
[0].done
= true;
231 else if (stricmp(directive
, "GSHOST") == 0)
233 value
= strtok(NULL
, " ");
234 gshost
= new char[strlen(value
) + 1];
235 strcpy(gshost
, value
);
236 directives
[1].done
= true;
238 else if (stricmp(directive
, "GSIDENT") == 0)
240 value
= strtok(NULL
, " ");
241 gsident
= new char[strlen(value
) + 1];
242 strcpy(gsident
, value
);
243 directives
[2].done
= true;
245 else if (stricmp(directive
, "SERVERNAME") == 0)
247 value
= strtok(NULL
, " ");
248 servername
= new char[strlen(value
) + 1];
249 strcpy(servername
, value
);
250 directives
[3].done
= true;
252 else if (stricmp(directive
, "C_FOREST") == 0)
254 value
= strtok(NULL
, " ");
255 c_Forest
= new char[strlen(value
) + 1];
256 strcpy(c_Forest
, value
);
257 directives
[4].done
= true;
259 else if (stricmp(directive
, "C_FORESTTOPIC") == 0)
261 value
= strtok(NULL
, "");
262 c_ForestTopic
= new char[strlen(value
) + 1];
263 strcpy(c_ForestTopic
, value
);
264 directives
[5].done
= true;
266 else if (stricmp(directive
, "REMOTESERVER") == 0)
268 value
= strtok(NULL
, " ");
269 remoteserver
= new char[strlen(value
) + 1];
270 strcpy(remoteserver
, value
);
271 directives
[6].done
= true;
273 else if (stricmp(directive
, "REMOTEPORT") == 0)
275 value
= strtok(NULL
, " ");
276 remoteport
= stringtoint(value
);
277 directives
[7].done
= true;
279 else if (stricmp(directive
, "REMOTEPASS") == 0)
281 value
= strtok(NULL
, "");
282 remotepass
= new char[strlen(value
) + 1];
283 strcpy(remotepass
, value
);
284 directives
[8].done
= true;
286 else if (stricmp(directive
, "PLAYERDATA") == 0)
288 value
= strtok(NULL
, "");
289 playerdata
= new char[strlen(value
) + 1];
290 strcpy(playerdata
, value
);
291 directives
[9].done
= true;
293 else if (stricmp(directive
, "SAVEDNOTICE") == 0)
295 value
= strtok(NULL
, "");
296 if (stricmp(value
, "TRUE") == 0)
298 directives
[10].done
= true;
300 else if (stricmp(directive
, "ADMINPASS") == 0)
302 value
= strtok(NULL
, "");
303 adminpass
= new char[strlen(value
) + 1];
304 strcpy(adminpass
, value
);
305 directives
[11].done
= true;
307 else if (stricmp(directive
, "WELCOMEDELAY") == 0)
309 value
= strtok(NULL
, " ");
310 welcomedelay
= stringtoint(value
);
311 directives
[12].done
= true;
313 else if (stricmp(directive
, "FORESTFIGHTS") == 0)
315 value
= strtok(NULL
, " ");
316 forestfights
= stringtoint(value
);
317 directives
[13].done
= true;
319 else if (stricmp(directive
, "UPDATEPERIOD") == 0)
321 value
= strtok(NULL
, " ");
322 updateperiod
= stringtoint(value
);
323 directives
[14].done
= true;
325 else if (stricmp(directive
, "PIDFILE") == 0)
327 value
= strtok(NULL
, " ");
328 pidfile
= new char[strlen(value
) + 1];
329 strcpy(pidfile
, value
);
330 directives
[15].done
= true;
332 else if (stricmp(directive
, "MAXAFIGHTDISTANCE") == 0)
334 value
= strtok(NULL
, " ");
335 maxafightdistance
= stringtoint(value
);
336 directives
[16].done
= true;;
338 else if (stricmp(directive
, "MAXBFIGHTDISTANCE") == 0)
340 value
= strtok(NULL
, " ");
341 maxbfightdistance
= stringtoint(value
);
342 directives
[17].done
= true;
344 else if (stricmp(directive
, "MAXIDLETIME") == 0)
346 value
= strtok(NULL
, " ");
347 maxidletime
= stringtoint(value
);
348 directives
[18].done
= true;
350 else if (stricmp(directive
, "IDLECHECKPERIOD") == 0)
352 value
= strtok(NULL
, " ");
353 idlecheckperiod
= stringtoint(value
);
354 directives
[19].done
= true;
356 else if (stricmp(directive
, "LISTENONC_FOREST") == 0)
358 value
= strtok(NULL
, " ");
359 if(stricmp(value
, "TRUE") == 0)
364 directives
[20].done
= true;
366 else if (stricmp(directive
, "NEWSDATA") == 0)
368 value
= strtok(NULL
, " ");
369 newsdata
= new char [strlen(value
) + 1];
370 strcpy(newsdata
, value
);
371 directives
[21].done
= true;
373 else if (stricmp(directive
, "REFRESHPERIOD") == 0)
375 value
= strtok(NULL
, " ");
376 refreshperiod
= stringtoint(value
);
377 directives
[22].done
= true;
379 else if (stricmp(directive
, "LEVEL1EXPIRE") == 0)
381 value
= strtok(NULL
, " ");
382 level1expire
= stringtoint(value
);
383 directives
[23].done
= true;
385 else if (stricmp(directive
, "DEFAULTEXPIRE") == 0)
387 value
= strtok(NULL
, " ");
388 defaultexpire
= stringtoint(value
);
389 directives
[24].done
= true;
391 else if (stricmp(directive
, "USENICKSERV") == 0)
393 value
= strtok(NULL
, " ");
394 if (stricmp(value
, "TRUE") == 0)
399 directives
[25].done
= true;
401 else if (stricmp(directive
, "NSNAME") == 0)
403 value
= strtok(NULL
, "");
404 nsname
= new char[strlen(value
) + 1];
405 strcpy(nsname
, value
);
406 directives
[26].done
= true;
408 else if (stricmp(directive
, "NSPASS") == 0)
410 value
= strtok(NULL
, "");
411 nspass
= new char[strlen(value
) + 1];
412 strcpy(nspass
, value
);
413 directives
[27].done
= true;
415 else if (stricmp(directive
, "DRAGONDATA") == 0)
417 value
= strtok(NULL
, "");
418 dragondata
= new char[strlen(value
) + 1];
419 strcpy(dragondata
, value
);
420 directives
[28].done
= true;
422 else if (stricmp(directive
, "MASTERDATA") == 0)
424 value
= strtok(NULL
, "");
425 masterdata
= new char[strlen(value
) + 1];
426 strcpy(masterdata
, value
);
427 directives
[29].done
= true;
429 else if (stricmp(directive
, "ITEMDATA") == 0)
431 value
= strtok(NULL
, "");
432 itemdata
= new char[strlen(value
) + 1];
433 strcpy(itemdata
, value
);
434 directives
[30].done
= true;
436 else if (stricmp(directive
, "TAVERNITEMDATA") == 0)
438 value
= strtok(NULL
, "");
439 tavernitemdata
= new char[strlen(value
) + 1];
440 strcpy(tavernitemdata
, value
);
441 directives
[31].done
= true;
443 else if (stricmp(directive
, "MAXITEMS") == 0)
445 value
= strtok(NULL
, "");
446 maxitems
= stringtoint(value
);
447 directives
[32].done
= true;
449 else if (stricmp(directive
, "STOREITEMDATA") == 0)
451 value
= strtok(NULL
, "");
452 storeitemdata
= new char[strlen(value
) + 1];
453 strcpy(storeitemdata
, value
);
454 directives
[33].done
= true;
456 else if (stricmp(directive
, "LOCALHOST") == 0)
458 value
= strtok(NULL
, "");
459 localhost
= new char[strlen(value
) + 1];
460 strcpy(localhost
, value
);
461 directives
[34].done
= true;
463 else if (stricmp(directive
, "ROLLOVERFORESTFIGHTS") == 0)
465 value
= strtok(NULL
, " ");
466 if (stricmp(value
, "TRUE") == 0)
468 setRolloverForestFights();
472 directives
[36].done
= true;
473 directives
[37].done
= true;
474 directives
[38].done
= true;
476 directives
[35].done
= true;
478 else if (stricmp(directive
, "MAXFORESTFIGHTS") == 0)
480 value
= strtok(NULL
, "");
481 maxforestfights
= stringtoint(value
);
482 directives
[36].done
= true;
484 else if (stricmp(directive
, "ROLLOVERPERIOD") == 0)
486 value
= strtok(NULL
, "");
487 rolloverperiod
= stringtoint(value
);
488 directives
[37].done
= true;
490 else if (stricmp(directive
, "NUMROLLOVERFIGHTS") == 0)
492 value
= strtok(NULL
, "");
493 numrolloverfights
= stringtoint(value
);
494 directives
[38].done
= true;
496 else if (stricmp(directive
, "FAIRFIGHTS") == 0)
498 value
= strtok(NULL
, "");
499 if (stricmp(value
, "TRUE") == 0)
501 directives
[39].done
= true;
503 else if (stricmp(directive
, "WELCOMEMSG") == 0)
505 // This directive is optional
506 value
= strtok(NULL
, "");
507 welcomemsg
= new char[strlen(value
) + 1];
508 strcpy(welcomemsg
, value
);
511 else if (stricmp(directive
, "USEPRIVMSG") == 0)
513 // This directive is optional
516 else if (stricmp(directive
, "BOPER") == 0)
518 // This directive is optional
521 else if (stricmp(directive
, "IGNORESERVERS") == 0)
523 // This directive is optional
524 value
= strtok(NULL
, "");
525 ignoreserverslist
= new char[strlen(value
) + 1];
526 strcpy(ignoreserverslist
, value
);
531 log("Unknown Directive. Buffer: %s", buf
);
532 cerr
<< "Unknown " << config
<< " directive. Buffer: "
542 for (int count2
= 0; count2
< numdirectives
; count2
++)
544 if (!directives
[count2
].done
)
546 cerr
<< "Missing config directive: " << directives
[count2
].desc
<< endl
;