]> jfr.im git - irc/gameservirc.git/blame - gameserv/config.cpp
Fixed a bug that caused a player to be deleted after Player::reset() because it set...
[irc/gameservirc.git] / gameserv / config.cpp
CommitLineData
fb37ecc7 1#include <fstream>
85ce9d3e 2#include <string.h>
20d5d721 3#include <stdlib.h>
85ce9d3e 4#include <stdio.h>
5#include "extern.h"
9bafc40d 6#include "flags.h"
85ce9d3e 7
fb37ecc7 8using std::ifstream;
33ac4371 9using std::cerr;
10using std::endl;
fb37ecc7 11
624c0352 12int load_config_file(char *config);
85ce9d3e 13void unload_config_file();
85ce9d3e 14
15/* Random Configuration Stuff Goes Here until I code it to load from a .conf file :)*/
16
17char *s_GameServ; // GameServ's nickname
18char *gshost; // GameServ's Hostname
19char *gsident; // GameServ's ident/username
20char *servername; // GameServ's Server
21char *c_Forest; // Forest channel
22char *c_ForestTopic; // Forest Channel Topic
45a84400 23char *adminpass; // Administrator password
bf2cabcd 24char *welcomemsg; // Welcome Message
448a1531 25char *ignoreserverslist; // Servernames to ignore
5431156e 26char *nsname; // NickServ's name
27char *nspass; // GameServ's NickServ Password
28
922daad7 29int welcomedelay; // Welcome Message Delay
30int updateperiod; // Seconds until another player database update
20d5d721 31int forestfights; // Forest fights per day
8450c018 32int maxafightdistance; // Max levels above a player they can fight player->player
33int maxbfightdistance; // Max levels below a player they can fight player->player
40251952 34int maxidletime; // Max time (in seconds) a player can be idle for
35int idlecheckperiod; // Period for checking every player's idle time
14e24ba1 36int level1expire; // Days for level 1 players to expire
37int defaultexpire; // Days for other levels to expire
1ee4a31b 38int maxitems; // Maximum amount of items a player can carry
4bcfa863 39long refreshperiod; // Period for refreshing players
1fe6fccd 40long rolloverperiod; // Period for rolling over forest fights
41long configflags; // Holds the binary representation of some boolean values
42long maxforestfights; // Maximum amount of forest fights to roll over
7fdd9c86 43long numrolloverfights; // Number of forest fights to roll over
85ce9d3e 44
45// Remote server stuff. This is used for the outgoing connection gameserv needs to make
46// to a real ircd.
47char *remoteserver; // Server to connect to
285f72cf 48char *localhost; // Hostname of the local address to bind to
49int remoteport; // Port to connect to on remoteserver
85ce9d3e 50char *remotepass; // Password for the server link
51
3f107f27 52char *storeitemdata; // File to store the items available in the store
c7bceafd 53char *tavernitemdata; // File to store the items available in the tavern
ec4605a9 54char *itemdata; // File to store the items in
85ce9d3e 55char *playerdata; // File to store player data in
8e800549 56char *dragondata; // File to store current dragon data in
57char *masterdata; // File to store the master data in
c260a8d7 58char *newsdata; // File to store news data in
69ae096c 59char *pidfile; // Process ID file
85ce9d3e 60
e1c41a84 61#if defined(P10)
392daa60 62char *gsnum = "[]AAA"; // GameServ Numeric
e1c41a84 63#endif
64
85ce9d3e 65void unload_config_file()
66{
3f107f27 67 if (s_GameServ)
68 delete [] s_GameServ;
69 if (gshost)
70 delete [] gshost;
71 if (gsident)
72 delete [] gsident;
73 if (servername)
74 delete [] servername;
75 if (c_Forest)
76 delete [] c_Forest;
77 if (c_ForestTopic)
78 delete [] c_ForestTopic;
79 if (remoteserver)
80 delete [] remoteserver;
285f72cf 81 if (localhost)
82 delete [] localhost;
3f107f27 83 if (remotepass)
84 delete [] remotepass;
85 if (playerdata)
86 delete [] playerdata;
87 if (storeitemdata)
88 delete [] storeitemdata;
89 if (tavernitemdata)
90 delete [] tavernitemdata;
91 if (itemdata)
92 delete [] itemdata;
93 if (dragondata)
94 delete [] dragondata;
95 if (masterdata)
96 delete [] masterdata;
97 if (adminpass)
98 delete [] adminpass;
99 if (welcomemsg)
100 delete [] welcomemsg;
101 if (pidfile)
102 delete [] pidfile;
103 if (ignoreserverslist)
104 delete [] ignoreserverslist;
105 if (newsdata)
106 delete [] newsdata;
107 if (nsname)
108 delete [] nsname;
109 if (nspass)
110 delete [] nspass;
392daa60 111
3f107f27 112 configflags = 0;
85ce9d3e 113}
bf2cabcd 114
624c0352 115int load_config_file(char *config)
85ce9d3e 116{
392daa60 117 char *buf, *directive, *value;
118
119#define numdirectives 39
120
121 unload_config_file();
122
123 struct DIRECTIVE {
1e1b5312 124 bool done;
125 char *desc;
392daa60 126 };
127
128 DIRECTIVE directives[numdirectives];
129
130 directives[0].desc = "s_GameServ - GameServ Nickname";
131 directives[1].desc = "GSHOST - GameServ Hostname";
132 directives[2].desc = "GSIDENT - GameServ Ident";
133 directives[3].desc = "SERVERNAME - Pseudo Server's Name";
134 directives[4].desc = "C_FOREST - Forest Channel";
135 directives[5].desc = "C_FORESTTOPIC - Topic for the Forest Channel";
136 directives[6].desc = "REMOTESERVER - Server for gameserv to connect to (ip or hostname)";
137 directives[7].desc = "REMOTEPORT - Port on the remote server to connect to";
138 directives[8].desc = "REMOTEPASS - Password on the remote server";
139 directives[9].desc = "PLAYERDATA - File to store the player saves in";
140 directives[10].desc = "SAVEDNOTICE - True/False as to wether or not to tell the forest "\
141 "channel that the player database has been saved";
142 directives[11].desc = "ADMINPASS - Password to identify as an admin with";
143 directives[12].desc = "WELCOMEDELAY - Delay (in seconds) to wait before welcoming new users to the network";
144 directives[13].desc = "FORESTFIGHTS - Number of forest fights players get every day";
145 directives[14].desc = "UPDATEPERIOD - Number of seconds between every player data save";
146 directives[15].desc = "PIDFILE - Filename to store the gameserv process ID in";
147 directives[16].desc = "MAXAFIGHTDISTANCE - The maximum number of levels above you "\
148 "that you can fight player->player";
149 directives[17].desc = "MAXBFIGHTDISTANCE - The maximum number of levels below you "\
150 "that you can fight player->player";
151 directives[18].desc = "MAXIDLETIME - The maximum amount of time (in seconds) "\
152 "that a player can be idle before something happens";
153 directives[19].desc = "IDLECHECKPERIOD - The period (in seconds) in which the entire "\
154 "players list will be checked for idlers. See also: "\
155 "MAXIDLETIME";
156 directives[20].desc = "LISTENONC_FOREST - True/False as to "\
157 "whether or not to listen for forest "\
158 "commands on the forest channel";
159 directives[21].desc = "NEWSDATA - File to store daily news in";
160 directives[22].desc = "REFRESHPERIOD - Period (in seconds) to "\
161 "refresh players";
162 directives[23].desc = "LEVEL1EXPIRE - Amount of days until a "\
163 "level 1 player's account is deleted due to "\
164 "inactivity.";
165 directives[24].desc = "DEFAULTEXPIRE - Amount of days until a "\
166 "level 2 and above player's account is "\
167 "deleted due to inactivity";
168 directives[25].desc = "USENICKSERV - True/False as to wether or not "\
169 "GameServ should identify with NickServ";
170 directives[26].desc = "NSNAME - Your network's NickServ nickname";
171 directives[27].desc = "NSPASS - GameServ's NickServ Password";
172 directives[28].desc = "DRAGONDATA - File to store the current "\
173 "dragon's stats in";
174 directives[29].desc = "MASTERDATA - File to store the level master stats in";
175 directives[30].desc = "ITEMDATA - File to store the items in";
176 directives[31].desc = "TAVERNITEMDATA - File in which to store the items that are available in the tavern";
177 directives[32].desc = "MAXITEMS - Maximum number of items a player can carry";
178 directives[33].desc = "STOREITEMDATA - File in which to store the items that are available in the store";
179 directives[34].desc = "LOCALHOST - Local hostname or IP to bind to when connecting to the remote server";
180 directives[35].desc = "ROLLOVERFORESTFIGHTS - True/False as to wether or not to roll over forest fights "\
181 "into the next day";
182 directives[36].desc = "MAXFORESTFIGHTS - Maximum amount of forest fights to roll over";
183 directives[37].desc = "ROLLOVERPERIOD - Period (in seconds) to rollover forest fights";
184 directives[38].desc = "NUMROLLOVERFIGHTS - Number of forest fights to roll over";
185
186 configflags = 0;
187
188 for (int count = 0; count < numdirectives; count++)
1e1b5312 189 {
392daa60 190 directives[count].done = false;
1e1b5312 191 }
392daa60 192
193 ifstream infile;
194 infile.open(config);
195 if (infile.fail())
85ce9d3e 196 {
392daa60 197 log("Error opening %s", config);
198 cerr << "Error opening " << config << endl;
199 return 0;
85ce9d3e 200 }
392daa60 201
202 buf = new char[1024];
203
204 while (infile.getline(buf, 1024, '\n'))
85ce9d3e 205 {
392daa60 206#ifdef DEBUGMODE
207 log("Config file entry buf: %s", buf);
208#endif
209
210 if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r')
85ce9d3e 211 continue;
392daa60 212
213 directive = strtok(buf, " ");
214
215 if (stricmp(directive, "DIE") == 0)
216 {
217 value = strtok(NULL, "");
218 log("You should read the entire %s file!", config);
219 cerr << "You should read the entire " << config << " file!"
220 << endl;
221 delete []buf;
222 exit(0);
223 }
224 if (stricmp(directive, "S_GAMESERV") == 0)
225 {
226 value = strtok(NULL, " ");
227 s_GameServ = new char[strlen(value) + 1];
228 strcpy(s_GameServ, value);
229 directives[0].done = true;
230 }
231 else if (stricmp(directive, "GSHOST") == 0)
232 {
233 value = strtok(NULL, " ");
234 gshost = new char[strlen(value) + 1];
235 strcpy(gshost, value);
236 directives[1].done = true;
237 }
238 else if (stricmp(directive, "GSIDENT") == 0)
239 {
240 value = strtok(NULL, " ");
241 gsident = new char[strlen(value) + 1];
242 strcpy(gsident, value);
243 directives[2].done = true;
244 }
245 else if (stricmp(directive, "SERVERNAME") == 0)
246 {
247 value = strtok(NULL, " ");
248 servername = new char[strlen(value) + 1];
249 strcpy(servername, value);
250 directives[3].done = true;
251 }
252 else if (stricmp(directive, "C_FOREST") == 0)
253 {
254 value = strtok(NULL, " ");
255 c_Forest = new char[strlen(value) + 1];
256 strcpy(c_Forest, value);
257 directives[4].done = true;
258 }
259 else if (stricmp(directive, "C_FORESTTOPIC") == 0)
260 {
261 value = strtok(NULL, "");
262 c_ForestTopic = new char[strlen(value) + 1];
263 strcpy(c_ForestTopic, value);
264 directives[5].done = true;
265 }
266 else if (stricmp(directive, "REMOTESERVER") == 0)
267 {
268 value = strtok(NULL, " ");
269 remoteserver = new char[strlen(value) + 1];
270 strcpy(remoteserver, value);
271 directives[6].done = true;
272 }
273 else if (stricmp(directive, "REMOTEPORT") == 0)
274 {
275 value = strtok(NULL, " ");
276 remoteport = stringtoint(value);
277 directives[7].done = true;
278 }
279 else if (stricmp(directive, "REMOTEPASS") == 0)
280 {
281 value = strtok(NULL, "");
282 remotepass = new char[strlen(value) + 1];
283 strcpy(remotepass, value);
284 directives[8].done = true;
285 }
286 else if (stricmp(directive, "PLAYERDATA") == 0)
287 {
288 value = strtok(NULL, "");
289 playerdata = new char[strlen(value) + 1];
290 strcpy(playerdata, value);
291 directives[9].done = true;
292 }
293 else if (stricmp(directive, "SAVEDNOTICE") == 0)
294 {
295 value = strtok(NULL, "");
296 if (stricmp(value, "TRUE") == 0)
297 setSavedNotice();
298 directives[10].done = true;
299 }
300 else if (stricmp(directive, "ADMINPASS") == 0)
301 {
302 value = strtok(NULL, "");
303 adminpass = new char[strlen(value) + 1];
304 strcpy(adminpass, value);
305 directives[11].done = true;
306 }
307 else if (stricmp(directive, "WELCOMEDELAY") == 0)
308 {
309 value = strtok(NULL, " ");
310 welcomedelay = stringtoint(value);
311 directives[12].done = true;
312 }
313 else if (stricmp(directive, "FORESTFIGHTS") == 0)
314 {
315 value = strtok(NULL, " ");
316 forestfights = stringtoint(value);
317 directives[13].done = true;
318 }
319 else if (stricmp(directive, "UPDATEPERIOD") == 0)
320 {
321 value = strtok(NULL, " ");
322 updateperiod = stringtoint(value);
323 directives[14].done = true;
324 }
325 else if (stricmp(directive, "PIDFILE") == 0)
326 {
327 value = strtok(NULL, " ");
328 pidfile = new char[strlen(value) + 1];
329 strcpy(pidfile, value);
330 directives[15].done = true;
331 }
332 else if (stricmp(directive, "MAXAFIGHTDISTANCE") == 0)
333 {
334 value = strtok(NULL, " ");
335 maxafightdistance = stringtoint(value);
336 directives[16].done = true;;
337 }
338 else if (stricmp(directive, "MAXBFIGHTDISTANCE") == 0)
339 {
340 value = strtok(NULL, " ");
341 maxbfightdistance = stringtoint(value);
342 directives[17].done = true;
343 }
344 else if (stricmp(directive, "MAXIDLETIME") == 0)
345 {
346 value = strtok(NULL, " ");
347 maxidletime = stringtoint(value);
348 directives[18].done = true;
349 }
350 else if (stricmp(directive, "IDLECHECKPERIOD") == 0)
351 {
352 value = strtok(NULL, " ");
353 idlecheckperiod = stringtoint(value);
354 directives[19].done = true;
355 }
356 else if (stricmp(directive, "LISTENONC_FOREST") == 0)
357 {
358 value = strtok(NULL, " ");
359 if(stricmp(value, "TRUE") == 0)
360 {
361 setListenOnCF();
362 }
363
364 directives[20].done = true;
365 }
366 else if (stricmp(directive, "NEWSDATA") == 0)
367 {
368 value = strtok(NULL, " ");
369 newsdata = new char [strlen(value) + 1];
370 strcpy(newsdata, value);
371 directives[21].done = true;
372 }
373 else if (stricmp(directive, "REFRESHPERIOD") == 0)
374 {
375 value = strtok(NULL, " ");
376 refreshperiod = stringtoint(value);
377 directives[22].done = true;
378 }
379 else if (stricmp(directive, "LEVEL1EXPIRE") == 0)
380 {
381 value = strtok(NULL, " ");
382 level1expire = stringtoint(value);
383 directives[23].done = true;
384 }
385 else if (stricmp(directive, "DEFAULTEXPIRE") == 0)
386 {
387 value = strtok(NULL, " ");
388 defaultexpire = stringtoint(value);
389 directives[24].done = true;
390 }
391 else if (stricmp(directive, "USENICKSERV") == 0)
392 {
393 value = strtok(NULL, " ");
394 if (stricmp(value, "TRUE") == 0)
395 {
396 setUseNickServ();
397 }
398
399 directives[25].done = true;
400 }
401 else if (stricmp(directive, "NSNAME") == 0)
402 {
403 value = strtok(NULL, "");
404 nsname = new char[strlen(value) + 1];
405 strcpy(nsname, value);
406 directives[26].done = true;
407 }
408 else if (stricmp(directive, "NSPASS") == 0)
409 {
410 value = strtok(NULL, "");
411 nspass = new char[strlen(value) + 1];
412 strcpy(nspass, value);
413 directives[27].done = true;
414 }
415 else if (stricmp(directive, "DRAGONDATA") == 0)
416 {
417 value = strtok(NULL, "");
418 dragondata = new char[strlen(value) + 1];
419 strcpy(dragondata, value);
420 directives[28].done = true;
421 }
422 else if (stricmp(directive, "MASTERDATA") == 0)
423 {
424 value = strtok(NULL, "");
425 masterdata = new char[strlen(value) + 1];
426 strcpy(masterdata, value);
427 directives[29].done = true;
428 }
429 else if (stricmp(directive, "ITEMDATA") == 0)
430 {
431 value = strtok(NULL, "");
432 itemdata = new char[strlen(value) + 1];
433 strcpy(itemdata, value);
434 directives[30].done = true;
435 }
436 else if (stricmp(directive, "TAVERNITEMDATA") == 0)
437 {
438 value = strtok(NULL, "");
439 tavernitemdata = new char[strlen(value) + 1];
440 strcpy(tavernitemdata, value);
441 directives[31].done = true;
442 }
443 else if (stricmp(directive, "MAXITEMS") == 0)
444 {
445 value = strtok(NULL, "");
446 maxitems = stringtoint(value);
447 directives[32].done = true;
448 }
449 else if (stricmp(directive, "STOREITEMDATA") == 0)
450 {
451 value = strtok(NULL, "");
452 storeitemdata = new char[strlen(value) + 1];
453 strcpy(storeitemdata, value);
454 directives[33].done = true;
455 }
456 else if (stricmp(directive, "LOCALHOST") == 0)
457 {
458 value = strtok(NULL, "");
459 localhost = new char[strlen(value) + 1];
460 strcpy(localhost, value);
461 directives[34].done = true;
462 }
463 else if (stricmp(directive, "ROLLOVERFORESTFIGHTS") == 0)
464 {
465 value = strtok(NULL, " ");
466 if (stricmp(value, "TRUE") == 0)
467 {
468 setRolloverForestFights();
469 }
470 else
471 {
472 directives[36].done = true;
473 directives[37].done = true;
474 directives[38].done = true;
475 }
476 directives[35].done = true;
477 }
478 else if (stricmp(directive, "MAXFORESTFIGHTS") == 0)
479 {
480 value = strtok(NULL, "");
481 maxforestfights = stringtoint(value);
482 directives[36].done = true;
483 }
484 else if (stricmp(directive, "ROLLOVERPERIOD") == 0)
485 {
486 value = strtok(NULL, "");
487 rolloverperiod = stringtoint(value);
488 directives[37].done = true;
489 }
490 else if (stricmp(directive, "NUMROLLOVERFIGHTS") == 0)
491 {
492 value = strtok(NULL, "");
493 numrolloverfights = stringtoint(value);
494 directives[38].done = true;
495 }
496 else if (stricmp(directive, "WELCOMEMSG") == 0)
497 {
498 // This directive is optional
499 value = strtok(NULL, "");
500 welcomemsg = new char[strlen(value) + 1];
501 strcpy(welcomemsg, value);
502 setWelcome();
503 }
504 else if (stricmp(directive, "USEPRIVMSG") == 0)
505 {
506 // This directive is optional
507 setUsePrivmsg();
508 }
509 else if (stricmp(directive, "BOPER") == 0)
510 {
511 // This directive is optional
512 setBOper();
513 }
514 else if (stricmp(directive, "IGNORESERVERS") == 0)
515 {
516 // This directive is optional
517 value = strtok(NULL, "");
518 ignoreserverslist = new char[strlen(value) + 1];
519 strcpy(ignoreserverslist, value);
520 }
521 else
522 {
523#ifdef DEBUGMODE
524 log("Unknown Directive. Buffer: %s", buf);
525 cerr << "Unknown " << config << " directive. Buffer: "
526 << buf << endl;
527#endif
528 continue;
529 }
1e1b5312 530 }
392daa60 531 delete [] buf;
532 infile.close();
533
534 int nonemissing = 1;
535 for (int count2 = 0; count2 < numdirectives; count2++)
536 {
537 if (!directives[count2].done)
538 {
539 cerr << "Missing config directive: " << directives[count2].desc << endl;
540 nonemissing = 0;
541 }
542 }
543
544 return nonemissing;
85ce9d3e 545}