]>
Commit | Line | Data |
---|---|---|
1 | #include <fstream> | |
2 | #include <iostream> | |
3 | #include <string.h> | |
4 | #include <stdlib.h> | |
5 | #include <stdio.h> | |
6 | #include "extern.h" | |
7 | #include "flags.h" | |
8 | ||
9 | using namespace std; | |
10 | ||
11 | int load_config_file(char *config); | |
12 | void unload_config_file(); | |
13 | ||
14 | /* Random Configuration Stuff Goes Here until I code it to load from a .conf file :)*/ | |
15 | ||
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 | |
27 | ||
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 | |
44 | ||
45 | ||
46 | // Remote server stuff. This is used for the outgoing connection gameserv needs to make | |
47 | // to a real ircd. | |
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 | |
52 | ||
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 | ||
62 | #if defined(P10) | |
63 | char *gsnum = "[]AAA"; // GameServ Numeric | |
64 | #endif | |
65 | ||
66 | void unload_config_file() | |
67 | { | |
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; | |
82 | if (localhost) | |
83 | delete [] localhost; | |
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; | |
112 | ||
113 | configflags = 0; | |
114 | } | |
115 | ||
116 | int load_config_file(char *config) | |
117 | { | |
118 | char *buf, *directive, *value; | |
119 | ||
120 | #define numdirectives 41 | |
121 | ||
122 | unload_config_file(); | |
123 | ||
124 | struct DIRECTIVE { | |
125 | bool done; | |
126 | char *desc; | |
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"; | |
186 | directives[39].desc = "FAIRFIGHTS - True/False as to whether or not to check for fair fights"; | |
187 | directives[40].desc = "MAXNICKLEN - Maximum length a nickname can be"; | |
188 | ||
189 | configflags = 0; | |
190 | ||
191 | for (int count = 0; count < numdirectives; count++) | |
192 | { | |
193 | directives[count].done = false; | |
194 | } | |
195 | ||
196 | ifstream infile; | |
197 | infile.open(config); | |
198 | if (infile.fail()) | |
199 | { | |
200 | log("Error opening %s", config); | |
201 | cerr << "Error opening " << config << endl; | |
202 | return 0; | |
203 | } | |
204 | ||
205 | buf = new char[1024]; | |
206 | ||
207 | while (infile.getline(buf, 1024, '\n')) | |
208 | { | |
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') | |
214 | continue; | |
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 | { | |
284 | value = strtok(NULL, " "); | |
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 | { | |
298 | value = strtok(NULL, " "); | |
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 | { | |
406 | value = strtok(NULL, " "); | |
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 | { | |
413 | value = strtok(NULL, " "); | |
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 | { | |
448 | value = strtok(NULL, " "); | |
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 | { | |
461 | value = strtok(NULL, " "); | |
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 | { | |
483 | value = strtok(NULL, " "); | |
484 | maxforestfights = stringtoint(value); | |
485 | directives[36].done = true; | |
486 | } | |
487 | else if (stricmp(directive, "ROLLOVERPERIOD") == 0) | |
488 | { | |
489 | value = strtok(NULL, " "); | |
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 | } | |
499 | else if (stricmp(directive, "FAIRFIGHTS") == 0) | |
500 | { | |
501 | value = strtok(NULL, " "); | |
502 | if (stricmp(value, "TRUE") == 0) | |
503 | setFairFights(); | |
504 | directives[39].done = true; | |
505 | } | |
506 | else if (stricmp(directive, "MAXNICKLEN") == 0) | |
507 | { | |
508 | value = strtok(NULL, " "); | |
509 | maxnicklen = stringtoint(value); | |
510 | directives[40].done = true; | |
511 | } | |
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 | } | |
546 | } | |
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; | |
561 | } |