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