]> jfr.im git - irc/gameservirc.git/blame_incremental - gameserv/config.cpp
Added everything necessary to save overtop of the old dragon when someone beats the...
[irc/gameservirc.git] / gameserv / config.cpp
... / ...
CommitLineData
1#include <fstream>
2#include <string.h>
3#include <stdlib.h>
4#include <stdio.h>
5#include "extern.h"
6#include "flags.h"
7
8using std::ifstream;
9using std::cerr;
10using std::endl;
11
12int load_config_file(char *config);
13void unload_config_file();
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
23char *adminpass; // Administrator password
24char *welcomemsg; // Welcome Message
25char *ignoreserverslist; // Servernames to ignore
26char *nsname; // NickServ's name
27char *nspass; // GameServ's NickServ Password
28
29int welcomedelay; // Welcome Message Delay
30int updateperiod; // Seconds until another player database update
31int forestfights; // Forest fights per day
32int maxafightdistance; // Max levels above a player they can fight player->player
33int maxbfightdistance; // Max levels below a player they can fight player->player
34int maxidletime; // Max time (in seconds) a player can be idle for
35int idlecheckperiod; // Period for checking every player's idle time
36int level1expire; // Days for level 1 players to expire
37int defaultexpire; // Days for other levels to expire
38long refreshperiod; // Period for refreshing players
39long configflags; // Holds the bit representation of some boolean values
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
48char *dragondata; // File to store current dragon data in
49char *masterdata; // File to store the master data in
50char *newsdata; // File to store news data in
51char *pidfile; // Process ID file
52
53#if defined(P10)
54 char *gsnum = "[]AAA"; // GameServ Numeric
55#endif
56
57void unload_config_file()
58{
59 if (s_GameServ)
60 delete [] s_GameServ;
61 if (gshost)
62 delete [] gshost;
63 if (gsident)
64 delete [] gsident;
65 if (servername)
66 delete [] servername;
67 if (c_Forest)
68 delete [] c_Forest;
69 if (c_ForestTopic)
70 delete [] c_ForestTopic;
71 if (remoteserver)
72 delete [] remoteserver;
73 if (remoteport)
74 delete [] remoteport;
75 if (remotepass)
76 delete [] remotepass;
77 if (playerdata)
78 delete [] playerdata;
79 if (dragondata)
80 delete [] dragondata;
81 if (masterdata)
82 delete [] masterdata;
83 if (adminpass)
84 delete [] adminpass;
85 if (welcomemsg)
86 delete [] welcomemsg;
87 if (pidfile)
88 delete [] pidfile;
89 if (ignoreserverslist)
90 delete [] ignoreserverslist;
91 if (newsdata)
92 delete [] newsdata;
93 if (nsname)
94 delete [] nsname;
95 if (nspass)
96 delete [] nspass;
97
98 configflags = 0;
99}
100
101int load_config_file(char *config)
102{
103 char *buf, *directive, *value;
104
105 #define numdirectives 30
106
107 unload_config_file();
108
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";
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";
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";
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 "\
134 "that you can fight player->player";
135 directives[17].desc = "MAXBFIGHTDISTANCE - The maximum number of levels below you "\
136 "that you can fight player->player";
137 directives[18].desc = "MAXIDLETIME - The maximum amount of time (in seconds) "\
138 "that a player can be idle before something happens";
139 directives[19].desc = "IDLECHECKPERIOD - The period (in seconds) in which the entire "\
140 "players list will be checked for idlers. See also: "\
141 "MAXIDLETIME";
142 directives[20].desc = "LISTENONC_FOREST - True/False as to "\
143 "whether or not to listen for forest "\
144 "commands on the forest channel";
145 directives[21].desc = "NEWSDATA - File to store daily news in";
146 directives[22].desc = "REFRESHPERIOD - Period (in seconds) to "\
147 "refresh players";
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";
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";
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";
161
162 configflags = 0;
163
164 for (int count = 0; count < numdirectives; count++)
165 {
166 directives[count].done = false;
167 }
168
169 ifstream infile;
170 infile.open(config);
171 if (infile.fail())
172 {
173 log("Error opening %s", config);
174 cerr << "Error opening " << config << endl;
175 return 0;
176 }
177
178 buf = new char[1024];
179
180 while (infile.getline(buf, 1024, '\n'))
181 {
182 #ifdef DEBUGMODE
183 log("Config file entry buf: %s", buf);
184 #endif
185
186 if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r')
187 continue;
188
189 directive = strtok(buf, " ");
190
191 if (stricmp(directive, "DIE") == 0)
192 {
193 value = strtok(NULL, "");
194 log("You should read the entire %s file!", config);
195 cerr << "You should read the entire " << config << " file!"
196 << endl;
197 delete []buf;
198 exit(0);
199 }
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);
205 directives[0].done = true;
206 }
207 else if (stricmp(directive, "GSHOST") == 0)
208 {
209 value = strtok(NULL, " ");
210 gshost = new char[strlen(value) + 1];
211 strcpy(gshost, value);
212 directives[1].done = true;
213 }
214 else if (stricmp(directive, "GSIDENT") == 0)
215 {
216 value = strtok(NULL, " ");
217 gsident = new char[strlen(value) + 1];
218 strcpy(gsident, value);
219 directives[2].done = true;
220 }
221 else if (stricmp(directive, "SERVERNAME") == 0)
222 {
223 value = strtok(NULL, " ");
224 servername = new char[strlen(value) + 1];
225 strcpy(servername, value);
226 directives[3].done = true;
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);
233 directives[4].done = true;
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);
240 directives[5].done = true;
241 }
242 else if (stricmp(directive, "REMOTESERVER") == 0)
243 {
244 value = strtok(NULL, " ");
245 remoteserver = new char[strlen(value) + 1];
246 strcpy(remoteserver, value);
247 directives[6].done = true;
248 }
249 else if (stricmp(directive, "REMOTEPORT") == 0)
250 {
251 value = strtok(NULL, " ");
252 remoteport = new char[strlen(value) + 1];
253 strcpy(remoteport, value);
254 directives[7].done = true;
255 }
256 else if (stricmp(directive, "REMOTEPASS") == 0)
257 {
258 value = strtok(NULL, "");
259 remotepass = new char[strlen(value) + 1];
260 strcpy(remotepass, value);
261 directives[8].done = true;
262 }
263 else if (stricmp(directive, "PLAYERDATA") == 0)
264 {
265 value = strtok(NULL, "");
266 playerdata = new char[strlen(value) + 1];
267 strcpy(playerdata, value);
268 directives[9].done = true;
269 }
270 else if (stricmp(directive, "SAVEDNOTICE") == 0)
271 {
272 value = strtok(NULL, "");
273 if (stricmp(value, "TRUE") == 0)
274 setSavedNotice();
275 directives[10].done = true;
276 }
277 else if (stricmp(directive, "ADMINPASS") == 0)
278 {
279 value = strtok(NULL, "");
280 adminpass = new char[strlen(value) + 1];
281 strcpy(adminpass, value);
282 directives[11].done = true;
283 }
284 else if (stricmp(directive, "WELCOMEDELAY") == 0)
285 {
286 value = strtok(NULL, " ");
287 welcomedelay = stringtoint(value);
288 directives[12].done = true;
289 }
290 else if (stricmp(directive, "FORESTFIGHTS") == 0)
291 {
292 value = strtok(NULL, " ");
293 forestfights = stringtoint(value);
294 directives[13].done = true;
295 }
296 else if (stricmp(directive, "UPDATEPERIOD") == 0)
297 {
298 value = strtok(NULL, " ");
299 updateperiod = stringtoint(value);
300 directives[14].done = true;
301 }
302 else if (stricmp(directive, "PIDFILE") == 0)
303 {
304 value = strtok(NULL, " ");
305 pidfile = new char[strlen(value) + 1];
306 strcpy(pidfile, value);
307 directives[15].done = true;
308 }
309 else if (stricmp(directive, "MAXAFIGHTDISTANCE") == 0)
310 {
311 value = strtok(NULL, " ");
312 maxafightdistance = stringtoint(value);
313 directives[16].done = true;;
314 }
315 else if (stricmp(directive, "MAXBFIGHTDISTANCE") == 0)
316 {
317 value = strtok(NULL, " ");
318 maxbfightdistance = stringtoint(value);
319 directives[17].done = true;
320 }
321 else if (stricmp(directive, "MAXIDLETIME") == 0)
322 {
323 value = strtok(NULL, " ");
324 maxidletime = stringtoint(value);
325 directives[18].done = true;
326 }
327 else if (stricmp(directive, "IDLECHECKPERIOD") == 0)
328 {
329 value = strtok(NULL, " ");
330 idlecheckperiod = stringtoint(value);
331 directives[19].done = true;
332 }
333 else if (stricmp(directive, "LISTENONC_FOREST") == 0)
334 {
335 value = strtok(NULL, " ");
336 if (stricmp(value, "TRUE") == 0)
337 setListenOnCF();
338
339 directives[20].done = true;
340 }
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 }
348 else if (stricmp(directive, "REFRESHPERIOD") == 0)
349 {
350 value = strtok(NULL, " ");
351 refreshperiod = stringtoint(value);
352 directives[22].done = true;
353 }
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 }
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 }
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 }
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();
411 }
412 else if (stricmp(directive, "USEPRIVMSG") == 0)
413 {
414 // This directive is optional
415 setUsePrivmsg();
416 }
417 else if (stricmp(directive, "BOPER") == 0)
418 {
419 // This directive is optional
420 setBOper();
421 }
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 }
429 else
430 {
431 #ifdef DEBUGMODE
432 log("Unknown Directive. Buffer: %s", buf);
433 cerr << "Unknown " << config << " directive. Buffer: "
434 << buf << endl;
435 #endif
436 continue;
437 }
438 }
439delete [] buf;
440infile.close();
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;
453}