]>
jfr.im git - irc/gameservirc.git/blob - gameserv/config.cpp
12 int load_config_file(char *config
);
13 void unload_config_file();
15 /* Random Configuration Stuff Goes Here until I code it to load from a .conf file :)*/
17 char *s_GameServ
; // GameServ's nickname
18 char *gshost
; // GameServ's Hostname
19 char *gsident
; // GameServ's ident/username
20 char *servername
; // GameServ's Server
21 char *c_Forest
; // Forest channel
22 char *c_ForestTopic
; // Forest Channel Topic
23 char *adminpass
; // Administrator password
24 char *welcomemsg
; // Welcome Message
25 char *ignoreserverslist
; // Servernames to ignore
26 char *nsname
; // NickServ's name
27 char *nspass
; // GameServ's NickServ Password
29 int welcomedelay
; // Welcome Message Delay
30 int updateperiod
; // Seconds until another player database update
31 int forestfights
; // Forest fights per day
32 int maxafightdistance
; // Max levels above a player they can fight player->player
33 int maxbfightdistance
; // Max levels below a player they can fight player->player
34 int maxidletime
; // Max time (in seconds) a player can be idle for
35 int idlecheckperiod
; // Period for checking every player's idle time
36 int level1expire
; // Days for level 1 players to expire
37 int defaultexpire
; // Days for other levels to expire
38 long refreshperiod
; // Period for refreshing players
39 long configflags
; // Holds the bit representation of some boolean values
41 // Remote server stuff. This is used for the outgoing connection gameserv needs to make
43 char *remoteserver
; // Server to connect to
44 char *remoteport
; // Port to connect to on remoteserver
45 char *remotepass
; // Password for the server link
47 char *playerdata
; // File to store player data in
48 char *newsdata
; // File to store news data in
49 char *pidfile
; // Process ID file
52 char *gsnum
= "[]AAA"; // GameServ Numeric
55 void unload_config_file()
68 delete [] c_ForestTopic
;
70 delete [] remoteserver
;
83 if (ignoreserverslist
)
84 delete [] ignoreserverslist
;
95 int load_config_file(char *config
)
97 char *buf
, *directive
, *value
;
99 #define numdirectives 28
101 unload_config_file();
108 DIRECTIVE directives
[numdirectives
];
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";
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";
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";
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 "\
128 "that you can fight player->player";
129 directives
[17].desc
= "MAXBFIGHTDISTANCE - The maximum number of levels below you "\
130 "that you can fight player->player";
131 directives
[18].desc
= "MAXIDLETIME - The maximum amount of time (in seconds) "\
132 "that a player can be idle before something happens";
133 directives
[19].desc
= "IDLECHECKPERIOD - The period (in seconds) in which the entire "\
134 "players list will be checked for idlers. See also: "\
136 directives
[20].desc
= "LISTENONC_FOREST - True/False as to "\
137 "whether or not to listen for forest "\
138 "commands on the forest channel";
139 directives
[21].desc
= "NEWSDATA - File to store daily news in";
140 directives
[22].desc
= "REFRESHPERIOD - Period (in seconds) to "\
142 directives
[23].desc
= "LEVEL1EXPIRE - Amount of days until a "\
143 "level 1 player's account is deleted due to "\
145 directives
[24].desc
= "DEFAULTEXPIRE - Amount of days until a "\
146 "level 2 and above player's account is "\
147 "deleted due to inactivity";
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";
155 for (int count
= 0; count
< numdirectives
; count
++)
157 directives
[count
].done
= false;
164 log("Error opening %s", config
);
165 cerr
<< "Error opening " << config
<< endl
;
169 buf
= new char[1024];
171 while (infile
.getline(buf
, 1024, '\n'))
174 log("Config file entry buf: %s", buf
);
177 if (buf
[0] == '#' || buf
[0] == ' ' || buf
[0] == '\0' || buf
[0] == '\n' || buf
[0] == '\r')
180 directive
= strtok(buf
, " ");
182 if (stricmp(directive
, "DIE") == 0)
184 value
= strtok(NULL
, "");
185 log("You should read the entire %s file!", config
);
186 cerr
<< "You should read the entire " << config
<< " file!"
191 if (stricmp(directive
, "S_GAMESERV") == 0)
193 value
= strtok(NULL
, " ");
194 s_GameServ
= new char[strlen(value
) + 1];
195 strcpy(s_GameServ
, value
);
196 directives
[0].done
= true;
198 else if (stricmp(directive
, "GSHOST") == 0)
200 value
= strtok(NULL
, " ");
201 gshost
= new char[strlen(value
) + 1];
202 strcpy(gshost
, value
);
203 directives
[1].done
= true;
205 else if (stricmp(directive
, "GSIDENT") == 0)
207 value
= strtok(NULL
, " ");
208 gsident
= new char[strlen(value
) + 1];
209 strcpy(gsident
, value
);
210 directives
[2].done
= true;
212 else if (stricmp(directive
, "SERVERNAME") == 0)
214 value
= strtok(NULL
, " ");
215 servername
= new char[strlen(value
) + 1];
216 strcpy(servername
, value
);
217 directives
[3].done
= true;
219 else if (stricmp(directive
, "C_FOREST") == 0)
221 value
= strtok(NULL
, " ");
222 c_Forest
= new char[strlen(value
) + 1];
223 strcpy(c_Forest
, value
);
224 directives
[4].done
= true;
226 else if (stricmp(directive
, "C_FORESTTOPIC") == 0)
228 value
= strtok(NULL
, "");
229 c_ForestTopic
= new char[strlen(value
) + 1];
230 strcpy(c_ForestTopic
, value
);
231 directives
[5].done
= true;
233 else if (stricmp(directive
, "REMOTESERVER") == 0)
235 value
= strtok(NULL
, " ");
236 remoteserver
= new char[strlen(value
) + 1];
237 strcpy(remoteserver
, value
);
238 directives
[6].done
= true;
240 else if (stricmp(directive
, "REMOTEPORT") == 0)
242 value
= strtok(NULL
, " ");
243 remoteport
= new char[strlen(value
) + 1];
244 strcpy(remoteport
, value
);
245 directives
[7].done
= true;
247 else if (stricmp(directive
, "REMOTEPASS") == 0)
249 value
= strtok(NULL
, "");
250 remotepass
= new char[strlen(value
) + 1];
251 strcpy(remotepass
, value
);
252 directives
[8].done
= true;
254 else if (stricmp(directive
, "PLAYERDATA") == 0)
256 value
= strtok(NULL
, "");
257 playerdata
= new char[strlen(value
) + 1];
258 strcpy(playerdata
, value
);
259 directives
[9].done
= true;
261 else if (stricmp(directive
, "SAVEDNOTICE") == 0)
263 value
= strtok(NULL
, "");
264 if (stricmp(value
, "TRUE") == 0)
266 directives
[10].done
= true;
268 else if (stricmp(directive
, "ADMINPASS") == 0)
270 value
= strtok(NULL
, "");
271 adminpass
= new char[strlen(value
) + 1];
272 strcpy(adminpass
, value
);
273 directives
[11].done
= true;
275 else if (stricmp(directive
, "WELCOMEDELAY") == 0)
277 value
= strtok(NULL
, " ");
278 welcomedelay
= stringtoint(value
);
279 directives
[12].done
= true;
281 else if (stricmp(directive
, "FORESTFIGHTS") == 0)
283 value
= strtok(NULL
, " ");
284 forestfights
= stringtoint(value
);
285 directives
[13].done
= true;
287 else if (stricmp(directive
, "UPDATEPERIOD") == 0)
289 value
= strtok(NULL
, " ");
290 updateperiod
= stringtoint(value
);
291 directives
[14].done
= true;
293 else if (stricmp(directive
, "PIDFILE") == 0)
295 value
= strtok(NULL
, " ");
296 pidfile
= new char[strlen(value
) + 1];
297 strcpy(pidfile
, value
);
298 directives
[15].done
= true;
300 else if (stricmp(directive
, "MAXAFIGHTDISTANCE") == 0)
302 value
= strtok(NULL
, " ");
303 maxafightdistance
= stringtoint(value
);
304 directives
[16].done
= true;;
306 else if (stricmp(directive
, "MAXBFIGHTDISTANCE") == 0)
308 value
= strtok(NULL
, " ");
309 maxbfightdistance
= stringtoint(value
);
310 directives
[17].done
= true;
312 else if (stricmp(directive
, "MAXIDLETIME") == 0)
314 value
= strtok(NULL
, " ");
315 maxidletime
= stringtoint(value
);
316 directives
[18].done
= true;
318 else if (stricmp(directive
, "IDLECHECKPERIOD") == 0)
320 value
= strtok(NULL
, " ");
321 idlecheckperiod
= stringtoint(value
);
322 directives
[19].done
= true;
324 else if (stricmp(directive
, "LISTENONC_FOREST") == 0)
326 value
= strtok(NULL
, " ");
327 if (stricmp(value
, "TRUE") == 0)
330 directives
[20].done
= true;
332 else if (stricmp(directive
, "NEWSDATA") == 0)
334 value
= strtok(NULL
, " ");
335 newsdata
= new char [strlen(value
) + 1];
336 strcpy(newsdata
, value
);
337 directives
[21].done
= true;
339 else if (stricmp(directive
, "REFRESHPERIOD") == 0)
341 value
= strtok(NULL
, " ");
342 refreshperiod
= stringtoint(value
);
343 directives
[22].done
= true;
345 else if (stricmp(directive
, "LEVEL1EXPIRE") == 0)
347 value
= strtok(NULL
, " ");
348 level1expire
= stringtoint(value
);
349 directives
[23].done
= true;
351 else if (stricmp(directive
, "DEFAULTEXPIRE") == 0)
353 value
= strtok(NULL
, " ");
354 defaultexpire
= stringtoint(value
);
355 directives
[24].done
= true;
357 else if (stricmp(directive
, "USENICKSERV") == 0)
359 value
= strtok(NULL
, " ");
360 if (stricmp(value
, "TRUE") == 0)
365 directives
[25].done
= true;
367 else if (stricmp(directive
, "NSNAME") == 0)
369 value
= strtok(NULL
, "");
370 nsname
= new char[strlen(value
) + 1];
371 strcpy(nsname
, value
);
372 directives
[26].done
= true;
374 else if (stricmp(directive
, "NSPASS") == 0)
376 value
= strtok(NULL
, "");
377 nspass
= new char[strlen(value
) + 1];
378 strcpy(nspass
, value
);
379 directives
[27].done
= true;
381 else if (stricmp(directive
, "WELCOMEMSG") == 0)
383 // This directive is optional
384 value
= strtok(NULL
, "");
385 welcomemsg
= new char[strlen(value
) + 1];
386 strcpy(welcomemsg
, value
);
389 else if (stricmp(directive
, "USEPRIVMSG") == 0)
391 // This directive is optional
394 else if (stricmp(directive
, "BOPER") == 0)
396 // This directive is optional
399 else if (stricmp(directive
, "IGNORESERVERS") == 0)
401 // This directive is optional
402 value
= strtok(NULL
, "");
403 ignoreserverslist
= new char[strlen(value
) + 1];
404 strcpy(ignoreserverslist
, value
);
409 log("Unknown Directive. Buffer: %s", buf
);
410 cerr
<< "Unknown " << config
<< " directive. Buffer: "
420 for (int count2
= 0; count2
< numdirectives
; count2
++)
422 if (!directives
[count2
].done
)
424 cerr
<< "Missing config directive: " << directives
[count2
].desc
<< endl
;