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