]>
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 *remoteport
; // Port to connect to on remoteserver
46 char *remotepass
; // Password for the server link
48 char *tavernitemdata
; // File to store the items available in the tavern
49 char *itemdata
; // File to store the items in
50 char *playerdata
; // File to store player data in
51 char *dragondata
; // File to store current dragon data in
52 char *masterdata
; // File to store the master data in
53 char *newsdata
; // File to store news data in
54 char *pidfile
; // Process ID file
57 char *gsnum
= "[]AAA"; // GameServ Numeric
60 void unload_config_file()
73 delete [] c_ForestTopic
;
75 delete [] remoteserver
;
83 delete [] tavernitemdata
;
96 if (ignoreserverslist
)
97 delete [] ignoreserverslist
;
108 int load_config_file(char *config
)
110 char *buf
, *directive
, *value
;
112 #define numdirectives 33
114 unload_config_file();
121 DIRECTIVE directives
[numdirectives
];
123 directives
[0].desc
= "s_GameServ - GameServ Nickname";
124 directives
[1].desc
= "GSHOST - GameServ Hostname";
125 directives
[2].desc
= "GSIDENT - GameServ Ident";
126 directives
[3].desc
= "SERVERNAME - Pseudo Server's Name";
127 directives
[4].desc
= "C_FOREST - Forest Channel";
128 directives
[5].desc
= "C_FORESTTOPIC - Topic for the Forest Channel";
129 directives
[6].desc
= "REMOTESERVER - Server for gameserv to connect to (ip or hostname)";
130 directives
[7].desc
= "REMOTEPORT - Port on the remote server to connect to";
131 directives
[8].desc
= "REMOTEPASS - Password on the remote server";
132 directives
[9].desc
= "PLAYERDATA - File to store the player saves in";
133 directives
[10].desc
= "SAVEDNOTICE - True/False as to wether or not to tell the forest "\
134 "channel that the player database has been saved";
135 directives
[11].desc
= "ADMINPASS - Password to identify as an admin with";
136 directives
[12].desc
= "WELCOMEDELAY - Delay (in seconds) to wait before welcoming new users to the network";
137 directives
[13].desc
= "FORESTFIGHTS - Number of forest fights players get every day";
138 directives
[14].desc
= "UPDATEPERIOD - Number of seconds between every player data save";
139 directives
[15].desc
= "PIDFILE - Filename to store the gameserv process ID in";
140 directives
[16].desc
= "MAXAFIGHTDISTANCE - The maximum number of levels above you "\
141 "that you can fight player->player";
142 directives
[17].desc
= "MAXBFIGHTDISTANCE - The maximum number of levels below you "\
143 "that you can fight player->player";
144 directives
[18].desc
= "MAXIDLETIME - The maximum amount of time (in seconds) "\
145 "that a player can be idle before something happens";
146 directives
[19].desc
= "IDLECHECKPERIOD - The period (in seconds) in which the entire "\
147 "players list will be checked for idlers. See also: "\
149 directives
[20].desc
= "LISTENONC_FOREST - True/False as to "\
150 "whether or not to listen for forest "\
151 "commands on the forest channel";
152 directives
[21].desc
= "NEWSDATA - File to store daily news in";
153 directives
[22].desc
= "REFRESHPERIOD - Period (in seconds) to "\
155 directives
[23].desc
= "LEVEL1EXPIRE - Amount of days until a "\
156 "level 1 player's account is deleted due to "\
158 directives
[24].desc
= "DEFAULTEXPIRE - Amount of days until a "\
159 "level 2 and above player's account is "\
160 "deleted due to inactivity";
161 directives
[25].desc
= "USENICKSERV - True/False as to wether or not "\
162 "GameServ should identify with NickServ";
163 directives
[26].desc
= "NSNAME - Your network's NickServ nickname";
164 directives
[27].desc
= "NSPASS - GameServ's NickServ Password";
165 directives
[28].desc
= "DRAGONDATA - File to store the current "\
167 directives
[29].desc
= "MASTERDATA - File to store the level master stats in";
168 directives
[30].desc
= "ITEMDATA - File to store the items in";
169 directives
[31].desc
= "TAVERNITEMDATA - File in which to store the items that are available in the tavern";
170 directives
[32].desc
= "MAXITEMS - Maximum number of items a player can carry";
174 for (int count
= 0; count
< numdirectives
; count
++)
176 directives
[count
].done
= false;
183 log("Error opening %s", config
);
184 cerr
<< "Error opening " << config
<< endl
;
188 buf
= new char[1024];
190 while (infile
.getline(buf
, 1024, '\n'))
193 log("Config file entry buf: %s", buf
);
196 if (buf
[0] == '#' || buf
[0] == ' ' || buf
[0] == '\0' || buf
[0] == '\n' || buf
[0] == '\r')
199 directive
= strtok(buf
, " ");
201 if (stricmp(directive
, "DIE") == 0)
203 value
= strtok(NULL
, "");
204 log("You should read the entire %s file!", config
);
205 cerr
<< "You should read the entire " << config
<< " file!"
210 if (stricmp(directive
, "S_GAMESERV") == 0)
212 value
= strtok(NULL
, " ");
213 s_GameServ
= new char[strlen(value
) + 1];
214 strcpy(s_GameServ
, value
);
215 directives
[0].done
= true;
217 else if (stricmp(directive
, "GSHOST") == 0)
219 value
= strtok(NULL
, " ");
220 gshost
= new char[strlen(value
) + 1];
221 strcpy(gshost
, value
);
222 directives
[1].done
= true;
224 else if (stricmp(directive
, "GSIDENT") == 0)
226 value
= strtok(NULL
, " ");
227 gsident
= new char[strlen(value
) + 1];
228 strcpy(gsident
, value
);
229 directives
[2].done
= true;
231 else if (stricmp(directive
, "SERVERNAME") == 0)
233 value
= strtok(NULL
, " ");
234 servername
= new char[strlen(value
) + 1];
235 strcpy(servername
, value
);
236 directives
[3].done
= true;
238 else if (stricmp(directive
, "C_FOREST") == 0)
240 value
= strtok(NULL
, " ");
241 c_Forest
= new char[strlen(value
) + 1];
242 strcpy(c_Forest
, value
);
243 directives
[4].done
= true;
245 else if (stricmp(directive
, "C_FORESTTOPIC") == 0)
247 value
= strtok(NULL
, "");
248 c_ForestTopic
= new char[strlen(value
) + 1];
249 strcpy(c_ForestTopic
, value
);
250 directives
[5].done
= true;
252 else if (stricmp(directive
, "REMOTESERVER") == 0)
254 value
= strtok(NULL
, " ");
255 remoteserver
= new char[strlen(value
) + 1];
256 strcpy(remoteserver
, value
);
257 directives
[6].done
= true;
259 else if (stricmp(directive
, "REMOTEPORT") == 0)
261 value
= strtok(NULL
, " ");
262 remoteport
= new char[strlen(value
) + 1];
263 strcpy(remoteport
, value
);
264 directives
[7].done
= true;
266 else if (stricmp(directive
, "REMOTEPASS") == 0)
268 value
= strtok(NULL
, "");
269 remotepass
= new char[strlen(value
) + 1];
270 strcpy(remotepass
, value
);
271 directives
[8].done
= true;
273 else if (stricmp(directive
, "PLAYERDATA") == 0)
275 value
= strtok(NULL
, "");
276 playerdata
= new char[strlen(value
) + 1];
277 strcpy(playerdata
, value
);
278 directives
[9].done
= true;
280 else if (stricmp(directive
, "SAVEDNOTICE") == 0)
282 value
= strtok(NULL
, "");
283 if (stricmp(value
, "TRUE") == 0)
285 directives
[10].done
= true;
287 else if (stricmp(directive
, "ADMINPASS") == 0)
289 value
= strtok(NULL
, "");
290 adminpass
= new char[strlen(value
) + 1];
291 strcpy(adminpass
, value
);
292 directives
[11].done
= true;
294 else if (stricmp(directive
, "WELCOMEDELAY") == 0)
296 value
= strtok(NULL
, " ");
297 welcomedelay
= stringtoint(value
);
298 directives
[12].done
= true;
300 else if (stricmp(directive
, "FORESTFIGHTS") == 0)
302 value
= strtok(NULL
, " ");
303 forestfights
= stringtoint(value
);
304 directives
[13].done
= true;
306 else if (stricmp(directive
, "UPDATEPERIOD") == 0)
308 value
= strtok(NULL
, " ");
309 updateperiod
= stringtoint(value
);
310 directives
[14].done
= true;
312 else if (stricmp(directive
, "PIDFILE") == 0)
314 value
= strtok(NULL
, " ");
315 pidfile
= new char[strlen(value
) + 1];
316 strcpy(pidfile
, value
);
317 directives
[15].done
= true;
319 else if (stricmp(directive
, "MAXAFIGHTDISTANCE") == 0)
321 value
= strtok(NULL
, " ");
322 maxafightdistance
= stringtoint(value
);
323 directives
[16].done
= true;;
325 else if (stricmp(directive
, "MAXBFIGHTDISTANCE") == 0)
327 value
= strtok(NULL
, " ");
328 maxbfightdistance
= stringtoint(value
);
329 directives
[17].done
= true;
331 else if (stricmp(directive
, "MAXIDLETIME") == 0)
333 value
= strtok(NULL
, " ");
334 maxidletime
= stringtoint(value
);
335 directives
[18].done
= true;
337 else if (stricmp(directive
, "IDLECHECKPERIOD") == 0)
339 value
= strtok(NULL
, " ");
340 idlecheckperiod
= stringtoint(value
);
341 directives
[19].done
= true;
343 else if (stricmp(directive
, "LISTENONC_FOREST") == 0)
345 value
= strtok(NULL
, " ");
346 if (stricmp(value
, "TRUE") == 0)
349 directives
[20].done
= true;
351 else if (stricmp(directive
, "NEWSDATA") == 0)
353 value
= strtok(NULL
, " ");
354 newsdata
= new char [strlen(value
) + 1];
355 strcpy(newsdata
, value
);
356 directives
[21].done
= true;
358 else if (stricmp(directive
, "REFRESHPERIOD") == 0)
360 value
= strtok(NULL
, " ");
361 refreshperiod
= stringtoint(value
);
362 directives
[22].done
= true;
364 else if (stricmp(directive
, "LEVEL1EXPIRE") == 0)
366 value
= strtok(NULL
, " ");
367 level1expire
= stringtoint(value
);
368 directives
[23].done
= true;
370 else if (stricmp(directive
, "DEFAULTEXPIRE") == 0)
372 value
= strtok(NULL
, " ");
373 defaultexpire
= stringtoint(value
);
374 directives
[24].done
= true;
376 else if (stricmp(directive
, "USENICKSERV") == 0)
378 value
= strtok(NULL
, " ");
379 if (stricmp(value
, "TRUE") == 0)
384 directives
[25].done
= true;
386 else if (stricmp(directive
, "NSNAME") == 0)
388 value
= strtok(NULL
, "");
389 nsname
= new char[strlen(value
) + 1];
390 strcpy(nsname
, value
);
391 directives
[26].done
= true;
393 else if (stricmp(directive
, "NSPASS") == 0)
395 value
= strtok(NULL
, "");
396 nspass
= new char[strlen(value
) + 1];
397 strcpy(nspass
, value
);
398 directives
[27].done
= true;
400 else if (stricmp(directive
, "DRAGONDATA") == 0)
402 value
= strtok(NULL
, "");
403 dragondata
= new char[strlen(value
) + 1];
404 strcpy(dragondata
, value
);
405 directives
[28].done
= true;
407 else if (stricmp(directive
, "MASTERDATA") == 0)
409 value
= strtok(NULL
, "");
410 masterdata
= new char[strlen(value
) + 1];
411 strcpy(masterdata
, value
);
412 directives
[29].done
= true;
414 else if (stricmp(directive
, "ITEMDATA") == 0)
416 value
= strtok(NULL
, "");
417 itemdata
= new char[strlen(value
) + 1];
418 strcpy(itemdata
, value
);
419 directives
[30].done
= true;
421 else if (stricmp(directive
, "TAVERNITEMDATA") == 0)
423 value
= strtok(NULL
, "");
424 tavernitemdata
= new char[strlen(value
) + 1];
425 strcpy(tavernitemdata
, value
);
426 directives
[31].done
= true;
428 else if (stricmp(directive
, "MAXITEMS") == 0)
430 value
= strtok(NULL
, "");
431 maxitems
= stringtoint(value
);
432 directives
[32].done
= true;
434 else if (stricmp(directive
, "WELCOMEMSG") == 0)
436 // This directive is optional
437 value
= strtok(NULL
, "");
438 welcomemsg
= new char[strlen(value
) + 1];
439 strcpy(welcomemsg
, value
);
442 else if (stricmp(directive
, "USEPRIVMSG") == 0)
444 // This directive is optional
447 else if (stricmp(directive
, "BOPER") == 0)
449 // This directive is optional
452 else if (stricmp(directive
, "IGNORESERVERS") == 0)
454 // This directive is optional
455 value
= strtok(NULL
, "");
456 ignoreserverslist
= new char[strlen(value
) + 1];
457 strcpy(ignoreserverslist
, value
);
462 log("Unknown Directive. Buffer: %s", buf
);
463 cerr
<< "Unknown " << config
<< " directive. Buffer: "
473 for (int count2
= 0; count2
< numdirectives
; count2
++)
475 if (!directives
[count2
].done
)
477 cerr
<< "Missing config directive: " << directives
[count2
].desc
<< endl
;