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