]>
jfr.im git - irc/gameservirc.git/blob - gameserv/config.cpp
11 int load_config_file(char *config
);
12 void unload_config_file();
14 /* Random Configuration Stuff Goes Here until I code it to load from a .conf file :)*/
16 char *s_GameServ
; // GameServ's nickname
17 char *gshost
; // GameServ's Hostname
18 char *gsident
; // GameServ's ident/username
19 char *servername
; // GameServ's Server
20 char *c_Forest
; // Forest channel
21 char *c_ForestTopic
; // Forest Channel Topic
22 char *adminpass
; // Administrator password
23 char *welcomemsg
; // Welcome Message
24 char *ignoreserverslist
; // Servernames to ignore
25 int welcomedelay
; // Welcome Message Delay
26 int updateperiod
; // Seconds until another player database update
27 int forestfights
; // Forest fights per day
28 int maxafightdistance
; // Max levels above a player they can fight player->player
29 int maxbfightdistance
; // Max levels below a player they can fight player->player
30 int maxidletime
; // Max time (in seconds) a player can be idle for
31 int idlecheckperiod
; // Period for checking every player's idle time
32 bool listenonc_forest
; // If true, listen for commands on the forest channel
34 // Remote server stuff. This is used for the outgoing connection gameserv needs to make
36 char *remoteserver
; // Server to connect to
37 char *remoteport
; // Port to connect to on remoteserver
38 char *remotepass
; // Password for the server link
40 char *playerdata
; // File to store player data in
41 char *monsterdata
; // File to load monster data from
42 char *pidfile
; // Process ID file
45 char *gsnum
= "[]AAA"; // GameServ Numeric
48 void unload_config_file()
61 delete [] c_ForestTopic
;
63 delete [] remoteserver
;
71 delete [] monsterdata
;
78 if (ignoreserverslist
)
79 delete [] ignoreserverslist
;
82 int load_config_file(char *config
)
84 char *buf
, *directive
, *value
;
86 #define numdirectives 22
95 DIRECTIVE directives
[numdirectives
];
97 directives
[0].desc
= "s_GameServ - GameServ Nickname";
98 directives
[1].desc
= "GSHOST - GameServ Hostname";
99 directives
[2].desc
= "GSIDENT - GameServ Ident";
100 directives
[3].desc
= "SERVERNAME - Pseudo Server's Name";
101 directives
[4].desc
= "C_FOREST - Forest Channel";
102 directives
[5].desc
= "C_FORESTTOPIC - Topic for the Forest Channel";
103 directives
[6].desc
= "REMOTESERVER - Server for gameserv to connect to (ip or hostname)";
104 directives
[7].desc
= "REMOTEPORT - Port on the remote server to connect to";
105 directives
[8].desc
= "REMOTEPASS - Password on the remote server";
106 directives
[9].desc
= "PLAYERDATA - File to store the player saves in";
107 directives
[10].desc
= "MONSTERDATA - File to load the monsters from";
108 directives
[11].desc
= "ADMINPASS - Password to identify as an admin with";
109 directives
[12].desc
= "WELCOMEDELAY - Delay (in seconds) to wait before welcoming new users to the network";
110 directives
[13].desc
= "FORESTFIGHTS - Number of forest fights players get every day";
111 directives
[14].desc
= "UPDATEPERIOD - Number of seconds between every player data save";
112 directives
[15].desc
= "WELCOMEMSG - Message to send to new users on the network";
113 directives
[16].desc
= "PIDFILE - Filename to store the gameserv process ID in";
114 directives
[17].desc
= "MAXAFIGHTDISTANCE - The maximum number of levels above you "\
115 "that you can fight player->player";
116 directives
[18].desc
= "MAXBFIGHTDISTANCE - The maximum number of levels below you "\
117 "that you can fight player->player";
118 directives
[19].desc
= "MAXIDLETIME - The maximum amount of time (in seconds) "\
119 "that a player can be idle before something happens";
120 directives
[20].desc
= "IDLECHECKPERIOD - The period (in seconds) in which the entire "\
121 "players list will be checked for idlers. See also: "\
123 directives
[21].desc
= "LISTENONC_FOREST - True/False as to "\
124 "whether or not to listen for forest "\
125 "commands on the forest channel";
127 for (int count
= 0; count
< numdirectives
; count
++)
129 directives
[count
].done
= false;
136 log("Error opening %s", config
);
137 cerr
<< "Error opening " << config
<< endl
;
141 buf
= new char[1024];
143 while (infile
.getline(buf
, 1024, '\n'))
146 log("Config file entry buf: %s", buf
);
149 if (buf
[0] == '#' || buf
[0] == ' ' || buf
[0] == '\0' || buf
[0] == '\n' || buf
[0] == '\r')
152 directive
= strtok(buf
, " ");
154 if (stricmp(directive
, "DIE") == 0)
156 value
= strtok(NULL
, "");
157 log("You should read the entire %s file!", config
);
158 cerr
<< "You should read the entire " << config
<< " file!"
163 if (stricmp(directive
, "S_GAMESERV") == 0)
165 value
= strtok(NULL
, " ");
166 s_GameServ
= new char[strlen(value
) + 1];
167 strcpy(s_GameServ
, value
);
168 directives
[0].done
= true;
170 else if (stricmp(directive
, "GSHOST") == 0)
172 value
= strtok(NULL
, " ");
173 gshost
= new char[strlen(value
) + 1];
174 strcpy(gshost
, value
);
175 directives
[1].done
= true;
177 else if (stricmp(directive
, "GSIDENT") == 0)
179 value
= strtok(NULL
, " ");
180 gsident
= new char[strlen(value
) + 1];
181 strcpy(gsident
, value
);
182 directives
[2].done
= true;
184 else if (stricmp(directive
, "SERVERNAME") == 0)
186 value
= strtok(NULL
, " ");
187 servername
= new char[strlen(value
) + 1];
188 strcpy(servername
, value
);
189 directives
[3].done
= true;
191 else if (stricmp(directive
, "C_FOREST") == 0)
193 value
= strtok(NULL
, " ");
194 c_Forest
= new char[strlen(value
) + 1];
195 strcpy(c_Forest
, value
);
196 directives
[4].done
= true;
198 else if (stricmp(directive
, "C_FORESTTOPIC") == 0)
200 value
= strtok(NULL
, "");
201 c_ForestTopic
= new char[strlen(value
) + 1];
202 strcpy(c_ForestTopic
, value
);
203 directives
[5].done
= true;
205 else if (stricmp(directive
, "REMOTESERVER") == 0)
207 value
= strtok(NULL
, " ");
208 remoteserver
= new char[strlen(value
) + 1];
209 strcpy(remoteserver
, value
);
210 directives
[6].done
= true;
212 else if (stricmp(directive
, "REMOTEPORT") == 0)
214 value
= strtok(NULL
, " ");
215 remoteport
= new char[strlen(value
) + 1];
216 strcpy(remoteport
, value
);
217 directives
[7].done
= true;
219 else if (stricmp(directive
, "REMOTEPASS") == 0)
221 value
= strtok(NULL
, "");
222 remotepass
= new char[strlen(value
) + 1];
223 strcpy(remotepass
, value
);
224 directives
[8].done
= true;
226 else if (stricmp(directive
, "PLAYERDATA") == 0)
228 value
= strtok(NULL
, "");
229 playerdata
= new char[strlen(value
) + 1];
230 strcpy(playerdata
, value
);
231 directives
[9].done
= true;
233 else if (stricmp(directive
, "MONSTERDATA") == 0)
235 value
= strtok(NULL
, "");
236 monsterdata
= new char[strlen(value
) + 1];
237 strcpy(monsterdata
, value
);
238 directives
[10].done
= true;
240 else if (stricmp(directive
, "ADMINPASS") == 0)
242 value
= strtok(NULL
, "");
243 adminpass
= new char[strlen(value
) + 1];
244 strcpy(adminpass
, value
);
245 directives
[11].done
= true;
247 else if (stricmp(directive
, "WELCOMEDELAY") == 0)
249 value
= strtok(NULL
, " ");
250 welcomedelay
= stringtoint(value
);
251 directives
[12].done
= true;
253 else if (stricmp(directive
, "FORESTFIGHTS") == 0)
255 value
= strtok(NULL
, " ");
256 forestfights
= stringtoint(value
);
257 directives
[13].done
= true;
259 else if (stricmp(directive
, "UPDATEPERIOD") == 0)
261 value
= strtok(NULL
, " ");
262 updateperiod
= stringtoint(value
);
263 directives
[14].done
= true;
265 else if (stricmp(directive
, "WELCOMEMSG") == 0)
267 value
= strtok(NULL
, "");
268 welcomemsg
= new char[strlen(value
) + 1];
269 strcpy(welcomemsg
, value
);
270 directives
[15].done
= true;
272 else if (stricmp(directive
, "PIDFILE") == 0)
274 value
= strtok(NULL
, " ");
275 pidfile
= new char[strlen(value
) + 1];
276 strcpy(pidfile
, value
);
277 directives
[16].done
= true;
279 else if (stricmp(directive
, "MAXAFIGHTDISTANCE") == 0)
281 value
= strtok(NULL
, " ");
282 maxafightdistance
= stringtoint(value
);
283 directives
[17].done
= true;;
285 else if (stricmp(directive
, "MAXBFIGHTDISTANCE") == 0)
287 value
= strtok(NULL
, " ");
288 maxbfightdistance
= stringtoint(value
);
289 directives
[18].done
= true;
291 else if (stricmp(directive
, "MAXIDLETIME") == 0)
293 value
= strtok(NULL
, " ");
294 maxidletime
= stringtoint(value
);
295 directives
[19].done
= true;
297 else if (stricmp(directive
, "IDLECHECKPERIOD") == 0)
299 value
= strtok(NULL
, " ");
300 idlecheckperiod
= stringtoint(value
);
301 directives
[20].done
= true;
303 else if (stricmp(directive
, "LISTENONC_FOREST") == 0)
305 value
= strtok(NULL
, " ");
306 if (stricmp(value
, "TRUE") == 0)
307 listenonc_forest
= true;
309 listenonc_forest
= false;
311 directives
[21].done
= true;
313 else if (stricmp(directive
, "IGNORESERVERS") == 0)
315 // This directive is optional
316 value
= strtok(NULL
, "");
317 ignoreserverslist
= new char[strlen(value
) + 1];
318 strcpy(ignoreserverslist
, value
);
323 log("Unknown Directive. Buffer: %s", buf
);
324 cerr
<< "Unknown " << config
<< " directive. Buffer: "
334 for (int count2
= 0; count2
< numdirectives
; count2
++)
336 if (!directives
[count2
].done
)
338 cerr
<< "Missing config directive: " << directives
[count2
].desc
<< endl
;