]>
Commit | Line | Data |
---|---|---|
fb37ecc7 | 1 | #include <fstream> |
85ce9d3e | 2 | #include <string.h> |
20d5d721 | 3 | #include <stdlib.h> |
85ce9d3e | 4 | #include <stdio.h> |
5 | #include "extern.h" | |
9bafc40d | 6 | #include "flags.h" |
85ce9d3e | 7 | |
fb37ecc7 | 8 | using std::ifstream; |
33ac4371 | 9 | using std::cerr; |
10 | using std::endl; | |
fb37ecc7 | 11 | |
624c0352 | 12 | int load_config_file(char *config); |
85ce9d3e | 13 | void unload_config_file(); |
85ce9d3e | 14 | |
15 | /* Random Configuration Stuff Goes Here until I code it to load from a .conf file :)*/ | |
16 | ||
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 | |
45a84400 | 23 | char *adminpass; // Administrator password |
bf2cabcd | 24 | char *welcomemsg; // Welcome Message |
448a1531 | 25 | char *ignoreserverslist; // Servernames to ignore |
922daad7 | 26 | int welcomedelay; // Welcome Message Delay |
27 | int updateperiod; // Seconds until another player database update | |
20d5d721 | 28 | int forestfights; // Forest fights per day |
8450c018 | 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 | |
40251952 | 31 | int maxidletime; // Max time (in seconds) a player can be idle for |
32 | int idlecheckperiod; // Period for checking every player's idle time | |
9bafc40d | 33 | long configflags; // Holds the bit representation of some boolean values |
85ce9d3e | 34 | |
35 | // Remote server stuff. This is used for the outgoing connection gameserv needs to make | |
36 | // to a real ircd. | |
37 | char *remoteserver; // Server to connect to | |
38 | char *remoteport; // Port to connect to on remoteserver | |
39 | char *remotepass; // Password for the server link | |
40 | ||
41 | char *playerdata; // File to store player data in | |
4dde2ed9 | 42 | char *monsterdata; // File to load monster data from |
c260a8d7 | 43 | char *newsdata; // File to store news data in |
69ae096c | 44 | char *pidfile; // Process ID file |
85ce9d3e | 45 | |
e1c41a84 | 46 | #if defined(P10) |
47 | char *gsnum = "[]AAA"; // GameServ Numeric | |
48 | #endif | |
49 | ||
85ce9d3e | 50 | void unload_config_file() |
51 | { | |
52 | if (s_GameServ) | |
1cf88153 | 53 | delete [] s_GameServ; |
85ce9d3e | 54 | if (gshost) |
1cf88153 | 55 | delete [] gshost; |
85ce9d3e | 56 | if (gsident) |
1cf88153 | 57 | delete [] gsident; |
85ce9d3e | 58 | if (servername) |
1cf88153 | 59 | delete [] servername; |
85ce9d3e | 60 | if (c_Forest) |
1cf88153 | 61 | delete [] c_Forest; |
85ce9d3e | 62 | if (c_ForestTopic) |
1cf88153 | 63 | delete [] c_ForestTopic; |
85ce9d3e | 64 | if (remoteserver) |
1cf88153 | 65 | delete [] remoteserver; |
85ce9d3e | 66 | if (remoteport) |
1cf88153 | 67 | delete [] remoteport; |
85ce9d3e | 68 | if (remotepass) |
1cf88153 | 69 | delete [] remotepass; |
85ce9d3e | 70 | if (playerdata) |
1cf88153 | 71 | delete [] playerdata; |
4dde2ed9 | 72 | if (monsterdata) |
73 | delete [] monsterdata; | |
45a84400 | 74 | if (adminpass) |
75 | delete [] adminpass; | |
bf2cabcd | 76 | if (welcomemsg) |
77 | delete [] welcomemsg; | |
69ae096c | 78 | if (pidfile) |
79 | delete [] pidfile; | |
448a1531 | 80 | if (ignoreserverslist) |
81 | delete [] ignoreserverslist; | |
c260a8d7 | 82 | if (newsdata) |
83 | delete [] newsdata; | |
9bafc40d | 84 | |
85 | configflags = 0; | |
85ce9d3e | 86 | } |
bf2cabcd | 87 | |
624c0352 | 88 | int load_config_file(char *config) |
85ce9d3e | 89 | { |
90 | char *buf, *directive, *value; | |
69ae096c | 91 | |
c260a8d7 | 92 | #define numdirectives 22 |
85ce9d3e | 93 | |
94 | unload_config_file(); | |
95 | ||
1e1b5312 | 96 | struct DIRECTIVE { |
97 | bool done; | |
98 | char *desc; | |
99 | }; | |
100 | ||
101 | DIRECTIVE directives[numdirectives]; | |
102 | ||
103 | directives[0].desc = "s_GameServ - GameServ Nickname"; | |
104 | directives[1].desc = "GSHOST - GameServ Hostname"; | |
105 | directives[2].desc = "GSIDENT - GameServ Ident"; | |
106 | directives[3].desc = "SERVERNAME - Pseudo Server's Name"; | |
107 | directives[4].desc = "C_FOREST - Forest Channel"; | |
108 | directives[5].desc = "C_FORESTTOPIC - Topic for the Forest Channel"; | |
109 | directives[6].desc = "REMOTESERVER - Server for gameserv to connect to (ip or hostname)"; | |
110 | directives[7].desc = "REMOTEPORT - Port on the remote server to connect to"; | |
111 | directives[8].desc = "REMOTEPASS - Password on the remote server"; | |
112 | directives[9].desc = "PLAYERDATA - File to store the player saves in"; | |
113 | directives[10].desc = "MONSTERDATA - File to load the monsters from"; | |
114 | directives[11].desc = "ADMINPASS - Password to identify as an admin with"; | |
115 | directives[12].desc = "WELCOMEDELAY - Delay (in seconds) to wait before welcoming new users to the network"; | |
116 | directives[13].desc = "FORESTFIGHTS - Number of forest fights players get every day"; | |
117 | directives[14].desc = "UPDATEPERIOD - Number of seconds between every player data save"; | |
18b84d11 | 118 | directives[15].desc = "PIDFILE - Filename to store the gameserv process ID in"; |
119 | directives[16].desc = "MAXAFIGHTDISTANCE - The maximum number of levels above you "\ | |
8450c018 | 120 | "that you can fight player->player"; |
18b84d11 | 121 | directives[17].desc = "MAXBFIGHTDISTANCE - The maximum number of levels below you "\ |
8450c018 | 122 | "that you can fight player->player"; |
18b84d11 | 123 | directives[18].desc = "MAXIDLETIME - The maximum amount of time (in seconds) "\ |
40251952 | 124 | "that a player can be idle before something happens"; |
18b84d11 | 125 | directives[19].desc = "IDLECHECKPERIOD - The period (in seconds) in which the entire "\ |
40251952 | 126 | "players list will be checked for idlers. See also: "\ |
127 | "MAXIDLETIME"; | |
18b84d11 | 128 | directives[20].desc = "LISTENONC_FOREST - True/False as to "\ |
448a1531 | 129 | "whether or not to listen for forest "\ |
130 | "commands on the forest channel"; | |
c260a8d7 | 131 | directives[21].desc = "NEWSDATA - File to store daily news in"; |
1e1b5312 | 132 | |
9bafc40d | 133 | configflags = 0; |
134 | ||
1e1b5312 | 135 | for (int count = 0; count < numdirectives; count++) |
136 | { | |
137 | directives[count].done = false; | |
138 | } | |
139 | ||
85ce9d3e | 140 | ifstream infile; |
141 | infile.open(config); | |
142 | if (infile.fail()) | |
143 | { | |
fb37ecc7 | 144 | log("Error opening %s", config); |
33ac4371 | 145 | cerr << "Error opening " << config << endl; |
624c0352 | 146 | return 0; |
85ce9d3e | 147 | } |
148 | ||
1e1b5312 | 149 | buf = new char[1024]; |
150 | ||
85ce9d3e | 151 | while (infile.getline(buf, 1024, '\n')) |
152 | { | |
9f8c2acc | 153 | #ifdef DEBUGMODE |
33ac4371 | 154 | log("Config file entry buf: %s", buf); |
9f8c2acc | 155 | #endif |
85ce9d3e | 156 | |
9cc5ab57 | 157 | if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') |
85ce9d3e | 158 | continue; |
159 | ||
160 | directive = strtok(buf, " "); | |
161 | ||
20d5d721 | 162 | if (stricmp(directive, "DIE") == 0) |
163 | { | |
164 | value = strtok(NULL, ""); | |
fb37ecc7 | 165 | log("You should read the entire %s file!", config); |
33ac4371 | 166 | cerr << "You should read the entire " << config << " file!" |
167 | << endl; | |
1e1b5312 | 168 | delete []buf; |
20d5d721 | 169 | exit(0); |
170 | } | |
85ce9d3e | 171 | if (stricmp(directive, "S_GAMESERV") == 0) |
172 | { | |
173 | value = strtok(NULL, " "); | |
174 | s_GameServ = new char[strlen(value) + 1]; | |
175 | strcpy(s_GameServ, value); | |
1e1b5312 | 176 | directives[0].done = true; |
85ce9d3e | 177 | } |
178 | else if (stricmp(directive, "GSHOST") == 0) | |
179 | { | |
180 | value = strtok(NULL, " "); | |
181 | gshost = new char[strlen(value) + 1]; | |
182 | strcpy(gshost, value); | |
1e1b5312 | 183 | directives[1].done = true; |
85ce9d3e | 184 | } |
185 | else if (stricmp(directive, "GSIDENT") == 0) | |
186 | { | |
187 | value = strtok(NULL, " "); | |
188 | gsident = new char[strlen(value) + 1]; | |
189 | strcpy(gsident, value); | |
1e1b5312 | 190 | directives[2].done = true; |
85ce9d3e | 191 | } |
192 | else if (stricmp(directive, "SERVERNAME") == 0) | |
193 | { | |
194 | value = strtok(NULL, " "); | |
195 | servername = new char[strlen(value) + 1]; | |
196 | strcpy(servername, value); | |
1e1b5312 | 197 | directives[3].done = true; |
85ce9d3e | 198 | } |
199 | else if (stricmp(directive, "C_FOREST") == 0) | |
200 | { | |
201 | value = strtok(NULL, " "); | |
202 | c_Forest = new char[strlen(value) + 1]; | |
203 | strcpy(c_Forest, value); | |
1e1b5312 | 204 | directives[4].done = true; |
85ce9d3e | 205 | } |
206 | else if (stricmp(directive, "C_FORESTTOPIC") == 0) | |
207 | { | |
208 | value = strtok(NULL, ""); | |
209 | c_ForestTopic = new char[strlen(value) + 1]; | |
210 | strcpy(c_ForestTopic, value); | |
1e1b5312 | 211 | directives[5].done = true; |
85ce9d3e | 212 | } |
213 | else if (stricmp(directive, "REMOTESERVER") == 0) | |
214 | { | |
215 | value = strtok(NULL, " "); | |
216 | remoteserver = new char[strlen(value) + 1]; | |
217 | strcpy(remoteserver, value); | |
1e1b5312 | 218 | directives[6].done = true; |
85ce9d3e | 219 | } |
220 | else if (stricmp(directive, "REMOTEPORT") == 0) | |
221 | { | |
222 | value = strtok(NULL, " "); | |
223 | remoteport = new char[strlen(value) + 1]; | |
224 | strcpy(remoteport, value); | |
1e1b5312 | 225 | directives[7].done = true; |
85ce9d3e | 226 | } |
227 | else if (stricmp(directive, "REMOTEPASS") == 0) | |
228 | { | |
229 | value = strtok(NULL, ""); | |
230 | remotepass = new char[strlen(value) + 1]; | |
231 | strcpy(remotepass, value); | |
1e1b5312 | 232 | directives[8].done = true; |
85ce9d3e | 233 | } |
234 | else if (stricmp(directive, "PLAYERDATA") == 0) | |
235 | { | |
236 | value = strtok(NULL, ""); | |
237 | playerdata = new char[strlen(value) + 1]; | |
238 | strcpy(playerdata, value); | |
1e1b5312 | 239 | directives[9].done = true; |
85ce9d3e | 240 | } |
4dde2ed9 | 241 | else if (stricmp(directive, "MONSTERDATA") == 0) |
242 | { | |
243 | value = strtok(NULL, ""); | |
244 | monsterdata = new char[strlen(value) + 1]; | |
245 | strcpy(monsterdata, value); | |
1e1b5312 | 246 | directives[10].done = true; |
4dde2ed9 | 247 | } |
45a84400 | 248 | else if (stricmp(directive, "ADMINPASS") == 0) |
249 | { | |
250 | value = strtok(NULL, ""); | |
251 | adminpass = new char[strlen(value) + 1]; | |
252 | strcpy(adminpass, value); | |
1e1b5312 | 253 | directives[11].done = true; |
45a84400 | 254 | } |
922daad7 | 255 | else if (stricmp(directive, "WELCOMEDELAY") == 0) |
bf2cabcd | 256 | { |
257 | value = strtok(NULL, " "); | |
922daad7 | 258 | welcomedelay = stringtoint(value); |
1e1b5312 | 259 | directives[12].done = true; |
922daad7 | 260 | } |
20d5d721 | 261 | else if (stricmp(directive, "FORESTFIGHTS") == 0) |
262 | { | |
263 | value = strtok(NULL, " "); | |
264 | forestfights = stringtoint(value); | |
1e1b5312 | 265 | directives[13].done = true; |
20d5d721 | 266 | } |
922daad7 | 267 | else if (stricmp(directive, "UPDATEPERIOD") == 0) |
268 | { | |
269 | value = strtok(NULL, " "); | |
270 | updateperiod = stringtoint(value); | |
1e1b5312 | 271 | directives[14].done = true; |
bf2cabcd | 272 | } |
69ae096c | 273 | else if (stricmp(directive, "PIDFILE") == 0) |
274 | { | |
275 | value = strtok(NULL, " "); | |
276 | pidfile = new char[strlen(value) + 1]; | |
277 | strcpy(pidfile, value); | |
18b84d11 | 278 | directives[15].done = true; |
69ae096c | 279 | } |
8450c018 | 280 | else if (stricmp(directive, "MAXAFIGHTDISTANCE") == 0) |
281 | { | |
282 | value = strtok(NULL, " "); | |
283 | maxafightdistance = stringtoint(value); | |
18b84d11 | 284 | directives[16].done = true;; |
8450c018 | 285 | } |
286 | else if (stricmp(directive, "MAXBFIGHTDISTANCE") == 0) | |
287 | { | |
288 | value = strtok(NULL, " "); | |
289 | maxbfightdistance = stringtoint(value); | |
18b84d11 | 290 | directives[17].done = true; |
8450c018 | 291 | } |
40251952 | 292 | else if (stricmp(directive, "MAXIDLETIME") == 0) |
293 | { | |
294 | value = strtok(NULL, " "); | |
295 | maxidletime = stringtoint(value); | |
18b84d11 | 296 | directives[18].done = true; |
40251952 | 297 | } |
298 | else if (stricmp(directive, "IDLECHECKPERIOD") == 0) | |
299 | { | |
300 | value = strtok(NULL, " "); | |
301 | idlecheckperiod = stringtoint(value); | |
18b84d11 | 302 | directives[19].done = true; |
40251952 | 303 | } |
ff7d02f3 | 304 | else if (stricmp(directive, "LISTENONC_FOREST") == 0) |
305 | { | |
306 | value = strtok(NULL, " "); | |
307 | if (stricmp(value, "TRUE") == 0) | |
6f727d4c | 308 | setListenOnCF(); |
ff7d02f3 | 309 | |
18b84d11 | 310 | directives[20].done = true; |
311 | } | |
c260a8d7 | 312 | else if (stricmp(directive, "NEWSDATA") == 0) |
313 | { | |
314 | value = strtok(NULL, " "); | |
315 | newsdata = new char [strlen(value) + 1]; | |
316 | strcpy(newsdata, value); | |
317 | directives[21].done = true; | |
318 | } | |
18b84d11 | 319 | else if (stricmp(directive, "WELCOMEMSG") == 0) |
320 | { | |
321 | // This directive is optional | |
322 | value = strtok(NULL, ""); | |
323 | welcomemsg = new char[strlen(value) + 1]; | |
324 | strcpy(welcomemsg, value); | |
325 | setWelcome(); | |
ff7d02f3 | 326 | } |
9bafc40d | 327 | else if (stricmp(directive, "USEPRIVMSG") == 0) |
328 | { | |
329 | // This directive is optional | |
6f727d4c | 330 | setUsePrivmsg(); |
331 | } | |
332 | else if (stricmp(directive, "BOPER") == 0) | |
333 | { | |
334 | // This directive is optional | |
335 | setBOper(); | |
9bafc40d | 336 | } |
448a1531 | 337 | else if (stricmp(directive, "IGNORESERVERS") == 0) |
338 | { | |
339 | // This directive is optional | |
340 | value = strtok(NULL, ""); | |
341 | ignoreserverslist = new char[strlen(value) + 1]; | |
342 | strcpy(ignoreserverslist, value); | |
343 | } | |
85ce9d3e | 344 | else |
345 | { | |
9f8c2acc | 346 | #ifdef DEBUGMODE |
347 | log("Unknown Directive. Buffer: %s", buf); | |
33ac4371 | 348 | cerr << "Unknown " << config << " directive. Buffer: " |
349 | << buf << endl; | |
9f8c2acc | 350 | #endif |
85ce9d3e | 351 | continue; |
352 | } | |
85ce9d3e | 353 | } |
1cf88153 | 354 | delete [] buf; |
85ce9d3e | 355 | infile.close(); |
1e1b5312 | 356 | |
357 | int nonemissing = 1; | |
358 | for (int count2 = 0; count2 < numdirectives; count2++) | |
359 | { | |
360 | if (!directives[count2].done) | |
361 | { | |
362 | cerr << "Missing config directive: " << directives[count2].desc << endl; | |
363 | nonemissing = 0; | |
364 | } | |
365 | } | |
366 | ||
367 | return nonemissing; | |
85ce9d3e | 368 | } |