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