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