]> jfr.im git - irc/gameservirc.git/blame_incremental - gameserv/config.cpp
Updated the change log for the numrolloverfights directive
[irc/gameservirc.git] / gameserv / config.cpp
... / ...
CommitLineData
1#include <fstream>
2#include <string.h>
3#include <stdlib.h>
4#include <stdio.h>
5#include "extern.h"
6#include "flags.h"
7
8using std::ifstream;
9using std::cerr;
10using std::endl;
11
12int load_config_file(char *config);
13void unload_config_file();
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
23char *adminpass; // Administrator password
24char *welcomemsg; // Welcome Message
25char *ignoreserverslist; // Servernames to ignore
26char *nsname; // NickServ's name
27char *nspass; // GameServ's NickServ Password
28
29int welcomedelay; // Welcome Message Delay
30int updateperiod; // Seconds until another player database update
31int forestfights; // Forest fights per day
32int maxafightdistance; // Max levels above a player they can fight player->player
33int maxbfightdistance; // Max levels below a player they can fight player->player
34int maxidletime; // Max time (in seconds) a player can be idle for
35int idlecheckperiod; // Period for checking every player's idle time
36int level1expire; // Days for level 1 players to expire
37int defaultexpire; // Days for other levels to expire
38int maxitems; // Maximum amount of items a player can carry
39long refreshperiod; // Period for refreshing players
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
43long numrolloverfights; // Number of forest fights to roll over
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
48char *localhost; // Hostname of the local address to bind to
49int remoteport; // Port to connect to on remoteserver
50char *remotepass; // Password for the server link
51
52char *storeitemdata; // File to store the items available in the store
53char *tavernitemdata; // File to store the items available in the tavern
54char *itemdata; // File to store the items in
55char *playerdata; // File to store player data in
56char *dragondata; // File to store current dragon data in
57char *masterdata; // File to store the master data in
58char *newsdata; // File to store news data in
59char *pidfile; // Process ID file
60
61#if defined(P10)
62 char *gsnum = "[]AAA"; // GameServ Numeric
63#endif
64
65void unload_config_file()
66{
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;
81 if (localhost)
82 delete [] localhost;
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;
111
112 configflags = 0;
113}
114
115int load_config_file(char *config)
116{
117 char *buf, *directive, *value;
118
119 #define numdirectives 39
120
121 unload_config_file();
122
123 struct DIRECTIVE {
124 bool done;
125 char *desc;
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++)
189 {
190 directives[count].done = false;
191 }
192
193 ifstream infile;
194 infile.open(config);
195 if (infile.fail())
196 {
197 log("Error opening %s", config);
198 cerr << "Error opening " << config << endl;
199 return 0;
200 }
201
202 buf = new char[1024];
203
204 while (infile.getline(buf, 1024, '\n'))
205 {
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')
211 continue;
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 setListenOnCF();
361
362 directives[20].done = true;
363 }
364 else if (stricmp(directive, "NEWSDATA") == 0)
365 {
366 value = strtok(NULL, " ");
367 newsdata = new char [strlen(value) + 1];
368 strcpy(newsdata, value);
369 directives[21].done = true;
370 }
371 else if (stricmp(directive, "REFRESHPERIOD") == 0)
372 {
373 value = strtok(NULL, " ");
374 refreshperiod = stringtoint(value);
375 directives[22].done = true;
376 }
377 else if (stricmp(directive, "LEVEL1EXPIRE") == 0)
378 {
379 value = strtok(NULL, " ");
380 level1expire = stringtoint(value);
381 directives[23].done = true;
382 }
383 else if (stricmp(directive, "DEFAULTEXPIRE") == 0)
384 {
385 value = strtok(NULL, " ");
386 defaultexpire = stringtoint(value);
387 directives[24].done = true;
388 }
389 else if (stricmp(directive, "USENICKSERV") == 0)
390 {
391 value = strtok(NULL, " ");
392 if (stricmp(value, "TRUE") == 0)
393 {
394 setUseNickServ();
395 }
396
397 directives[25].done = true;
398 }
399 else if (stricmp(directive, "NSNAME") == 0)
400 {
401 value = strtok(NULL, "");
402 nsname = new char[strlen(value) + 1];
403 strcpy(nsname, value);
404 directives[26].done = true;
405 }
406 else if (stricmp(directive, "NSPASS") == 0)
407 {
408 value = strtok(NULL, "");
409 nspass = new char[strlen(value) + 1];
410 strcpy(nspass, value);
411 directives[27].done = true;
412 }
413 else if (stricmp(directive, "DRAGONDATA") == 0)
414 {
415 value = strtok(NULL, "");
416 dragondata = new char[strlen(value) + 1];
417 strcpy(dragondata, value);
418 directives[28].done = true;
419 }
420 else if (stricmp(directive, "MASTERDATA") == 0)
421 {
422 value = strtok(NULL, "");
423 masterdata = new char[strlen(value) + 1];
424 strcpy(masterdata, value);
425 directives[29].done = true;
426 }
427 else if (stricmp(directive, "ITEMDATA") == 0)
428 {
429 value = strtok(NULL, "");
430 itemdata = new char[strlen(value) + 1];
431 strcpy(itemdata, value);
432 directives[30].done = true;
433 }
434 else if (stricmp(directive, "TAVERNITEMDATA") == 0)
435 {
436 value = strtok(NULL, "");
437 tavernitemdata = new char[strlen(value) + 1];
438 strcpy(tavernitemdata, value);
439 directives[31].done = true;
440 }
441 else if (stricmp(directive, "MAXITEMS") == 0)
442 {
443 value = strtok(NULL, "");
444 maxitems = stringtoint(value);
445 directives[32].done = true;
446 }
447 else if (stricmp(directive, "STOREITEMDATA") == 0)
448 {
449 value = strtok(NULL, "");
450 storeitemdata = new char[strlen(value) + 1];
451 strcpy(storeitemdata, value);
452 directives[33].done = true;
453 }
454 else if (stricmp(directive, "LOCALHOST") == 0)
455 {
456 value = strtok(NULL, "");
457 localhost = new char[strlen(value) + 1];
458 strcpy(localhost, value);
459 directives[34].done = true;
460 }
461 else if (stricmp(directive, "ROLLOVERFORESTFIGHTS") == 0)
462 {
463 value = strtok(NULL, " ");
464 if (stricmp(value, "TRUE") == 0)
465 {
466 setRolloverForestFights();
467 }
468 else
469 {
470 directives[36].done = true;
471 directives[37].done = true;
472 directives[38].done = true;
473 }
474 directives[35].done = true;
475 }
476 else if (stricmp(directive, "MAXFORESTFIGHTS") == 0)
477 {
478 value = strtok(NULL, "");
479 maxforestfights = stringtoint(value);
480 directives[36].done = true;
481 }
482 else if (stricmp(directive, "ROLLOVERPERIOD") == 0)
483 {
484 value = strtok(NULL, "");
485 rolloverperiod = stringtoint(value);
486 directives[37].done = true;
487 }
488 else if (stricmp(directive, "NUMROLLOVERFIGHTS") == 0)
489 {
490 value = strtok(NULL, "");
491 numrolloverfights = stringtoint(value);
492 directives[38].done = true;
493 }
494 else if (stricmp(directive, "WELCOMEMSG") == 0)
495 {
496 // This directive is optional
497 value = strtok(NULL, "");
498 welcomemsg = new char[strlen(value) + 1];
499 strcpy(welcomemsg, value);
500 setWelcome();
501 }
502 else if (stricmp(directive, "USEPRIVMSG") == 0)
503 {
504 // This directive is optional
505 setUsePrivmsg();
506 }
507 else if (stricmp(directive, "BOPER") == 0)
508 {
509 // This directive is optional
510 setBOper();
511 }
512 else if (stricmp(directive, "IGNORESERVERS") == 0)
513 {
514 // This directive is optional
515 value = strtok(NULL, "");
516 ignoreserverslist = new char[strlen(value) + 1];
517 strcpy(ignoreserverslist, value);
518 }
519 else
520 {
521 #ifdef DEBUGMODE
522 log("Unknown Directive. Buffer: %s", buf);
523 cerr << "Unknown " << config << " directive. Buffer: "
524 << buf << endl;
525 #endif
526 continue;
527 }
528 }
529delete [] buf;
530infile.close();
531
532 int nonemissing = 1;
533 for (int count2 = 0; count2 < numdirectives; count2++)
534 {
535 if (!directives[count2].done)
536 {
537 cerr << "Missing config directive: " << directives[count2].desc << endl;
538 nonemissing = 0;
539 }
540 }
541
542 return nonemissing;
543}