]>
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 int maxitems
; // Maximum amount of items a player can carry
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 *localhost
; // Hostname of the local address to bind to
46 int remoteport
; // Port to connect to on remoteserver
47 char *remotepass
; // Password for the server link
49 char *storeitemdata
; // File to store the items available in the store
50 char *tavernitemdata
; // File to store the items available in the tavern
51 char *itemdata
; // File to store the items in
52 char *playerdata
; // File to store player data in
53 char *dragondata
; // File to store current dragon data in
54 char *masterdata
; // File to store the master data in
55 char *newsdata
; // File to store news data in
56 char *pidfile
; // Process ID file
59 char *gsnum
= "[]AAA"; // GameServ Numeric
62 void unload_config_file()
75 delete [] c_ForestTopic
;
77 delete [] remoteserver
;
85 delete [] storeitemdata
;
87 delete [] tavernitemdata
;
100 if (ignoreserverslist
)
101 delete [] ignoreserverslist
;
112 int load_config_file(char *config
)
114 char *buf
, *directive
, *value
;
116 #define numdirectives 35
118 unload_config_file();
125 DIRECTIVE directives
[numdirectives
];
127 directives
[0].desc
= "s_GameServ - GameServ Nickname";
128 directives
[1].desc
= "GSHOST - GameServ Hostname";
129 directives
[2].desc
= "GSIDENT - GameServ Ident";
130 directives
[3].desc
= "SERVERNAME - Pseudo Server's Name";
131 directives
[4].desc
= "C_FOREST - Forest Channel";
132 directives
[5].desc
= "C_FORESTTOPIC - Topic for the Forest Channel";
133 directives
[6].desc
= "REMOTESERVER - Server for gameserv to connect to (ip or hostname)";
134 directives
[7].desc
= "REMOTEPORT - Port on the remote server to connect to";
135 directives
[8].desc
= "REMOTEPASS - Password on the remote server";
136 directives
[9].desc
= "PLAYERDATA - File to store the player saves in";
137 directives
[10].desc
= "SAVEDNOTICE - True/False as to wether or not to tell the forest "\
138 "channel that the player database has been saved";
139 directives
[11].desc
= "ADMINPASS - Password to identify as an admin with";
140 directives
[12].desc
= "WELCOMEDELAY - Delay (in seconds) to wait before welcoming new users to the network";
141 directives
[13].desc
= "FORESTFIGHTS - Number of forest fights players get every day";
142 directives
[14].desc
= "UPDATEPERIOD - Number of seconds between every player data save";
143 directives
[15].desc
= "PIDFILE - Filename to store the gameserv process ID in";
144 directives
[16].desc
= "MAXAFIGHTDISTANCE - The maximum number of levels above you "\
145 "that you can fight player->player";
146 directives
[17].desc
= "MAXBFIGHTDISTANCE - The maximum number of levels below you "\
147 "that you can fight player->player";
148 directives
[18].desc
= "MAXIDLETIME - The maximum amount of time (in seconds) "\
149 "that a player can be idle before something happens";
150 directives
[19].desc
= "IDLECHECKPERIOD - The period (in seconds) in which the entire "\
151 "players list will be checked for idlers. See also: "\
153 directives
[20].desc
= "LISTENONC_FOREST - True/False as to "\
154 "whether or not to listen for forest "\
155 "commands on the forest channel";
156 directives
[21].desc
= "NEWSDATA - File to store daily news in";
157 directives
[22].desc
= "REFRESHPERIOD - Period (in seconds) to "\
159 directives
[23].desc
= "LEVEL1EXPIRE - Amount of days until a "\
160 "level 1 player's account is deleted due to "\
162 directives
[24].desc
= "DEFAULTEXPIRE - Amount of days until a "\
163 "level 2 and above player's account is "\
164 "deleted due to inactivity";
165 directives
[25].desc
= "USENICKSERV - True/False as to wether or not "\
166 "GameServ should identify with NickServ";
167 directives
[26].desc
= "NSNAME - Your network's NickServ nickname";
168 directives
[27].desc
= "NSPASS - GameServ's NickServ Password";
169 directives
[28].desc
= "DRAGONDATA - File to store the current "\
171 directives
[29].desc
= "MASTERDATA - File to store the level master stats in";
172 directives
[30].desc
= "ITEMDATA - File to store the items in";
173 directives
[31].desc
= "TAVERNITEMDATA - File in which to store the items that are available in the tavern";
174 directives
[32].desc
= "MAXITEMS - Maximum number of items a player can carry";
175 directives
[33].desc
= "STOREITEMDATA - File in which to store the items that are available in the store";
176 directives
[34].desc
= "LOCALHOST - Local hostname or IP to bind to when connecting to the remote server";
180 for (int count
= 0; count
< numdirectives
; count
++)
182 directives
[count
].done
= false;
189 log("Error opening %s", config
);
190 cerr
<< "Error opening " << config
<< endl
;
194 buf
= new char[1024];
196 while (infile
.getline(buf
, 1024, '\n'))
199 log("Config file entry buf: %s", buf
);
202 if (buf
[0] == '#' || buf
[0] == ' ' || buf
[0] == '\0' || buf
[0] == '\n' || buf
[0] == '\r')
205 directive
= strtok(buf
, " ");
207 if (stricmp(directive
, "DIE") == 0)
209 value
= strtok(NULL
, "");
210 log("You should read the entire %s file!", config
);
211 cerr
<< "You should read the entire " << config
<< " file!"
216 if (stricmp(directive
, "S_GAMESERV") == 0)
218 value
= strtok(NULL
, " ");
219 s_GameServ
= new char[strlen(value
) + 1];
220 strcpy(s_GameServ
, value
);
221 directives
[0].done
= true;
223 else if (stricmp(directive
, "GSHOST") == 0)
225 value
= strtok(NULL
, " ");
226 gshost
= new char[strlen(value
) + 1];
227 strcpy(gshost
, value
);
228 directives
[1].done
= true;
230 else if (stricmp(directive
, "GSIDENT") == 0)
232 value
= strtok(NULL
, " ");
233 gsident
= new char[strlen(value
) + 1];
234 strcpy(gsident
, value
);
235 directives
[2].done
= true;
237 else if (stricmp(directive
, "SERVERNAME") == 0)
239 value
= strtok(NULL
, " ");
240 servername
= new char[strlen(value
) + 1];
241 strcpy(servername
, value
);
242 directives
[3].done
= true;
244 else if (stricmp(directive
, "C_FOREST") == 0)
246 value
= strtok(NULL
, " ");
247 c_Forest
= new char[strlen(value
) + 1];
248 strcpy(c_Forest
, value
);
249 directives
[4].done
= true;
251 else if (stricmp(directive
, "C_FORESTTOPIC") == 0)
253 value
= strtok(NULL
, "");
254 c_ForestTopic
= new char[strlen(value
) + 1];
255 strcpy(c_ForestTopic
, value
);
256 directives
[5].done
= true;
258 else if (stricmp(directive
, "REMOTESERVER") == 0)
260 value
= strtok(NULL
, " ");
261 remoteserver
= new char[strlen(value
) + 1];
262 strcpy(remoteserver
, value
);
263 directives
[6].done
= true;
265 else if (stricmp(directive
, "REMOTEPORT") == 0)
267 value
= strtok(NULL
, " ");
268 remoteport
= stringtoint(value
);
269 directives
[7].done
= true;
271 else if (stricmp(directive
, "REMOTEPASS") == 0)
273 value
= strtok(NULL
, "");
274 remotepass
= new char[strlen(value
) + 1];
275 strcpy(remotepass
, value
);
276 directives
[8].done
= true;
278 else if (stricmp(directive
, "PLAYERDATA") == 0)
280 value
= strtok(NULL
, "");
281 playerdata
= new char[strlen(value
) + 1];
282 strcpy(playerdata
, value
);
283 directives
[9].done
= true;
285 else if (stricmp(directive
, "SAVEDNOTICE") == 0)
287 value
= strtok(NULL
, "");
288 if (stricmp(value
, "TRUE") == 0)
290 directives
[10].done
= true;
292 else if (stricmp(directive
, "ADMINPASS") == 0)
294 value
= strtok(NULL
, "");
295 adminpass
= new char[strlen(value
) + 1];
296 strcpy(adminpass
, value
);
297 directives
[11].done
= true;
299 else if (stricmp(directive
, "WELCOMEDELAY") == 0)
301 value
= strtok(NULL
, " ");
302 welcomedelay
= stringtoint(value
);
303 directives
[12].done
= true;
305 else if (stricmp(directive
, "FORESTFIGHTS") == 0)
307 value
= strtok(NULL
, " ");
308 forestfights
= stringtoint(value
);
309 directives
[13].done
= true;
311 else if (stricmp(directive
, "UPDATEPERIOD") == 0)
313 value
= strtok(NULL
, " ");
314 updateperiod
= stringtoint(value
);
315 directives
[14].done
= true;
317 else if (stricmp(directive
, "PIDFILE") == 0)
319 value
= strtok(NULL
, " ");
320 pidfile
= new char[strlen(value
) + 1];
321 strcpy(pidfile
, value
);
322 directives
[15].done
= true;
324 else if (stricmp(directive
, "MAXAFIGHTDISTANCE") == 0)
326 value
= strtok(NULL
, " ");
327 maxafightdistance
= stringtoint(value
);
328 directives
[16].done
= true;;
330 else if (stricmp(directive
, "MAXBFIGHTDISTANCE") == 0)
332 value
= strtok(NULL
, " ");
333 maxbfightdistance
= stringtoint(value
);
334 directives
[17].done
= true;
336 else if (stricmp(directive
, "MAXIDLETIME") == 0)
338 value
= strtok(NULL
, " ");
339 maxidletime
= stringtoint(value
);
340 directives
[18].done
= true;
342 else if (stricmp(directive
, "IDLECHECKPERIOD") == 0)
344 value
= strtok(NULL
, " ");
345 idlecheckperiod
= stringtoint(value
);
346 directives
[19].done
= true;
348 else if (stricmp(directive
, "LISTENONC_FOREST") == 0)
350 value
= strtok(NULL
, " ");
351 if (stricmp(value
, "TRUE") == 0)
354 directives
[20].done
= true;
356 else if (stricmp(directive
, "NEWSDATA") == 0)
358 value
= strtok(NULL
, " ");
359 newsdata
= new char [strlen(value
) + 1];
360 strcpy(newsdata
, value
);
361 directives
[21].done
= true;
363 else if (stricmp(directive
, "REFRESHPERIOD") == 0)
365 value
= strtok(NULL
, " ");
366 refreshperiod
= stringtoint(value
);
367 directives
[22].done
= true;
369 else if (stricmp(directive
, "LEVEL1EXPIRE") == 0)
371 value
= strtok(NULL
, " ");
372 level1expire
= stringtoint(value
);
373 directives
[23].done
= true;
375 else if (stricmp(directive
, "DEFAULTEXPIRE") == 0)
377 value
= strtok(NULL
, " ");
378 defaultexpire
= stringtoint(value
);
379 directives
[24].done
= true;
381 else if (stricmp(directive
, "USENICKSERV") == 0)
383 value
= strtok(NULL
, " ");
384 if (stricmp(value
, "TRUE") == 0)
389 directives
[25].done
= true;
391 else if (stricmp(directive
, "NSNAME") == 0)
393 value
= strtok(NULL
, "");
394 nsname
= new char[strlen(value
) + 1];
395 strcpy(nsname
, value
);
396 directives
[26].done
= true;
398 else if (stricmp(directive
, "NSPASS") == 0)
400 value
= strtok(NULL
, "");
401 nspass
= new char[strlen(value
) + 1];
402 strcpy(nspass
, value
);
403 directives
[27].done
= true;
405 else if (stricmp(directive
, "DRAGONDATA") == 0)
407 value
= strtok(NULL
, "");
408 dragondata
= new char[strlen(value
) + 1];
409 strcpy(dragondata
, value
);
410 directives
[28].done
= true;
412 else if (stricmp(directive
, "MASTERDATA") == 0)
414 value
= strtok(NULL
, "");
415 masterdata
= new char[strlen(value
) + 1];
416 strcpy(masterdata
, value
);
417 directives
[29].done
= true;
419 else if (stricmp(directive
, "ITEMDATA") == 0)
421 value
= strtok(NULL
, "");
422 itemdata
= new char[strlen(value
) + 1];
423 strcpy(itemdata
, value
);
424 directives
[30].done
= true;
426 else if (stricmp(directive
, "TAVERNITEMDATA") == 0)
428 value
= strtok(NULL
, "");
429 tavernitemdata
= new char[strlen(value
) + 1];
430 strcpy(tavernitemdata
, value
);
431 directives
[31].done
= true;
433 else if (stricmp(directive
, "MAXITEMS") == 0)
435 value
= strtok(NULL
, "");
436 maxitems
= stringtoint(value
);
437 directives
[32].done
= true;
439 else if (stricmp(directive
, "STOREITEMDATA") == 0)
441 value
= strtok(NULL
, "");
442 storeitemdata
= new char[strlen(value
) + 1];
443 strcpy(storeitemdata
, value
);
444 directives
[33].done
= true;
446 else if (stricmp(directive
, "LOCALHOST") == 0)
448 value
= strtok(NULL
, "");
449 localhost
= new char[strlen(value
) + 1];
450 strcpy(localhost
, value
);
451 directives
[34].done
= true;
453 else if (stricmp(directive
, "WELCOMEMSG") == 0)
455 // This directive is optional
456 value
= strtok(NULL
, "");
457 welcomemsg
= new char[strlen(value
) + 1];
458 strcpy(welcomemsg
, value
);
461 else if (stricmp(directive
, "USEPRIVMSG") == 0)
463 // This directive is optional
466 else if (stricmp(directive
, "BOPER") == 0)
468 // This directive is optional
471 else if (stricmp(directive
, "IGNORESERVERS") == 0)
473 // This directive is optional
474 value
= strtok(NULL
, "");
475 ignoreserverslist
= new char[strlen(value
) + 1];
476 strcpy(ignoreserverslist
, value
);
481 log("Unknown Directive. Buffer: %s", buf
);
482 cerr
<< "Unknown " << config
<< " directive. Buffer: "
492 for (int count2
= 0; count2
< numdirectives
; count2
++)
494 if (!directives
[count2
].done
)
496 cerr
<< "Missing config directive: " << directives
[count2
].desc
<< endl
;