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