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