]>
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 long configflags
; // Holds the bit representation of some boolean values
35 // Remote server stuff. This is used for the outgoing connection gameserv needs to make
37 char *remoteserver
; // Server to connect to
38 char *remoteport
; // Port to connect to on remoteserver
39 char *remotepass
; // Password for the server link
41 char *playerdata
; // File to store player data in
42 char *monsterdata
; // File to load monster data from
43 char *pidfile
; // Process ID file
46 char *gsnum
= "[]AAA"; // GameServ Numeric
49 void unload_config_file()
62 delete [] c_ForestTopic
;
64 delete [] remoteserver
;
72 delete [] monsterdata
;
79 if (ignoreserverslist
)
80 delete [] ignoreserverslist
;
85 int load_config_file(char *config
)
87 char *buf
, *directive
, *value
;
89 #define numdirectives 22
98 DIRECTIVE directives
[numdirectives
];
100 directives
[0].desc
= "s_GameServ - GameServ Nickname";
101 directives
[1].desc
= "GSHOST - GameServ Hostname";
102 directives
[2].desc
= "GSIDENT - GameServ Ident";
103 directives
[3].desc
= "SERVERNAME - Pseudo Server's Name";
104 directives
[4].desc
= "C_FOREST - Forest Channel";
105 directives
[5].desc
= "C_FORESTTOPIC - Topic for the Forest Channel";
106 directives
[6].desc
= "REMOTESERVER - Server for gameserv to connect to (ip or hostname)";
107 directives
[7].desc
= "REMOTEPORT - Port on the remote server to connect to";
108 directives
[8].desc
= "REMOTEPASS - Password on the remote server";
109 directives
[9].desc
= "PLAYERDATA - File to store the player saves in";
110 directives
[10].desc
= "MONSTERDATA - File to load the monsters from";
111 directives
[11].desc
= "ADMINPASS - Password to identify as an admin with";
112 directives
[12].desc
= "WELCOMEDELAY - Delay (in seconds) to wait before welcoming new users to the network";
113 directives
[13].desc
= "FORESTFIGHTS - Number of forest fights players get every day";
114 directives
[14].desc
= "UPDATEPERIOD - Number of seconds between every player data save";
115 directives
[15].desc
= "WELCOMEMSG - Message to send to new users on the network";
116 directives
[16].desc
= "PIDFILE - Filename to store the gameserv process ID in";
117 directives
[17].desc
= "MAXAFIGHTDISTANCE - The maximum number of levels above you "\
118 "that you can fight player->player";
119 directives
[18].desc
= "MAXBFIGHTDISTANCE - The maximum number of levels below you "\
120 "that you can fight player->player";
121 directives
[19].desc
= "MAXIDLETIME - The maximum amount of time (in seconds) "\
122 "that a player can be idle before something happens";
123 directives
[20].desc
= "IDLECHECKPERIOD - The period (in seconds) in which the entire "\
124 "players list will be checked for idlers. See also: "\
126 directives
[21].desc
= "LISTENONC_FOREST - True/False as to "\
127 "whether or not to listen for forest "\
128 "commands on the forest channel";
132 for (int count
= 0; count
< numdirectives
; count
++)
134 directives
[count
].done
= false;
141 log("Error opening %s", config
);
142 cerr
<< "Error opening " << config
<< endl
;
146 buf
= new char[1024];
148 while (infile
.getline(buf
, 1024, '\n'))
151 log("Config file entry buf: %s", buf
);
154 if (buf
[0] == '#' || buf
[0] == ' ' || buf
[0] == '\0' || buf
[0] == '\n' || buf
[0] == '\r')
157 directive
= strtok(buf
, " ");
159 if (stricmp(directive
, "DIE") == 0)
161 value
= strtok(NULL
, "");
162 log("You should read the entire %s file!", config
);
163 cerr
<< "You should read the entire " << config
<< " file!"
168 if (stricmp(directive
, "S_GAMESERV") == 0)
170 value
= strtok(NULL
, " ");
171 s_GameServ
= new char[strlen(value
) + 1];
172 strcpy(s_GameServ
, value
);
173 directives
[0].done
= true;
175 else if (stricmp(directive
, "GSHOST") == 0)
177 value
= strtok(NULL
, " ");
178 gshost
= new char[strlen(value
) + 1];
179 strcpy(gshost
, value
);
180 directives
[1].done
= true;
182 else if (stricmp(directive
, "GSIDENT") == 0)
184 value
= strtok(NULL
, " ");
185 gsident
= new char[strlen(value
) + 1];
186 strcpy(gsident
, value
);
187 directives
[2].done
= true;
189 else if (stricmp(directive
, "SERVERNAME") == 0)
191 value
= strtok(NULL
, " ");
192 servername
= new char[strlen(value
) + 1];
193 strcpy(servername
, value
);
194 directives
[3].done
= true;
196 else if (stricmp(directive
, "C_FOREST") == 0)
198 value
= strtok(NULL
, " ");
199 c_Forest
= new char[strlen(value
) + 1];
200 strcpy(c_Forest
, value
);
201 directives
[4].done
= true;
203 else if (stricmp(directive
, "C_FORESTTOPIC") == 0)
205 value
= strtok(NULL
, "");
206 c_ForestTopic
= new char[strlen(value
) + 1];
207 strcpy(c_ForestTopic
, value
);
208 directives
[5].done
= true;
210 else if (stricmp(directive
, "REMOTESERVER") == 0)
212 value
= strtok(NULL
, " ");
213 remoteserver
= new char[strlen(value
) + 1];
214 strcpy(remoteserver
, value
);
215 directives
[6].done
= true;
217 else if (stricmp(directive
, "REMOTEPORT") == 0)
219 value
= strtok(NULL
, " ");
220 remoteport
= new char[strlen(value
) + 1];
221 strcpy(remoteport
, value
);
222 directives
[7].done
= true;
224 else if (stricmp(directive
, "REMOTEPASS") == 0)
226 value
= strtok(NULL
, "");
227 remotepass
= new char[strlen(value
) + 1];
228 strcpy(remotepass
, value
);
229 directives
[8].done
= true;
231 else if (stricmp(directive
, "PLAYERDATA") == 0)
233 value
= strtok(NULL
, "");
234 playerdata
= new char[strlen(value
) + 1];
235 strcpy(playerdata
, value
);
236 directives
[9].done
= true;
238 else if (stricmp(directive
, "MONSTERDATA") == 0)
240 value
= strtok(NULL
, "");
241 monsterdata
= new char[strlen(value
) + 1];
242 strcpy(monsterdata
, value
);
243 directives
[10].done
= true;
245 else if (stricmp(directive
, "ADMINPASS") == 0)
247 value
= strtok(NULL
, "");
248 adminpass
= new char[strlen(value
) + 1];
249 strcpy(adminpass
, value
);
250 directives
[11].done
= true;
252 else if (stricmp(directive
, "WELCOMEDELAY") == 0)
254 value
= strtok(NULL
, " ");
255 welcomedelay
= stringtoint(value
);
256 directives
[12].done
= true;
258 else if (stricmp(directive
, "FORESTFIGHTS") == 0)
260 value
= strtok(NULL
, " ");
261 forestfights
= stringtoint(value
);
262 directives
[13].done
= true;
264 else if (stricmp(directive
, "UPDATEPERIOD") == 0)
266 value
= strtok(NULL
, " ");
267 updateperiod
= stringtoint(value
);
268 directives
[14].done
= true;
270 else if (stricmp(directive
, "WELCOMEMSG") == 0)
272 value
= strtok(NULL
, "");
273 welcomemsg
= new char[strlen(value
) + 1];
274 strcpy(welcomemsg
, value
);
275 directives
[15].done
= true;
277 else if (stricmp(directive
, "PIDFILE") == 0)
279 value
= strtok(NULL
, " ");
280 pidfile
= new char[strlen(value
) + 1];
281 strcpy(pidfile
, value
);
282 directives
[16].done
= true;
284 else if (stricmp(directive
, "MAXAFIGHTDISTANCE") == 0)
286 value
= strtok(NULL
, " ");
287 maxafightdistance
= stringtoint(value
);
288 directives
[17].done
= true;;
290 else if (stricmp(directive
, "MAXBFIGHTDISTANCE") == 0)
292 value
= strtok(NULL
, " ");
293 maxbfightdistance
= stringtoint(value
);
294 directives
[18].done
= true;
296 else if (stricmp(directive
, "MAXIDLETIME") == 0)
298 value
= strtok(NULL
, " ");
299 maxidletime
= stringtoint(value
);
300 directives
[19].done
= true;
302 else if (stricmp(directive
, "IDLECHECKPERIOD") == 0)
304 value
= strtok(NULL
, " ");
305 idlecheckperiod
= stringtoint(value
);
306 directives
[20].done
= true;
308 else if (stricmp(directive
, "LISTENONC_FOREST") == 0)
310 value
= strtok(NULL
, " ");
311 if (stricmp(value
, "TRUE") == 0)
314 directives
[21].done
= true;
316 else if (stricmp(directive
, "USEPRIVMSG") == 0)
318 // This directive is optional
321 else if (stricmp(directive
, "BOPER") == 0)
323 // This directive is optional
326 else if (stricmp(directive
, "IGNORESERVERS") == 0)
328 // This directive is optional
329 value
= strtok(NULL
, "");
330 ignoreserverslist
= new char[strlen(value
) + 1];
331 strcpy(ignoreserverslist
, value
);
336 log("Unknown Directive. Buffer: %s", buf
);
337 cerr
<< "Unknown " << config
<< " directive. Buffer: "
347 for (int count2
= 0; count2
< numdirectives
; count2
++)
349 if (!directives
[count2
].done
)
351 cerr
<< "Missing config directive: " << directives
[count2
].desc
<< endl
;