]>
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 int welcomedelay
; // Welcome Message Delay
27 int updateperiod
; // Seconds until another player database update
28 int forestfights
; // Forest fights per day
29 int maxafightdistance
; // Max levels above a player they can fight player->player
30 int maxbfightdistance
; // Max levels below a player they can fight player->player
31 int maxidletime
; // Max time (in seconds) a player can be idle for
32 int idlecheckperiod
; // Period for checking every player's idle time
33 int level1expire
; // Days for level 1 players to expire
34 int defaultexpire
; // Days for other levels to expire
35 long refreshperiod
; // Period for refreshing players
36 long configflags
; // Holds the bit representation of some boolean values
38 // Remote server stuff. This is used for the outgoing connection gameserv needs to make
40 char *remoteserver
; // Server to connect to
41 char *remoteport
; // Port to connect to on remoteserver
42 char *remotepass
; // Password for the server link
44 char *playerdata
; // File to store player data in
45 char *monsterdata
; // File to load monster data from
46 char *newsdata
; // File to store news data in
47 char *pidfile
; // Process ID file
50 char *gsnum
= "[]AAA"; // GameServ Numeric
53 void unload_config_file()
66 delete [] c_ForestTopic
;
68 delete [] remoteserver
;
76 delete [] monsterdata
;
83 if (ignoreserverslist
)
84 delete [] ignoreserverslist
;
91 int load_config_file(char *config
)
93 char *buf
, *directive
, *value
;
95 #define numdirectives 25
104 DIRECTIVE directives
[numdirectives
];
106 directives
[0].desc
= "s_GameServ - GameServ Nickname";
107 directives
[1].desc
= "GSHOST - GameServ Hostname";
108 directives
[2].desc
= "GSIDENT - GameServ Ident";
109 directives
[3].desc
= "SERVERNAME - Pseudo Server's Name";
110 directives
[4].desc
= "C_FOREST - Forest Channel";
111 directives
[5].desc
= "C_FORESTTOPIC - Topic for the Forest Channel";
112 directives
[6].desc
= "REMOTESERVER - Server for gameserv to connect to (ip or hostname)";
113 directives
[7].desc
= "REMOTEPORT - Port on the remote server to connect to";
114 directives
[8].desc
= "REMOTEPASS - Password on the remote server";
115 directives
[9].desc
= "PLAYERDATA - File to store the player saves in";
116 directives
[10].desc
= "MONSTERDATA - File to load the monsters from";
117 directives
[11].desc
= "ADMINPASS - Password to identify as an admin with";
118 directives
[12].desc
= "WELCOMEDELAY - Delay (in seconds) to wait before welcoming new users to the network";
119 directives
[13].desc
= "FORESTFIGHTS - Number of forest fights players get every day";
120 directives
[14].desc
= "UPDATEPERIOD - Number of seconds between every player data save";
121 directives
[15].desc
= "PIDFILE - Filename to store the gameserv process ID in";
122 directives
[16].desc
= "MAXAFIGHTDISTANCE - The maximum number of levels above you "\
123 "that you can fight player->player";
124 directives
[17].desc
= "MAXBFIGHTDISTANCE - The maximum number of levels below you "\
125 "that you can fight player->player";
126 directives
[18].desc
= "MAXIDLETIME - The maximum amount of time (in seconds) "\
127 "that a player can be idle before something happens";
128 directives
[19].desc
= "IDLECHECKPERIOD - The period (in seconds) in which the entire "\
129 "players list will be checked for idlers. See also: "\
131 directives
[20].desc
= "LISTENONC_FOREST - True/False as to "\
132 "whether or not to listen for forest "\
133 "commands on the forest channel";
134 directives
[21].desc
= "NEWSDATA - File to store daily news in";
135 directives
[22].desc
= "REFRESHPERIOD - Period (in seconds) to "\
137 directives
[23].desc
= "LEVEL1EXPIRE - Amount of days until a "\
138 "level 1 player's account is deleted due to "\
140 directives
[24].desc
= "DEFAULTEXPIRE - Amount of days until a "\
141 "level 2 and above player's account is "\
142 "deleted due to inactivity";
146 for (int count
= 0; count
< numdirectives
; count
++)
148 directives
[count
].done
= false;
155 log("Error opening %s", config
);
156 cerr
<< "Error opening " << config
<< endl
;
160 buf
= new char[1024];
162 while (infile
.getline(buf
, 1024, '\n'))
165 log("Config file entry buf: %s", buf
);
168 if (buf
[0] == '#' || buf
[0] == ' ' || buf
[0] == '\0' || buf
[0] == '\n' || buf
[0] == '\r')
171 directive
= strtok(buf
, " ");
173 if (stricmp(directive
, "DIE") == 0)
175 value
= strtok(NULL
, "");
176 log("You should read the entire %s file!", config
);
177 cerr
<< "You should read the entire " << config
<< " file!"
182 if (stricmp(directive
, "S_GAMESERV") == 0)
184 value
= strtok(NULL
, " ");
185 s_GameServ
= new char[strlen(value
) + 1];
186 strcpy(s_GameServ
, value
);
187 directives
[0].done
= true;
189 else if (stricmp(directive
, "GSHOST") == 0)
191 value
= strtok(NULL
, " ");
192 gshost
= new char[strlen(value
) + 1];
193 strcpy(gshost
, value
);
194 directives
[1].done
= true;
196 else if (stricmp(directive
, "GSIDENT") == 0)
198 value
= strtok(NULL
, " ");
199 gsident
= new char[strlen(value
) + 1];
200 strcpy(gsident
, value
);
201 directives
[2].done
= true;
203 else if (stricmp(directive
, "SERVERNAME") == 0)
205 value
= strtok(NULL
, " ");
206 servername
= new char[strlen(value
) + 1];
207 strcpy(servername
, value
);
208 directives
[3].done
= true;
210 else if (stricmp(directive
, "C_FOREST") == 0)
212 value
= strtok(NULL
, " ");
213 c_Forest
= new char[strlen(value
) + 1];
214 strcpy(c_Forest
, value
);
215 directives
[4].done
= true;
217 else if (stricmp(directive
, "C_FORESTTOPIC") == 0)
219 value
= strtok(NULL
, "");
220 c_ForestTopic
= new char[strlen(value
) + 1];
221 strcpy(c_ForestTopic
, value
);
222 directives
[5].done
= true;
224 else if (stricmp(directive
, "REMOTESERVER") == 0)
226 value
= strtok(NULL
, " ");
227 remoteserver
= new char[strlen(value
) + 1];
228 strcpy(remoteserver
, value
);
229 directives
[6].done
= true;
231 else if (stricmp(directive
, "REMOTEPORT") == 0)
233 value
= strtok(NULL
, " ");
234 remoteport
= new char[strlen(value
) + 1];
235 strcpy(remoteport
, value
);
236 directives
[7].done
= true;
238 else if (stricmp(directive
, "REMOTEPASS") == 0)
240 value
= strtok(NULL
, "");
241 remotepass
= new char[strlen(value
) + 1];
242 strcpy(remotepass
, value
);
243 directives
[8].done
= true;
245 else if (stricmp(directive
, "PLAYERDATA") == 0)
247 value
= strtok(NULL
, "");
248 playerdata
= new char[strlen(value
) + 1];
249 strcpy(playerdata
, value
);
250 directives
[9].done
= true;
252 else if (stricmp(directive
, "MONSTERDATA") == 0)
254 value
= strtok(NULL
, "");
255 monsterdata
= new char[strlen(value
) + 1];
256 strcpy(monsterdata
, value
);
257 directives
[10].done
= true;
259 else if (stricmp(directive
, "ADMINPASS") == 0)
261 value
= strtok(NULL
, "");
262 adminpass
= new char[strlen(value
) + 1];
263 strcpy(adminpass
, value
);
264 directives
[11].done
= true;
266 else if (stricmp(directive
, "WELCOMEDELAY") == 0)
268 value
= strtok(NULL
, " ");
269 welcomedelay
= stringtoint(value
);
270 directives
[12].done
= true;
272 else if (stricmp(directive
, "FORESTFIGHTS") == 0)
274 value
= strtok(NULL
, " ");
275 forestfights
= stringtoint(value
);
276 directives
[13].done
= true;
278 else if (stricmp(directive
, "UPDATEPERIOD") == 0)
280 value
= strtok(NULL
, " ");
281 updateperiod
= stringtoint(value
);
282 directives
[14].done
= true;
284 else if (stricmp(directive
, "PIDFILE") == 0)
286 value
= strtok(NULL
, " ");
287 pidfile
= new char[strlen(value
) + 1];
288 strcpy(pidfile
, value
);
289 directives
[15].done
= true;
291 else if (stricmp(directive
, "MAXAFIGHTDISTANCE") == 0)
293 value
= strtok(NULL
, " ");
294 maxafightdistance
= stringtoint(value
);
295 directives
[16].done
= true;;
297 else if (stricmp(directive
, "MAXBFIGHTDISTANCE") == 0)
299 value
= strtok(NULL
, " ");
300 maxbfightdistance
= stringtoint(value
);
301 directives
[17].done
= true;
303 else if (stricmp(directive
, "MAXIDLETIME") == 0)
305 value
= strtok(NULL
, " ");
306 maxidletime
= stringtoint(value
);
307 directives
[18].done
= true;
309 else if (stricmp(directive
, "IDLECHECKPERIOD") == 0)
311 value
= strtok(NULL
, " ");
312 idlecheckperiod
= stringtoint(value
);
313 directives
[19].done
= true;
315 else if (stricmp(directive
, "LISTENONC_FOREST") == 0)
317 value
= strtok(NULL
, " ");
318 if (stricmp(value
, "TRUE") == 0)
321 directives
[20].done
= true;
323 else if (stricmp(directive
, "NEWSDATA") == 0)
325 value
= strtok(NULL
, " ");
326 newsdata
= new char [strlen(value
) + 1];
327 strcpy(newsdata
, value
);
328 directives
[21].done
= true;
330 else if (stricmp(directive
, "REFRESHPERIOD") == 0)
332 value
= strtok(NULL
, " ");
333 refreshperiod
= stringtoint(value
);
334 directives
[22].done
= true;
336 else if (stricmp(directive
, "LEVEL1EXPIRE") == 0)
338 value
= strtok(NULL
, " ");
339 level1expire
= stringtoint(value
);
340 directives
[23].done
= true;
342 else if (stricmp(directive
, "DEFAULTEXPIRE") == 0)
344 value
= strtok(NULL
, " ");
345 defaultexpire
= stringtoint(value
);
346 directives
[24].done
= true;
348 else if (stricmp(directive
, "WELCOMEMSG") == 0)
350 // This directive is optional
351 value
= strtok(NULL
, "");
352 welcomemsg
= new char[strlen(value
) + 1];
353 strcpy(welcomemsg
, value
);
356 else if (stricmp(directive
, "USEPRIVMSG") == 0)
358 // This directive is optional
361 else if (stricmp(directive
, "BOPER") == 0)
363 // This directive is optional
366 else if (stricmp(directive
, "IGNORESERVERS") == 0)
368 // This directive is optional
369 value
= strtok(NULL
, "");
370 ignoreserverslist
= new char[strlen(value
) + 1];
371 strcpy(ignoreserverslist
, value
);
376 log("Unknown Directive. Buffer: %s", buf
);
377 cerr
<< "Unknown " << config
<< " directive. Buffer: "
387 for (int count2
= 0; count2
< numdirectives
; count2
++)
389 if (!directives
[count2
].done
)
391 cerr
<< "Missing config directive: " << directives
[count2
].desc
<< endl
;