]>
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 |
69ae096c | 43 | char *pidfile; // Process ID file |
85ce9d3e | 44 | |
e1c41a84 | 45 | #if defined(P10) |
46 | char *gsnum = "[]AAA"; // GameServ Numeric | |
47 | #endif | |
48 | ||
85ce9d3e | 49 | void unload_config_file() |
50 | { | |
51 | if (s_GameServ) | |
1cf88153 | 52 | delete [] s_GameServ; |
85ce9d3e | 53 | if (gshost) |
1cf88153 | 54 | delete [] gshost; |
85ce9d3e | 55 | if (gsident) |
1cf88153 | 56 | delete [] gsident; |
85ce9d3e | 57 | if (servername) |
1cf88153 | 58 | delete [] servername; |
85ce9d3e | 59 | if (c_Forest) |
1cf88153 | 60 | delete [] c_Forest; |
85ce9d3e | 61 | if (c_ForestTopic) |
1cf88153 | 62 | delete [] c_ForestTopic; |
85ce9d3e | 63 | if (remoteserver) |
1cf88153 | 64 | delete [] remoteserver; |
85ce9d3e | 65 | if (remoteport) |
1cf88153 | 66 | delete [] remoteport; |
85ce9d3e | 67 | if (remotepass) |
1cf88153 | 68 | delete [] remotepass; |
85ce9d3e | 69 | if (playerdata) |
1cf88153 | 70 | delete [] playerdata; |
4dde2ed9 | 71 | if (monsterdata) |
72 | delete [] monsterdata; | |
45a84400 | 73 | if (adminpass) |
74 | delete [] adminpass; | |
bf2cabcd | 75 | if (welcomemsg) |
76 | delete [] welcomemsg; | |
69ae096c | 77 | if (pidfile) |
78 | delete [] pidfile; | |
448a1531 | 79 | if (ignoreserverslist) |
80 | delete [] ignoreserverslist; | |
9bafc40d | 81 | |
82 | configflags = 0; | |
85ce9d3e | 83 | } |
bf2cabcd | 84 | |
624c0352 | 85 | int load_config_file(char *config) |
85ce9d3e | 86 | { |
87 | char *buf, *directive, *value; | |
69ae096c | 88 | |
ff7d02f3 | 89 | #define numdirectives 22 |
85ce9d3e | 90 | |
91 | unload_config_file(); | |
92 | ||
1e1b5312 | 93 | struct DIRECTIVE { |
94 | bool done; | |
95 | char *desc; | |
96 | }; | |
97 | ||
98 | DIRECTIVE directives[numdirectives]; | |
99 | ||
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"; | |
69ae096c | 116 | directives[16].desc = "PIDFILE - Filename to store the gameserv process ID in"; |
8450c018 | 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"; | |
40251952 | 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: "\ | |
125 | "MAXIDLETIME"; | |
ff7d02f3 | 126 | directives[21].desc = "LISTENONC_FOREST - True/False as to "\ |
448a1531 | 127 | "whether or not to listen for forest "\ |
128 | "commands on the forest channel"; | |
1e1b5312 | 129 | |
9bafc40d | 130 | configflags = 0; |
131 | ||
1e1b5312 | 132 | for (int count = 0; count < numdirectives; count++) |
133 | { | |
134 | directives[count].done = false; | |
135 | } | |
136 | ||
85ce9d3e | 137 | ifstream infile; |
138 | infile.open(config); | |
139 | if (infile.fail()) | |
140 | { | |
fb37ecc7 | 141 | log("Error opening %s", config); |
33ac4371 | 142 | cerr << "Error opening " << config << endl; |
624c0352 | 143 | return 0; |
85ce9d3e | 144 | } |
145 | ||
1e1b5312 | 146 | buf = new char[1024]; |
147 | ||
85ce9d3e | 148 | while (infile.getline(buf, 1024, '\n')) |
149 | { | |
9f8c2acc | 150 | #ifdef DEBUGMODE |
33ac4371 | 151 | log("Config file entry buf: %s", buf); |
9f8c2acc | 152 | #endif |
85ce9d3e | 153 | |
9cc5ab57 | 154 | if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') |
85ce9d3e | 155 | continue; |
156 | ||
157 | directive = strtok(buf, " "); | |
158 | ||
20d5d721 | 159 | if (stricmp(directive, "DIE") == 0) |
160 | { | |
161 | value = strtok(NULL, ""); | |
fb37ecc7 | 162 | log("You should read the entire %s file!", config); |
33ac4371 | 163 | cerr << "You should read the entire " << config << " file!" |
164 | << endl; | |
1e1b5312 | 165 | delete []buf; |
20d5d721 | 166 | exit(0); |
167 | } | |
85ce9d3e | 168 | if (stricmp(directive, "S_GAMESERV") == 0) |
169 | { | |
170 | value = strtok(NULL, " "); | |
171 | s_GameServ = new char[strlen(value) + 1]; | |
172 | strcpy(s_GameServ, value); | |
1e1b5312 | 173 | directives[0].done = true; |
85ce9d3e | 174 | } |
175 | else if (stricmp(directive, "GSHOST") == 0) | |
176 | { | |
177 | value = strtok(NULL, " "); | |
178 | gshost = new char[strlen(value) + 1]; | |
179 | strcpy(gshost, value); | |
1e1b5312 | 180 | directives[1].done = true; |
85ce9d3e | 181 | } |
182 | else if (stricmp(directive, "GSIDENT") == 0) | |
183 | { | |
184 | value = strtok(NULL, " "); | |
185 | gsident = new char[strlen(value) + 1]; | |
186 | strcpy(gsident, value); | |
1e1b5312 | 187 | directives[2].done = true; |
85ce9d3e | 188 | } |
189 | else if (stricmp(directive, "SERVERNAME") == 0) | |
190 | { | |
191 | value = strtok(NULL, " "); | |
192 | servername = new char[strlen(value) + 1]; | |
193 | strcpy(servername, value); | |
1e1b5312 | 194 | directives[3].done = true; |
85ce9d3e | 195 | } |
196 | else if (stricmp(directive, "C_FOREST") == 0) | |
197 | { | |
198 | value = strtok(NULL, " "); | |
199 | c_Forest = new char[strlen(value) + 1]; | |
200 | strcpy(c_Forest, value); | |
1e1b5312 | 201 | directives[4].done = true; |
85ce9d3e | 202 | } |
203 | else if (stricmp(directive, "C_FORESTTOPIC") == 0) | |
204 | { | |
205 | value = strtok(NULL, ""); | |
206 | c_ForestTopic = new char[strlen(value) + 1]; | |
207 | strcpy(c_ForestTopic, value); | |
1e1b5312 | 208 | directives[5].done = true; |
85ce9d3e | 209 | } |
210 | else if (stricmp(directive, "REMOTESERVER") == 0) | |
211 | { | |
212 | value = strtok(NULL, " "); | |
213 | remoteserver = new char[strlen(value) + 1]; | |
214 | strcpy(remoteserver, value); | |
1e1b5312 | 215 | directives[6].done = true; |
85ce9d3e | 216 | } |
217 | else if (stricmp(directive, "REMOTEPORT") == 0) | |
218 | { | |
219 | value = strtok(NULL, " "); | |
220 | remoteport = new char[strlen(value) + 1]; | |
221 | strcpy(remoteport, value); | |
1e1b5312 | 222 | directives[7].done = true; |
85ce9d3e | 223 | } |
224 | else if (stricmp(directive, "REMOTEPASS") == 0) | |
225 | { | |
226 | value = strtok(NULL, ""); | |
227 | remotepass = new char[strlen(value) + 1]; | |
228 | strcpy(remotepass, value); | |
1e1b5312 | 229 | directives[8].done = true; |
85ce9d3e | 230 | } |
231 | else if (stricmp(directive, "PLAYERDATA") == 0) | |
232 | { | |
233 | value = strtok(NULL, ""); | |
234 | playerdata = new char[strlen(value) + 1]; | |
235 | strcpy(playerdata, value); | |
1e1b5312 | 236 | directives[9].done = true; |
85ce9d3e | 237 | } |
4dde2ed9 | 238 | else if (stricmp(directive, "MONSTERDATA") == 0) |
239 | { | |
240 | value = strtok(NULL, ""); | |
241 | monsterdata = new char[strlen(value) + 1]; | |
242 | strcpy(monsterdata, value); | |
1e1b5312 | 243 | directives[10].done = true; |
4dde2ed9 | 244 | } |
45a84400 | 245 | else if (stricmp(directive, "ADMINPASS") == 0) |
246 | { | |
247 | value = strtok(NULL, ""); | |
248 | adminpass = new char[strlen(value) + 1]; | |
249 | strcpy(adminpass, value); | |
1e1b5312 | 250 | directives[11].done = true; |
45a84400 | 251 | } |
922daad7 | 252 | else if (stricmp(directive, "WELCOMEDELAY") == 0) |
bf2cabcd | 253 | { |
254 | value = strtok(NULL, " "); | |
922daad7 | 255 | welcomedelay = stringtoint(value); |
1e1b5312 | 256 | directives[12].done = true; |
922daad7 | 257 | } |
20d5d721 | 258 | else if (stricmp(directive, "FORESTFIGHTS") == 0) |
259 | { | |
260 | value = strtok(NULL, " "); | |
261 | forestfights = stringtoint(value); | |
1e1b5312 | 262 | directives[13].done = true; |
20d5d721 | 263 | } |
922daad7 | 264 | else if (stricmp(directive, "UPDATEPERIOD") == 0) |
265 | { | |
266 | value = strtok(NULL, " "); | |
267 | updateperiod = stringtoint(value); | |
1e1b5312 | 268 | directives[14].done = true; |
bf2cabcd | 269 | } |
270 | else if (stricmp(directive, "WELCOMEMSG") == 0) | |
271 | { | |
272 | value = strtok(NULL, ""); | |
273 | welcomemsg = new char[strlen(value) + 1]; | |
274 | strcpy(welcomemsg, value); | |
1e1b5312 | 275 | directives[15].done = true; |
bf2cabcd | 276 | } |
69ae096c | 277 | else if (stricmp(directive, "PIDFILE") == 0) |
278 | { | |
279 | value = strtok(NULL, " "); | |
280 | pidfile = new char[strlen(value) + 1]; | |
281 | strcpy(pidfile, value); | |
282 | directives[16].done = true; | |
283 | } | |
8450c018 | 284 | else if (stricmp(directive, "MAXAFIGHTDISTANCE") == 0) |
285 | { | |
286 | value = strtok(NULL, " "); | |
287 | maxafightdistance = stringtoint(value); | |
288 | directives[17].done = true;; | |
289 | } | |
290 | else if (stricmp(directive, "MAXBFIGHTDISTANCE") == 0) | |
291 | { | |
292 | value = strtok(NULL, " "); | |
293 | maxbfightdistance = stringtoint(value); | |
294 | directives[18].done = true; | |
295 | } | |
40251952 | 296 | else if (stricmp(directive, "MAXIDLETIME") == 0) |
297 | { | |
298 | value = strtok(NULL, " "); | |
299 | maxidletime = stringtoint(value); | |
300 | directives[19].done = true; | |
301 | } | |
302 | else if (stricmp(directive, "IDLECHECKPERIOD") == 0) | |
303 | { | |
304 | value = strtok(NULL, " "); | |
305 | idlecheckperiod = stringtoint(value); | |
306 | directives[20].done = true; | |
307 | } | |
ff7d02f3 | 308 | else if (stricmp(directive, "LISTENONC_FOREST") == 0) |
309 | { | |
310 | value = strtok(NULL, " "); | |
311 | if (stricmp(value, "TRUE") == 0) | |
6f727d4c | 312 | setListenOnCF(); |
ff7d02f3 | 313 | |
314 | directives[21].done = true; | |
315 | } | |
9bafc40d | 316 | else if (stricmp(directive, "USEPRIVMSG") == 0) |
317 | { | |
318 | // This directive is optional | |
6f727d4c | 319 | setUsePrivmsg(); |
320 | } | |
321 | else if (stricmp(directive, "BOPER") == 0) | |
322 | { | |
323 | // This directive is optional | |
324 | setBOper(); | |
9bafc40d | 325 | } |
448a1531 | 326 | else if (stricmp(directive, "IGNORESERVERS") == 0) |
327 | { | |
328 | // This directive is optional | |
329 | value = strtok(NULL, ""); | |
330 | ignoreserverslist = new char[strlen(value) + 1]; | |
331 | strcpy(ignoreserverslist, value); | |
332 | } | |
85ce9d3e | 333 | else |
334 | { | |
9f8c2acc | 335 | #ifdef DEBUGMODE |
336 | log("Unknown Directive. Buffer: %s", buf); | |
33ac4371 | 337 | cerr << "Unknown " << config << " directive. Buffer: " |
338 | << buf << endl; | |
9f8c2acc | 339 | #endif |
85ce9d3e | 340 | continue; |
341 | } | |
85ce9d3e | 342 | } |
1cf88153 | 343 | delete [] buf; |
85ce9d3e | 344 | infile.close(); |
1e1b5312 | 345 | |
346 | int nonemissing = 1; | |
347 | for (int count2 = 0; count2 < numdirectives; count2++) | |
348 | { | |
349 | if (!directives[count2].done) | |
350 | { | |
351 | cerr << "Missing config directive: " << directives[count2].desc << endl; | |
352 | nonemissing = 0; | |
353 | } | |
354 | } | |
355 | ||
356 | return nonemissing; | |
85ce9d3e | 357 | } |