]>
jfr.im git - irc/gameservirc.git/blob - gameserv/config.cpp
13 int load_config_file(char *config
);
14 void unload_config_file();
16 /* Random Configuration Stuff Goes Here until I code it to load from a .conf file :)*/
18 char *s_GameServ
; // GameServ's nickname
19 char *gshost
; // GameServ's Hostname
20 char *gsident
; // GameServ's ident/username
21 char *servername
; // GameServ's Server
22 char *c_Forest
; // Forest channel
23 char *c_ForestTopic
; // Forest Channel Topic
24 char *adminpass
; // Administrator password
25 char *welcomemsg
; // Welcome Message
26 char *ignoreserverslist
; // Servernames to ignore
27 char *nsname
; // NickServ's name
28 char *nspass
; // GameServ's NickServ Password
30 int welcomedelay
; // Welcome Message Delay
31 int updateperiod
; // Seconds until another player database update
32 int forestfights
; // Forest fights per day
33 int maxafightdistance
; // Max levels above a player they can fight player->player
34 int maxbfightdistance
; // Max levels below a player they can fight player->player
35 int maxidletime
; // Max time (in seconds) a player can be idle for
36 int idlecheckperiod
; // Period for checking every player's idle time
37 int level1expire
; // Days for level 1 players to expire
38 int defaultexpire
; // Days for other levels to expire
39 long refreshperiod
; // Period for refreshing players
40 long configflags
; // Holds the bit representation of some boolean values
42 // Remote server stuff. This is used for the outgoing connection gameserv needs to make
44 char *remoteserver
; // Server to connect to
45 char *remoteport
; // Port to connect to on remoteserver
46 char *remotepass
; // Password for the server link
48 char *playerdata
; // File to store player data in
49 char *dragondata
; // File to store current dragon data in
50 char *masterdata
; // File to store the master data in
51 char *newsdata
; // File to store news data in
52 char *pidfile
; // Process ID file
55 char *gsnum
= "[]AAA"; // GameServ Numeric
58 void unload_config_file()
71 delete [] c_ForestTopic
;
73 delete [] remoteserver
;
90 if (ignoreserverslist
)
91 delete [] ignoreserverslist
;
102 int load_config_file(char *config
)
104 char *buf
, *directive
, *value
;
106 #define numdirectives 30
108 unload_config_file();
115 DIRECTIVE directives
[numdirectives
];
117 directives
[0].desc
= "s_GameServ - GameServ Nickname";
118 directives
[1].desc
= "GSHOST - GameServ Hostname";
119 directives
[2].desc
= "GSIDENT - GameServ Ident";
120 directives
[3].desc
= "SERVERNAME - Pseudo Server's Name";
121 directives
[4].desc
= "C_FOREST - Forest Channel";
122 directives
[5].desc
= "C_FORESTTOPIC - Topic for the Forest Channel";
123 directives
[6].desc
= "REMOTESERVER - Server for gameserv to connect to (ip or hostname)";
124 directives
[7].desc
= "REMOTEPORT - Port on the remote server to connect to";
125 directives
[8].desc
= "REMOTEPASS - Password on the remote server";
126 directives
[9].desc
= "PLAYERDATA - File to store the player saves in";
127 directives
[10].desc
= "SAVEDNOTICE - True/False as to wether or not to tell the forest "\
128 "channel that the player database has been saved";
129 directives
[11].desc
= "ADMINPASS - Password to identify as an admin with";
130 directives
[12].desc
= "WELCOMEDELAY - Delay (in seconds) to wait before welcoming new users to the network";
131 directives
[13].desc
= "FORESTFIGHTS - Number of forest fights players get every day";
132 directives
[14].desc
= "UPDATEPERIOD - Number of seconds between every player data save";
133 directives
[15].desc
= "PIDFILE - Filename to store the gameserv process ID in";
134 directives
[16].desc
= "MAXAFIGHTDISTANCE - The maximum number of levels above you "\
135 "that you can fight player->player";
136 directives
[17].desc
= "MAXBFIGHTDISTANCE - The maximum number of levels below you "\
137 "that you can fight player->player";
138 directives
[18].desc
= "MAXIDLETIME - The maximum amount of time (in seconds) "\
139 "that a player can be idle before something happens";
140 directives
[19].desc
= "IDLECHECKPERIOD - The period (in seconds) in which the entire "\
141 "players list will be checked for idlers. See also: "\
143 directives
[20].desc
= "LISTENONC_FOREST - True/False as to "\
144 "whether or not to listen for forest "\
145 "commands on the forest channel";
146 directives
[21].desc
= "NEWSDATA - File to store daily news in";
147 directives
[22].desc
= "REFRESHPERIOD - Period (in seconds) to "\
149 directives
[23].desc
= "LEVEL1EXPIRE - Amount of days until a "\
150 "level 1 player's account is deleted due to "\
152 directives
[24].desc
= "DEFAULTEXPIRE - Amount of days until a "\
153 "level 2 and above player's account is "\
154 "deleted due to inactivity";
155 directives
[25].desc
= "USENICKSERV - True/False as to wether or not "\
156 "GameServ should identify with NickServ";
157 directives
[26].desc
= "NSNAME - Your network's NickServ nickname";
158 directives
[27].desc
= "NSPASS - GameServ's NickServ Password";
159 directives
[28].desc
= "DRAGONDATA - File to store the current "\
161 directives
[29].desc
= "MASTERDATA - File to store the level master stats in";
165 for (int count
= 0; count
< numdirectives
; count
++)
167 directives
[count
].done
= false;
174 log("Error opening %s", config
);
175 cerr
<< "Error opening " << config
<< endl
;
179 buf
= new char[1024];
181 while (infile
.getline(buf
, 1024, '\n'))
184 log("Config file entry buf: %s", buf
);
187 if (buf
[0] == '#' || buf
[0] == ' ' || buf
[0] == '\0' || buf
[0] == '\n' || buf
[0] == '\r')
190 directive
= strtok(buf
, " ");
192 if (stricmp(directive
, "DIE") == 0)
194 value
= strtok(NULL
, "");
195 log("You should read the entire %s file!", config
);
196 cerr
<< "You should read the entire " << config
<< " file!"
201 if (stricmp(directive
, "S_GAMESERV") == 0)
203 value
= strtok(NULL
, " ");
204 s_GameServ
= new char[strlen(value
) + 1];
205 strcpy(s_GameServ
, value
);
206 directives
[0].done
= true;
208 else if (stricmp(directive
, "GSHOST") == 0)
210 value
= strtok(NULL
, " ");
211 gshost
= new char[strlen(value
) + 1];
212 strcpy(gshost
, value
);
213 directives
[1].done
= true;
215 else if (stricmp(directive
, "GSIDENT") == 0)
217 value
= strtok(NULL
, " ");
218 gsident
= new char[strlen(value
) + 1];
219 strcpy(gsident
, value
);
220 directives
[2].done
= true;
222 else if (stricmp(directive
, "SERVERNAME") == 0)
224 value
= strtok(NULL
, " ");
225 servername
= new char[strlen(value
) + 1];
226 strcpy(servername
, value
);
227 directives
[3].done
= true;
229 else if (stricmp(directive
, "C_FOREST") == 0)
231 value
= strtok(NULL
, " ");
232 c_Forest
= new char[strlen(value
) + 1];
233 strcpy(c_Forest
, value
);
234 directives
[4].done
= true;
236 else if (stricmp(directive
, "C_FORESTTOPIC") == 0)
238 value
= strtok(NULL
, "");
239 c_ForestTopic
= new char[strlen(value
) + 1];
240 strcpy(c_ForestTopic
, value
);
241 directives
[5].done
= true;
243 else if (stricmp(directive
, "REMOTESERVER") == 0)
245 value
= strtok(NULL
, " ");
246 remoteserver
= new char[strlen(value
) + 1];
247 strcpy(remoteserver
, value
);
248 directives
[6].done
= true;
250 else if (stricmp(directive
, "REMOTEPORT") == 0)
252 value
= strtok(NULL
, " ");
253 remoteport
= new char[strlen(value
) + 1];
254 strcpy(remoteport
, value
);
255 directives
[7].done
= true;
257 else if (stricmp(directive
, "REMOTEPASS") == 0)
259 value
= strtok(NULL
, "");
260 remotepass
= new char[strlen(value
) + 1];
261 strcpy(remotepass
, value
);
262 directives
[8].done
= true;
264 else if (stricmp(directive
, "PLAYERDATA") == 0)
266 value
= strtok(NULL
, "");
267 playerdata
= new char[strlen(value
) + 1];
268 strcpy(playerdata
, value
);
269 directives
[9].done
= true;
271 else if (stricmp(directive
, "SAVEDNOTICE") == 0)
273 value
= strtok(NULL
, "");
274 if (stricmp(value
, "TRUE") == 0)
276 directives
[10].done
= true;
278 else if (stricmp(directive
, "ADMINPASS") == 0)
280 value
= strtok(NULL
, "");
281 adminpass
= new char[strlen(value
) + 1];
282 strcpy(adminpass
, value
);
283 directives
[11].done
= true;
285 else if (stricmp(directive
, "WELCOMEDELAY") == 0)
287 value
= strtok(NULL
, " ");
288 welcomedelay
= stringtoint(value
);
289 directives
[12].done
= true;
291 else if (stricmp(directive
, "FORESTFIGHTS") == 0)
293 value
= strtok(NULL
, " ");
294 forestfights
= stringtoint(value
);
295 directives
[13].done
= true;
297 else if (stricmp(directive
, "UPDATEPERIOD") == 0)
299 value
= strtok(NULL
, " ");
300 updateperiod
= stringtoint(value
);
301 directives
[14].done
= true;
303 else if (stricmp(directive
, "PIDFILE") == 0)
305 value
= strtok(NULL
, " ");
306 pidfile
= new char[strlen(value
) + 1];
307 strcpy(pidfile
, value
);
308 directives
[15].done
= true;
310 else if (stricmp(directive
, "MAXAFIGHTDISTANCE") == 0)
312 value
= strtok(NULL
, " ");
313 maxafightdistance
= stringtoint(value
);
314 directives
[16].done
= true;;
316 else if (stricmp(directive
, "MAXBFIGHTDISTANCE") == 0)
318 value
= strtok(NULL
, " ");
319 maxbfightdistance
= stringtoint(value
);
320 directives
[17].done
= true;
322 else if (stricmp(directive
, "MAXIDLETIME") == 0)
324 value
= strtok(NULL
, " ");
325 maxidletime
= stringtoint(value
);
326 directives
[18].done
= true;
328 else if (stricmp(directive
, "IDLECHECKPERIOD") == 0)
330 value
= strtok(NULL
, " ");
331 idlecheckperiod
= stringtoint(value
);
332 directives
[19].done
= true;
334 else if (stricmp(directive
, "LISTENONC_FOREST") == 0)
336 value
= strtok(NULL
, " ");
337 if (stricmp(value
, "TRUE") == 0)
340 directives
[20].done
= true;
342 else if (stricmp(directive
, "NEWSDATA") == 0)
344 value
= strtok(NULL
, " ");
345 newsdata
= new char [strlen(value
) + 1];
346 strcpy(newsdata
, value
);
347 directives
[21].done
= true;
349 else if (stricmp(directive
, "REFRESHPERIOD") == 0)
351 value
= strtok(NULL
, " ");
352 refreshperiod
= stringtoint(value
);
353 directives
[22].done
= true;
355 else if (stricmp(directive
, "LEVEL1EXPIRE") == 0)
357 value
= strtok(NULL
, " ");
358 level1expire
= stringtoint(value
);
359 directives
[23].done
= true;
361 else if (stricmp(directive
, "DEFAULTEXPIRE") == 0)
363 value
= strtok(NULL
, " ");
364 defaultexpire
= stringtoint(value
);
365 directives
[24].done
= true;
367 else if (stricmp(directive
, "USENICKSERV") == 0)
369 value
= strtok(NULL
, " ");
370 if (stricmp(value
, "TRUE") == 0)
375 directives
[25].done
= true;
377 else if (stricmp(directive
, "NSNAME") == 0)
379 value
= strtok(NULL
, "");
380 nsname
= new char[strlen(value
) + 1];
381 strcpy(nsname
, value
);
382 directives
[26].done
= true;
384 else if (stricmp(directive
, "NSPASS") == 0)
386 value
= strtok(NULL
, "");
387 nspass
= new char[strlen(value
) + 1];
388 strcpy(nspass
, value
);
389 directives
[27].done
= true;
391 else if (stricmp(directive
, "DRAGONDATA") == 0)
393 value
= strtok(NULL
, "");
394 dragondata
= new char[strlen(value
) + 1];
395 strcpy(dragondata
, value
);
396 directives
[28].done
= true;
398 else if (stricmp(directive
, "MASTERDATA") == 0)
400 value
= strtok(NULL
, "");
401 masterdata
= new char[strlen(value
) + 1];
402 strcpy(masterdata
, value
);
403 directives
[29].done
= true;
405 else if (stricmp(directive
, "WELCOMEMSG") == 0)
407 // This directive is optional
408 value
= strtok(NULL
, "");
409 welcomemsg
= new char[strlen(value
) + 1];
410 strcpy(welcomemsg
, value
);
413 else if (stricmp(directive
, "USEPRIVMSG") == 0)
415 // This directive is optional
418 else if (stricmp(directive
, "BOPER") == 0)
420 // This directive is optional
423 else if (stricmp(directive
, "IGNORESERVERS") == 0)
425 // This directive is optional
426 value
= strtok(NULL
, "");
427 ignoreserverslist
= new char[strlen(value
) + 1];
428 strcpy(ignoreserverslist
, value
);
433 log("Unknown Directive. Buffer: %s", buf
);
434 cerr
<< "Unknown " << config
<< " directive. Buffer: "
444 for (int count2
= 0; count2
< numdirectives
; count2
++)
446 if (!directives
[count2
].done
)
448 cerr
<< "Missing config directive: " << directives
[count2
].desc
<< endl
;