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