1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | |
3 | * |
|
|
4 | * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
|
|
5 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
7 | * Copyright (©) 1992 Frank Tore Johansen |
6 | |
8 | * |
7 | This program is free software; you can redistribute it and/or modify |
9 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | it under the terms of the GNU General Public License as published by |
10 | * the terms of the Affero GNU General Public License as published by the |
9 | the Free Software Foundation; either version 2 of the License, or |
11 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | (at your option) any later version. |
12 | * option) any later version. |
11 | |
13 | * |
12 | This program is distributed in the hope that it will be useful, |
14 | * This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
17 | * GNU General Public License for more details. |
16 | |
18 | * |
17 | You should have received a copy of the GNU General Public License |
19 | * You should have received a copy of the Affero GNU General Public License |
18 | along with this program; if not, write to the Free Software |
20 | * and the GNU General Public License along with this program. If not, see |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | * <http://www.gnu.org/licenses/>. |
20 | |
22 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
23 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
24 | */ |
23 | |
25 | |
24 | #include <global.h> |
26 | #include <global.h> |
25 | #include <material.h> |
27 | #include <material.h> |
26 | #include <loader.h> |
|
|
27 | #ifndef __CEXTRACT__ |
|
|
28 | # include <sproto.h> |
28 | #include <sproto.h> |
29 | #endif |
|
|
30 | |
|
|
31 | /* global weathermap */ |
|
|
32 | weathermap_t **weathermap; |
|
|
33 | |
|
|
34 | void |
|
|
35 | set_logfile (char *val) |
|
|
36 | { |
|
|
37 | settings.logfilename = val; |
|
|
38 | } |
|
|
39 | |
|
|
40 | void |
|
|
41 | call_version (void) |
|
|
42 | { |
|
|
43 | version (NULL); |
|
|
44 | exit (0); |
|
|
45 | } |
|
|
46 | |
|
|
47 | void |
|
|
48 | showscores (void) |
|
|
49 | { |
|
|
50 | display_high_score (NULL, 9999, NULL); |
|
|
51 | exit (0); |
|
|
52 | } |
|
|
53 | |
|
|
54 | void |
|
|
55 | set_debug (void) |
|
|
56 | { |
|
|
57 | settings.debug = llevDebug; |
|
|
58 | } |
|
|
59 | |
|
|
60 | void |
|
|
61 | unset_debug (void) |
|
|
62 | { |
|
|
63 | settings.debug = llevInfo; |
|
|
64 | } |
|
|
65 | |
|
|
66 | void |
|
|
67 | set_mondebug (void) |
|
|
68 | { |
|
|
69 | settings.debug = llevMonster; |
|
|
70 | } |
|
|
71 | |
|
|
72 | void |
|
|
73 | set_dumpmon1 (void) |
|
|
74 | { |
|
|
75 | settings.dumpvalues = 1; |
|
|
76 | } |
|
|
77 | |
|
|
78 | void |
|
|
79 | set_dumpmon2 (void) |
|
|
80 | { |
|
|
81 | settings.dumpvalues = 2; |
|
|
82 | } |
|
|
83 | |
|
|
84 | void |
|
|
85 | set_dumpmon3 (void) |
|
|
86 | { |
|
|
87 | settings.dumpvalues = 3; |
|
|
88 | } |
|
|
89 | |
|
|
90 | void |
|
|
91 | set_dumpmon4 (void) |
|
|
92 | { |
|
|
93 | settings.dumpvalues = 4; |
|
|
94 | } |
|
|
95 | |
|
|
96 | void |
|
|
97 | set_dumpmon5 (void) |
|
|
98 | { |
|
|
99 | settings.dumpvalues = 5; |
|
|
100 | } |
|
|
101 | |
|
|
102 | void |
|
|
103 | set_dumpmon6 (void) |
|
|
104 | { |
|
|
105 | settings.dumpvalues = 6; |
|
|
106 | } |
|
|
107 | |
|
|
108 | void |
|
|
109 | set_dumpmon7 (void) |
|
|
110 | { |
|
|
111 | settings.dumpvalues = 7; |
|
|
112 | } |
|
|
113 | |
|
|
114 | void |
|
|
115 | set_dumpmon8 (void) |
|
|
116 | { |
|
|
117 | settings.dumpvalues = 8; |
|
|
118 | } |
|
|
119 | |
|
|
120 | void |
|
|
121 | set_dumpmon9 (void) |
|
|
122 | { |
|
|
123 | settings.dumpvalues = 9; |
|
|
124 | } |
|
|
125 | |
|
|
126 | void |
|
|
127 | set_dumpmont (char *name) |
|
|
128 | { |
|
|
129 | settings.dumpvalues = 10; |
|
|
130 | settings.dumparg = name; |
|
|
131 | } |
|
|
132 | |
|
|
133 | void |
|
|
134 | set_daemon (void) |
|
|
135 | { |
|
|
136 | settings.daemonmode = 1; |
|
|
137 | } |
|
|
138 | |
|
|
139 | void |
|
|
140 | set_datadir (char *path) |
|
|
141 | { |
|
|
142 | settings.datadir = path; |
|
|
143 | } |
|
|
144 | |
|
|
145 | void |
|
|
146 | set_confdir (char *path) |
|
|
147 | { |
|
|
148 | settings.confdir = path; |
|
|
149 | } |
|
|
150 | |
|
|
151 | void |
|
|
152 | set_localdir (char *path) |
|
|
153 | { |
|
|
154 | settings.localdir = path; |
|
|
155 | } |
|
|
156 | |
|
|
157 | void |
|
|
158 | set_mapdir (char *path) |
|
|
159 | { |
|
|
160 | settings.mapdir = path; |
|
|
161 | } |
|
|
162 | |
|
|
163 | void |
|
|
164 | set_archetypes (char *path) |
|
|
165 | { |
|
|
166 | settings.archetypes = path; |
|
|
167 | } |
|
|
168 | |
|
|
169 | void |
|
|
170 | set_regions (char *path) |
|
|
171 | { |
|
|
172 | settings.regions = path; |
|
|
173 | } |
|
|
174 | |
|
|
175 | void |
|
|
176 | set_treasures (char *path) |
|
|
177 | { |
|
|
178 | settings.treasures = path; |
|
|
179 | } |
|
|
180 | |
|
|
181 | void |
|
|
182 | set_uniquedir (char *path) |
|
|
183 | { |
|
|
184 | settings.uniquedir = path; |
|
|
185 | } |
|
|
186 | |
|
|
187 | void |
|
|
188 | set_templatedir (char *path) |
|
|
189 | { |
|
|
190 | settings.templatedir = path; |
|
|
191 | } |
|
|
192 | |
|
|
193 | void |
|
|
194 | set_playerdir (char *path) |
|
|
195 | { |
|
|
196 | settings.playerdir = path; |
|
|
197 | } |
|
|
198 | |
|
|
199 | void |
|
|
200 | set_tmpdir (char *path) |
|
|
201 | { |
|
|
202 | settings.tmpdir = path; |
|
|
203 | } |
|
|
204 | |
|
|
205 | void |
|
|
206 | showscoresparm (char *data) |
|
|
207 | { |
|
|
208 | display_high_score (NULL, 9999, data); |
|
|
209 | exit (0); |
|
|
210 | } |
|
|
211 | |
|
|
212 | void |
|
|
213 | set_csport (char *val) |
|
|
214 | { |
|
|
215 | settings.csport = atoi (val); |
|
|
216 | #ifndef WIN32 /* ***win32: set_csport: we remove csport error secure check here, do this later */ |
|
|
217 | if (settings.csport <= 0 || settings.csport > 32765 || (settings.csport < 1024 && getuid () != 0)) |
|
|
218 | { |
|
|
219 | LOG (llevError, "%d is an invalid csport number.\n", settings.csport); |
|
|
220 | exit (1); |
|
|
221 | } |
|
|
222 | #endif /* win32 */ |
|
|
223 | } |
|
|
224 | |
|
|
225 | /* Most of this is shamelessly stolen from XSysStats. But since that is |
|
|
226 | * also my program, no problem. |
|
|
227 | */ |
|
|
228 | struct Command_Line_Options |
|
|
229 | { |
|
|
230 | const char *cmd_option; /* how it is called on the command line */ |
|
|
231 | uint8 num_args; /* Number or args it takes */ |
|
|
232 | uint8 pass; /* What pass this should be processed on. */ |
|
|
233 | void (*func) (); /* function to call when we match this. |
|
|
234 | * if num_args is true, than that gets passed |
|
|
235 | * to the function, otherwise nothing is passed |
|
|
236 | */ |
|
|
237 | }; |
|
|
238 | |
|
|
239 | /* The way this system works is pretty simple - parse_args takes |
|
|
240 | * the options passed to the program and a pass number. If an option |
|
|
241 | * matches both in name and in pass (and we have enough options), |
|
|
242 | * we call the associated function. This makes writing a multi |
|
|
243 | * pass system very easy, and it is very easy to add in new options. |
|
|
244 | */ |
|
|
245 | struct Command_Line_Options options[] = { |
|
|
246 | |
|
|
247 | /* Pass 1 functions - STuff that can/should be called before we actually |
|
|
248 | * initialize any data. |
|
|
249 | */ |
|
|
250 | {"-h", 0, 1, help}, |
|
|
251 | |
|
|
252 | /* Honor -help also, since it is somewhat common */ |
|
|
253 | {"-help", 0, 1, help}, |
|
|
254 | {"-v", 0, 1, call_version}, |
|
|
255 | {"-d", 0, 1, set_debug}, |
|
|
256 | {"+d", 0, 1, unset_debug}, |
|
|
257 | {"-mon", 0, 1, set_mondebug}, |
|
|
258 | {"-data", 1, 1, (void (*)()) set_datadir}, |
|
|
259 | {"-conf", 1, 1, (void (*)()) set_confdir}, |
|
|
260 | {"-local", 1, 1, (void (*)()) set_localdir}, |
|
|
261 | {"-maps", 1, 1, (void (*)()) set_mapdir}, |
|
|
262 | {"-arch", 1, 1, (void (*)()) set_archetypes}, |
|
|
263 | {"-regions", 1, 1, (void (*)()) set_regions}, |
|
|
264 | {"-playerdir", 1, 1, (void (*)()) set_playerdir}, |
|
|
265 | {"-treasures", 1, 1, (void (*)()) set_treasures}, |
|
|
266 | {"-uniquedir", 1, 1, (void (*)()) set_uniquedir}, |
|
|
267 | {"-templatedir", 1, 1, (void (*)()) set_templatedir}, |
|
|
268 | {"-tmpdir", 1, 1, (void (*)()) set_tmpdir}, |
|
|
269 | {"-log", 1, 1, (void (*)()) set_logfile}, |
|
|
270 | |
|
|
271 | #ifdef WIN32 |
|
|
272 | |
|
|
273 | /* Windows service stuff */ |
|
|
274 | {"-regsrv", 0, 1, service_register}, |
|
|
275 | {"-unregsrv", 0, 1, service_unregister}, |
|
|
276 | {"-srv", 0, 1, service_handle}, |
|
|
277 | #endif |
|
|
278 | |
|
|
279 | /* Pass 2 functions. Most of these could probably be in pass 1, |
|
|
280 | * as they don't require much of anything to bet set up. |
|
|
281 | */ |
|
|
282 | {"-csport", 1, 2, (void (*)()) set_csport}, |
|
|
283 | {"-detach", 0, 2, set_daemon}, |
|
|
284 | |
|
|
285 | /* Start of pass 3 information. In theory, by pass 3, all data paths |
|
|
286 | * and defaults should have been set up. |
|
|
287 | */ |
|
|
288 | {"-o", 0, 3, compile_info}, |
|
|
289 | {"-m", 0, 3, set_dumpmon1}, |
|
|
290 | {"-m2", 0, 3, set_dumpmon2}, |
|
|
291 | {"-m3", 0, 3, set_dumpmon3}, |
|
|
292 | {"-m4", 0, 3, set_dumpmon4}, |
|
|
293 | {"-m5", 0, 3, set_dumpmon5}, |
|
|
294 | {"-m6", 0, 3, set_dumpmon6}, |
|
|
295 | {"-m7", 0, 3, set_dumpmon7}, |
|
|
296 | {"-m8", 0, 3, set_dumpmon8}, |
|
|
297 | {"-m9", 0, 3, set_dumpmon9}, |
|
|
298 | {"-mt", 1, 3, (void (*)()) set_dumpmont}, |
|
|
299 | {"-mexp", 0, 3, dump_experience}, |
|
|
300 | {"-s", 0, 3, showscores}, |
|
|
301 | {"-score", 1, 3, (void (*)()) showscoresparm} |
|
|
302 | }; |
|
|
303 | |
|
|
304 | |
|
|
305 | /* Note since this may be called before the library has been set up, |
|
|
306 | * we don't use any of crossfires built in logging functions. |
|
|
307 | */ |
|
|
308 | static void |
|
|
309 | parse_args (int argc, char *argv[], int pass) |
|
|
310 | { |
|
|
311 | size_t i; |
|
|
312 | int on_arg = 1; |
|
|
313 | |
|
|
314 | while (on_arg < argc) |
|
|
315 | { |
|
|
316 | for (i = 0; i < sizeof (options) / sizeof (struct Command_Line_Options); i++) |
|
|
317 | { |
|
|
318 | if (!strcmp (options[i].cmd_option, argv[on_arg])) |
|
|
319 | { |
|
|
320 | /* Found a matching option, but should not be processed on |
|
|
321 | * this pass. Just skip over it |
|
|
322 | */ |
|
|
323 | if (options[i].pass != pass) |
|
|
324 | { |
|
|
325 | on_arg += options[i].num_args + 1; |
|
|
326 | break; |
|
|
327 | } |
|
|
328 | if (options[i].num_args) |
|
|
329 | { |
|
|
330 | if ((on_arg + options[i].num_args) >= argc) |
|
|
331 | { |
|
|
332 | fprintf (stderr, "%s requires an argument.\n", options[i].cmd_option); |
|
|
333 | exit (1); |
|
|
334 | } |
|
|
335 | else |
|
|
336 | { |
|
|
337 | if (options[i].num_args == 1) |
|
|
338 | ((void (*)(char *)) options[i].func) (argv[on_arg + 1]); |
|
|
339 | if (options[i].num_args == 2) |
|
|
340 | ((void (*)(char *, char *)) options[i].func) (argv[on_arg + 1], argv[on_arg + 2]); |
|
|
341 | on_arg += options[i].num_args + 1; |
|
|
342 | } |
|
|
343 | } |
|
|
344 | else |
|
|
345 | { /* takes no args */ |
|
|
346 | options[i].func (); |
|
|
347 | on_arg++; |
|
|
348 | } |
|
|
349 | break; |
|
|
350 | } |
|
|
351 | } |
|
|
352 | if (i == sizeof (options) / sizeof (struct Command_Line_Options)) |
|
|
353 | { |
|
|
354 | fprintf (stderr, "Unknown option: %s\n", argv[on_arg]); |
|
|
355 | usage (); |
|
|
356 | exit (1); |
|
|
357 | } |
|
|
358 | } |
|
|
359 | } |
|
|
360 | |
|
|
361 | //TODO: make this a constructor |
|
|
362 | static materialtype_t * |
|
|
363 | get_empty_mat (void) |
|
|
364 | { |
|
|
365 | materialtype_t *mt; |
|
|
366 | int i; |
|
|
367 | |
|
|
368 | mt = new materialtype_t; |
|
|
369 | |
|
|
370 | mt->name = NULL; |
|
|
371 | mt->description = NULL; |
|
|
372 | for (i = 0; i < NROFATTACKS; i++) |
|
|
373 | { |
|
|
374 | mt->save[i] = 0; |
|
|
375 | mt->mod[i] = 0; |
|
|
376 | } |
|
|
377 | mt->chance = 0; |
|
|
378 | mt->difficulty = 0; |
|
|
379 | mt->magic = 0; |
|
|
380 | mt->damage = 0; |
|
|
381 | mt->wc = 0; |
|
|
382 | mt->ac = 0; |
|
|
383 | mt->sp = 0; |
|
|
384 | mt->weight = 100; |
|
|
385 | mt->value = 100; |
|
|
386 | mt->next = NULL; |
|
|
387 | return mt; |
|
|
388 | } |
|
|
389 | |
|
|
390 | static void |
|
|
391 | load_materials (void) |
|
|
392 | { |
|
|
393 | char buf[MAX_BUF], filename[MAX_BUF], *cp, *next; |
|
|
394 | FILE *fp; |
|
|
395 | materialtype_t *mt; |
|
|
396 | int i, value; |
|
|
397 | |
|
|
398 | sprintf (filename, "%s/materials", settings.datadir); |
|
|
399 | LOG (llevDebug, "Reading material type data from %s...", filename); |
|
|
400 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
401 | { |
|
|
402 | LOG (llevError, "Cannot open %s for reading\n", filename); |
|
|
403 | mt = get_empty_mat (); |
|
|
404 | mt->next = NULL; |
|
|
405 | materialt = mt; |
|
|
406 | return; |
|
|
407 | } |
|
|
408 | mt = get_empty_mat (); |
|
|
409 | materialt = mt; |
|
|
410 | while (fgets (buf, MAX_BUF, fp) != NULL) |
|
|
411 | { |
|
|
412 | if (*buf == '#') |
|
|
413 | continue; |
|
|
414 | if ((cp = strchr (buf, '\n')) != NULL) |
|
|
415 | *cp = '\0'; |
|
|
416 | cp = buf; |
|
|
417 | while (*cp == ' ') /* Skip blanks */ |
|
|
418 | cp++; |
|
|
419 | if (!strncmp (cp, "name", 4)) |
|
|
420 | { |
|
|
421 | /* clean up the previous entry */ |
|
|
422 | if (mt->next != NULL) |
|
|
423 | { |
|
|
424 | if (mt->description == NULL) |
|
|
425 | mt->description = mt->name; |
|
|
426 | mt = mt->next; |
|
|
427 | } |
|
|
428 | mt->next = get_empty_mat (); |
|
|
429 | mt->name = strchr (cp, ' ') + 1; |
|
|
430 | } |
|
|
431 | else if (!strncmp (cp, "description", 11)) |
|
|
432 | { |
|
|
433 | mt->description = strchr (cp, ' ') + 1; |
|
|
434 | } |
|
|
435 | else if (sscanf (cp, "material %d", &value)) |
|
|
436 | { |
|
|
437 | mt->material = value; |
|
|
438 | } |
|
|
439 | else if (!strncmp (cp, "saves", 5)) |
|
|
440 | { |
|
|
441 | cp = strchr (cp, ' ') + 1; |
|
|
442 | for (i = 0; i < NROFATTACKS; i++) |
|
|
443 | { |
|
|
444 | if (cp == NULL) |
|
|
445 | { |
|
|
446 | mt->save[i] = 0; |
|
|
447 | continue; |
|
|
448 | } |
|
|
449 | if ((next = strchr (cp, ',')) != NULL) |
|
|
450 | *(next++) = '\0'; |
|
|
451 | sscanf (cp, "%d", &value); |
|
|
452 | mt->save[i] = (sint8) value; |
|
|
453 | cp = next; |
|
|
454 | } |
|
|
455 | } |
|
|
456 | else if (!strncmp (cp, "mods", 4)) |
|
|
457 | { |
|
|
458 | cp = strchr (cp, ' ') + 1; |
|
|
459 | for (i = 0; i < NROFATTACKS; i++) |
|
|
460 | { |
|
|
461 | if (cp == NULL) |
|
|
462 | { |
|
|
463 | mt->save[i] = 0; |
|
|
464 | continue; |
|
|
465 | } |
|
|
466 | if ((next = strchr (cp, ',')) != NULL) |
|
|
467 | *(next++) = '\0'; |
|
|
468 | sscanf (cp, "%d", &value); |
|
|
469 | mt->mod[i] = (sint8) value; |
|
|
470 | cp = next; |
|
|
471 | } |
|
|
472 | } |
|
|
473 | else if (sscanf (cp, "chance %d\n", &value)) |
|
|
474 | { |
|
|
475 | mt->chance = (sint8) value; |
|
|
476 | } |
|
|
477 | else if (sscanf (cp, "diff %d\n", &value)) |
|
|
478 | { |
|
|
479 | mt->difficulty = (sint8) value; |
|
|
480 | } |
|
|
481 | else if (sscanf (cp, "magic %d\n", &value)) |
|
|
482 | { |
|
|
483 | mt->magic = (sint8) value; |
|
|
484 | } |
|
|
485 | else if (sscanf (cp, "damage %d\n", &value)) |
|
|
486 | { |
|
|
487 | mt->damage = (sint8) value; |
|
|
488 | } |
|
|
489 | else if (sscanf (cp, "wc %d\n", &value)) |
|
|
490 | { |
|
|
491 | mt->wc = (sint8) value; |
|
|
492 | } |
|
|
493 | else if (sscanf (cp, "ac %d\n", &value)) |
|
|
494 | { |
|
|
495 | mt->ac = (sint8) value; |
|
|
496 | } |
|
|
497 | else if (sscanf (cp, "sp %d\n", &value)) |
|
|
498 | { |
|
|
499 | mt->sp = (sint8) value; |
|
|
500 | } |
|
|
501 | else if (sscanf (cp, "weight %d\n", &value)) |
|
|
502 | { |
|
|
503 | mt->weight = value; |
|
|
504 | } |
|
|
505 | else if (sscanf (cp, "value %d\n", &value)) |
|
|
506 | { |
|
|
507 | mt->value = value; |
|
|
508 | } |
|
|
509 | } |
|
|
510 | if (mt->next) |
|
|
511 | { |
|
|
512 | delete mt->next; |
|
|
513 | |
|
|
514 | mt->next = NULL; |
|
|
515 | } |
|
|
516 | LOG (llevDebug, "Done.\n"); |
|
|
517 | fclose (fp); |
|
|
518 | } |
|
|
519 | |
29 | |
520 | /* This loads the settings file. There could be debate whether this should |
30 | /* This loads the settings file. There could be debate whether this should |
521 | * be here or in the common directory - but since only the server needs this |
31 | * be here or in the common directory - but since only the server needs this |
522 | * information, having it here probably makes more sense. |
32 | * information, having it here probably makes more sense. |
523 | */ |
33 | */ |
524 | static void |
34 | void |
525 | load_settings (void) |
35 | load_settings () |
526 | { |
36 | { |
527 | char buf[MAX_BUF], *cp; |
37 | object_thawer thawer (settings.confdir, "settings"); |
528 | int has_val, comp; |
|
|
529 | FILE *fp; |
|
|
530 | |
38 | |
531 | sprintf (buf, "%s/settings", settings.confdir); |
39 | if (!thawer) |
532 | |
|
|
533 | /* We don't require a settings file at current time, but down the road, |
|
|
534 | * there will probably be so many values that not having a settings file |
|
|
535 | * will not be a good thing. |
|
|
536 | */ |
|
|
537 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
|
|
538 | { |
40 | { |
539 | LOG (llevError, "Warning: No settings file found\n"); |
41 | LOG (llevError, "Error: No settings file found\n"); |
540 | return; |
42 | exit (1); |
541 | } |
43 | } |
542 | while (fgets (buf, MAX_BUF - 1, fp) != NULL) |
44 | |
|
|
45 | while (thawer.kw) |
543 | { |
46 | { |
544 | if (buf[0] == '#') |
47 | const char *buf = thawer.kw_str; |
545 | continue; |
48 | const char *cp = thawer.value_nn; |
546 | /* eliminate newline */ |
|
|
547 | if ((cp = strrchr (buf, '\n')) != NULL) |
|
|
548 | *cp = '\0'; |
|
|
549 | |
49 | |
550 | /* Skip over empty lines */ |
50 | if (!strcmp (buf, "not_permadeth")) |
551 | if (buf[0] == 0) |
|
|
552 | continue; |
|
|
553 | |
|
|
554 | /* Skip all the spaces and set them to nulls. If not space, |
|
|
555 | * set cp to "" to make strcpy's and the like easier down below. |
|
|
556 | */ |
|
|
557 | if ((cp = strchr (buf, ' ')) != NULL) |
|
|
558 | { |
|
|
559 | while (*cp == ' ') |
|
|
560 | *cp++ = 0; |
|
|
561 | has_val = 1; |
|
|
562 | } |
51 | { |
563 | else |
|
|
564 | { |
|
|
565 | cp = ""; |
|
|
566 | has_val = 0; |
|
|
567 | } |
|
|
568 | |
|
|
569 | if (!strcasecmp (buf, "metaserver_notification")) |
|
|
570 | { |
|
|
571 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
52 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
572 | { |
|
|
573 | settings.meta_on = TRUE; |
|
|
574 | } |
|
|
575 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
576 | { |
|
|
577 | settings.meta_on = FALSE; |
|
|
578 | } |
|
|
579 | else |
|
|
580 | { |
|
|
581 | LOG (llevError, "load_settings: Unknown value for metaserver_notification: %s\n", cp); |
|
|
582 | } |
|
|
583 | } |
|
|
584 | else if (!strcasecmp (buf, "metaserver_server")) |
|
|
585 | { |
|
|
586 | if (has_val) |
|
|
587 | strcpy (settings.meta_server, cp); |
|
|
588 | else |
|
|
589 | LOG (llevError, "load_settings: metaserver_server must have a value.\n"); |
|
|
590 | } |
|
|
591 | else if (!strcasecmp (buf, "motd")) |
|
|
592 | { |
|
|
593 | if (has_val) |
|
|
594 | strcpy (settings.motd, cp); |
|
|
595 | else |
|
|
596 | LOG (llevError, "load_settings: motd must have a value.\n"); |
|
|
597 | } |
|
|
598 | else if (!strcasecmp (buf, "dm_mail")) |
|
|
599 | { |
|
|
600 | if (has_val) |
|
|
601 | strcpy (settings.dm_mail, cp); |
|
|
602 | else |
|
|
603 | LOG (llevError, "load_settings: dm_mail must have a value.\n"); |
|
|
604 | } |
|
|
605 | else if (!strcasecmp (buf, "metaserver_host")) |
|
|
606 | { |
|
|
607 | if (has_val) |
|
|
608 | strcpy (settings.meta_host, cp); |
|
|
609 | else |
|
|
610 | LOG (llevError, "load_settings: metaserver_host must have a value.\n"); |
|
|
611 | } |
|
|
612 | else if (!strcasecmp (buf, "metaserver_port")) |
|
|
613 | { |
|
|
614 | int port = atoi (cp); |
|
|
615 | |
|
|
616 | if (port < 1 || port > 65535) |
|
|
617 | LOG (llevError, "load_settings: metaserver_port must be between 1 and 65535, %d is invalid\n", port); |
|
|
618 | else |
|
|
619 | settings.meta_port = port; |
|
|
620 | } |
|
|
621 | else if (!strcasecmp (buf, "metaserver_comment")) |
|
|
622 | { |
|
|
623 | strcpy (settings.meta_comment, cp); |
|
|
624 | } |
|
|
625 | else if (!strcasecmp (buf, "worldmapstartx")) |
|
|
626 | { |
|
|
627 | int size = atoi (cp); |
|
|
628 | |
|
|
629 | if (size < 0) |
|
|
630 | LOG (llevError, "load_settings: worldmapstartx must be at least " "0, %d is invalid\n", size); |
|
|
631 | else |
|
|
632 | settings.worldmapstartx = size; |
|
|
633 | } |
|
|
634 | else if (!strcasecmp (buf, "worldmapstarty")) |
|
|
635 | { |
|
|
636 | int size = atoi (cp); |
|
|
637 | |
|
|
638 | if (size < 0) |
|
|
639 | LOG (llevError, "load_settings: worldmapstarty must be at least " "0, %d is invalid\n", size); |
|
|
640 | else |
|
|
641 | settings.worldmapstarty = size; |
|
|
642 | } |
|
|
643 | else if (!strcasecmp (buf, "worldmaptilesx")) |
|
|
644 | { |
|
|
645 | int size = atoi (cp); |
|
|
646 | |
|
|
647 | if (size < 1) |
|
|
648 | LOG (llevError, "load_settings: worldmaptilesx must be greater " "than 1, %d is invalid\n", size); |
|
|
649 | else |
|
|
650 | settings.worldmaptilesx = size; |
|
|
651 | } |
|
|
652 | else if (!strcasecmp (buf, "worldmaptilesy")) |
|
|
653 | { |
|
|
654 | int size = atoi (cp); |
|
|
655 | |
|
|
656 | if (size < 1) |
|
|
657 | LOG (llevError, "load_settings: worldmaptilesy must be greater " "than 1, %d is invalid\n", size); |
|
|
658 | else |
|
|
659 | settings.worldmaptilesy = size; |
|
|
660 | } |
|
|
661 | else if (!strcasecmp (buf, "worldmaptilesizex")) |
|
|
662 | { |
|
|
663 | int size = atoi (cp); |
|
|
664 | |
|
|
665 | if (size < 1) |
|
|
666 | LOG (llevError, "load_settings: worldmaptilesizex must be " "greater than 1, %d is invalid\n", size); |
|
|
667 | else |
|
|
668 | settings.worldmaptilesizex = size; |
|
|
669 | } |
|
|
670 | else if (!strcasecmp (buf, "worldmaptilesizey")) |
|
|
671 | { |
|
|
672 | int size = atoi (cp); |
|
|
673 | |
|
|
674 | if (size < 1) |
|
|
675 | LOG (llevError, "load_settings: worldmaptilesizey must be " "greater than 1, %d is invalid\n", size); |
|
|
676 | else |
|
|
677 | settings.worldmaptilesizey = size; |
|
|
678 | } |
|
|
679 | else if (!strcasecmp (buf, "dynamiclevel")) |
|
|
680 | { |
|
|
681 | int lev = atoi (cp); |
|
|
682 | |
|
|
683 | if (lev < 0) |
|
|
684 | LOG (llevError, "load_settings: dynamiclevel must be " "at least 0, %d is invalid\n", lev); |
|
|
685 | else |
|
|
686 | settings.dynamiclevel = lev; |
|
|
687 | } |
|
|
688 | else if (!strcasecmp (buf, "fastclock")) |
|
|
689 | { |
|
|
690 | int lev = atoi (cp); |
|
|
691 | |
|
|
692 | if (lev < 0) |
|
|
693 | LOG (llevError, "load_settings: fastclock must be at least 0" ", %d is invalid\n", lev); |
|
|
694 | else |
|
|
695 | settings.fastclock = lev; |
|
|
696 | } |
|
|
697 | else if (!strcasecmp (buf, "not_permadeth")) |
|
|
698 | { |
|
|
699 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
700 | { |
53 | { |
701 | settings.not_permadeth = TRUE; |
54 | settings.not_permadeth = TRUE; |
702 | } |
55 | } |
703 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
56 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
704 | { |
57 | { |
705 | settings.not_permadeth = FALSE; |
58 | settings.not_permadeth = FALSE; |
706 | } |
59 | } |
707 | else |
60 | else |
708 | { |
61 | { |
709 | LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp); |
62 | LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp); |
710 | } |
63 | } |
711 | } |
64 | } |
712 | else if (!strcasecmp (buf, "resurrection")) |
65 | else if (!strcmp (buf, "resurrection")) |
713 | { |
66 | { |
714 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
67 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
715 | { |
68 | { |
716 | settings.resurrection = TRUE; |
69 | settings.resurrection = TRUE; |
717 | } |
70 | } |
718 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
71 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
719 | { |
72 | { |
720 | settings.resurrection = FALSE; |
73 | settings.resurrection = FALSE; |
721 | } |
74 | } |
722 | else |
75 | else |
723 | { |
76 | { |
724 | LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp); |
77 | LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp); |
725 | } |
78 | } |
726 | } |
79 | } |
727 | else if (!strcasecmp (buf, "set_title")) |
80 | else if (!strcmp (buf, "set_title")) |
728 | { |
81 | { |
729 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
82 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
730 | { |
83 | { |
731 | settings.set_title = TRUE; |
84 | settings.set_title = TRUE; |
732 | } |
85 | } |
733 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
86 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
734 | { |
87 | { |
735 | settings.set_title = FALSE; |
88 | settings.set_title = FALSE; |
736 | } |
89 | } |
737 | else |
90 | else |
738 | { |
91 | { |
739 | LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp); |
92 | LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp); |
740 | } |
93 | } |
741 | } |
94 | } |
742 | else if (!strcasecmp (buf, "search_items")) |
95 | else if (!strcmp (buf, "search_items")) |
743 | { |
96 | { |
744 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
97 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
745 | { |
98 | { |
746 | settings.search_items = TRUE; |
99 | settings.search_items = TRUE; |
747 | } |
100 | } |
748 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
101 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
749 | { |
102 | { |
750 | settings.search_items = FALSE; |
103 | settings.search_items = FALSE; |
751 | } |
104 | } |
752 | else |
105 | else |
753 | { |
106 | { |
754 | LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp); |
107 | LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp); |
755 | } |
108 | } |
756 | } |
109 | } |
757 | else if (!strcasecmp (buf, "spell_encumbrance")) |
110 | else if (!strcmp (buf, "spell_encumbrance")) |
758 | { |
111 | { |
759 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
112 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
760 | { |
113 | { |
761 | settings.spell_encumbrance = TRUE; |
114 | settings.spell_encumbrance = TRUE; |
762 | } |
115 | } |
763 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
116 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
764 | { |
117 | { |
765 | settings.spell_encumbrance = FALSE; |
118 | settings.spell_encumbrance = FALSE; |
766 | } |
119 | } |
767 | else |
120 | else |
768 | { |
121 | { |
769 | LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp); |
122 | LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp); |
770 | } |
123 | } |
771 | } |
124 | } |
772 | else if (!strcasecmp (buf, "spell_failure_effects")) |
125 | else if (!strcmp (buf, "spell_failure_effects")) |
773 | { |
126 | { |
774 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
127 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
775 | { |
128 | { |
776 | settings.spell_failure_effects = TRUE; |
129 | settings.spell_failure_effects = TRUE; |
777 | } |
130 | } |
778 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
131 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
779 | { |
132 | { |
780 | settings.spell_failure_effects = FALSE; |
133 | settings.spell_failure_effects = FALSE; |
781 | } |
134 | } |
782 | else |
135 | else |
783 | { |
136 | { |
784 | LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp); |
137 | LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp); |
785 | } |
138 | } |
786 | } |
139 | } |
787 | else if (!strcasecmp (buf, "casting_time")) |
|
|
788 | { |
|
|
789 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
790 | { |
|
|
791 | settings.casting_time = TRUE; |
|
|
792 | } |
|
|
793 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
794 | { |
|
|
795 | settings.casting_time = FALSE; |
|
|
796 | } |
|
|
797 | else |
|
|
798 | { |
|
|
799 | LOG (llevError, "load_settings: Unknown value for " "casting_time: %s\n", cp); |
|
|
800 | } |
|
|
801 | } |
|
|
802 | else if (!strcasecmp (buf, "real_wiz")) |
|
|
803 | { |
|
|
804 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
805 | { |
|
|
806 | settings.real_wiz = TRUE; |
|
|
807 | } |
|
|
808 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
809 | { |
|
|
810 | settings.real_wiz = FALSE; |
|
|
811 | } |
|
|
812 | else |
|
|
813 | { |
|
|
814 | LOG (llevError, "load_settings: Unknown value for " "real_wiz: %s\n", cp); |
|
|
815 | } |
|
|
816 | } |
|
|
817 | else if (!strcasecmp (buf, "recycle_tmp_maps")) |
|
|
818 | { |
|
|
819 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
820 | { |
|
|
821 | settings.recycle_tmp_maps = TRUE; |
|
|
822 | } |
|
|
823 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
824 | { |
|
|
825 | settings.recycle_tmp_maps = FALSE; |
|
|
826 | } |
|
|
827 | else |
|
|
828 | { |
|
|
829 | LOG (llevError, "load_settings: Unknown value for " "recycle_tmp_maps: %s\n", cp); |
|
|
830 | } |
|
|
831 | } |
|
|
832 | else if (!strcasecmp (buf, "explore_mode")) |
|
|
833 | { |
|
|
834 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
835 | { |
|
|
836 | settings.explore_mode = TRUE; |
|
|
837 | } |
|
|
838 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
839 | { |
|
|
840 | settings.explore_mode = FALSE; |
|
|
841 | } |
|
|
842 | else |
|
|
843 | { |
|
|
844 | LOG (llevError, "load_settings: Unknown value for " "explore_mode: %s\n", cp); |
|
|
845 | } |
|
|
846 | } |
|
|
847 | else if (!strcasecmp (buf, "who_format")) |
|
|
848 | { |
|
|
849 | if (has_val) |
|
|
850 | strcpy (settings.who_format, cp); |
|
|
851 | } |
|
|
852 | else if (!strcasecmp (buf, "who_wiz_format")) |
|
|
853 | { |
|
|
854 | if (has_val) |
|
|
855 | strcpy (settings.who_wiz_format, cp); |
|
|
856 | } |
|
|
857 | else if (!strcasecmp (buf, "spellpoint_level_depend")) |
140 | else if (!strcmp (buf, "spellpoint_level_depend")) |
858 | { |
141 | { |
859 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
142 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
860 | { |
143 | { |
861 | settings.spellpoint_level_depend = TRUE; |
144 | settings.spellpoint_level_depend = TRUE; |
862 | } |
145 | } |
863 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
146 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
864 | { |
147 | { |
865 | settings.spellpoint_level_depend = FALSE; |
148 | settings.spellpoint_level_depend = FALSE; |
866 | } |
149 | } |
867 | else |
150 | else |
868 | { |
151 | { |
869 | LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp); |
152 | LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp); |
870 | } |
153 | } |
871 | } |
154 | } |
872 | else if (!strcasecmp (buf, "stat_loss_on_death")) |
155 | else if (!strcmp (buf, "stat_loss_on_death")) |
873 | { |
156 | { |
874 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
157 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
875 | { |
158 | { |
876 | settings.stat_loss_on_death = TRUE; |
159 | settings.stat_loss_on_death = TRUE; |
877 | } |
160 | } |
878 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
161 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
879 | { |
162 | { |
880 | settings.stat_loss_on_death = FALSE; |
163 | settings.stat_loss_on_death = FALSE; |
881 | } |
164 | } |
882 | else |
165 | else |
883 | { |
166 | { |
884 | LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp); |
167 | LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp); |
885 | } |
168 | } |
886 | } |
169 | } |
887 | else if (!strcasecmp (buf, "use_permanent_experience")) |
170 | else if (!strcmp (buf, "use_permanent_experience")) |
888 | { |
171 | { |
889 | LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n"); |
172 | LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n"); |
890 | } |
173 | } |
891 | else if (!strcasecmp (buf, "permanent_experience_percentage")) |
174 | else if (!strcmp (buf, "permanent_experience_percentage")) |
892 | { |
175 | { |
893 | int val = atoi (cp); |
176 | int val = atoi (cp); |
894 | |
177 | |
895 | if (val < 0 || val > 100) |
178 | if (val < 0 || val > 100) |
896 | LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val); |
179 | LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val); |
897 | else |
180 | else |
898 | settings.permanent_exp_ratio = val; |
181 | settings.permanent_exp_ratio = val; |
899 | } |
182 | } |
900 | else if (!strcasecmp (buf, "death_penalty_percentage")) |
183 | else if (!strcmp (buf, "death_penalty_percentage")) |
901 | { |
184 | { |
902 | int val = atoi (cp); |
185 | int val = atoi (cp); |
903 | |
186 | |
904 | if (val < 0 || val > 100) |
187 | if (val < 0 || val > 100) |
905 | LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val); |
188 | LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val); |
906 | else |
189 | else |
907 | settings.death_penalty_ratio = val; |
190 | settings.death_penalty_ratio = val; |
908 | } |
191 | } |
909 | else if (!strcasecmp (buf, "death_penalty_levels")) |
192 | else if (!strcmp (buf, "death_penalty_levels")) |
910 | { |
193 | { |
911 | int val = atoi (cp); |
194 | int val = atoi (cp); |
912 | |
195 | |
913 | if (val < 0 || val > 255) |
196 | if (val < 0 || val > 255) |
914 | LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val); |
197 | LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val); |
915 | else |
198 | else |
916 | settings.death_penalty_level = val; |
199 | settings.death_penalty_level = val; |
917 | } |
200 | } |
918 | else if (!strcasecmp (buf, "balanced_stat_loss")) |
201 | else if (!strcmp (buf, "balanced_stat_loss")) |
919 | { |
202 | { |
920 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
203 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
921 | { |
204 | { |
922 | settings.balanced_stat_loss = TRUE; |
205 | settings.balanced_stat_loss = TRUE; |
923 | } |
206 | } |
924 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
207 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
925 | { |
208 | { |
926 | settings.balanced_stat_loss = FALSE; |
209 | settings.balanced_stat_loss = FALSE; |
927 | } |
210 | } |
928 | else |
211 | else |
929 | { |
212 | { |
930 | LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp); |
213 | LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp); |
931 | } |
214 | } |
932 | } |
215 | } |
933 | else if (!strcasecmp (buf, "simple_exp")) |
216 | else if (!strcmp (buf, "simple_exp")) |
934 | { |
217 | { |
935 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
218 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
936 | { |
219 | { |
937 | settings.simple_exp = TRUE; |
220 | settings.simple_exp = TRUE; |
938 | } |
221 | } |
939 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
222 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
940 | { |
223 | { |
941 | settings.simple_exp = FALSE; |
224 | settings.simple_exp = FALSE; |
942 | } |
225 | } |
943 | else |
226 | else |
944 | { |
227 | { |
945 | LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp); |
228 | LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp); |
946 | } |
229 | } |
947 | } |
230 | } |
948 | else if (!strcasecmp (buf, "item_power_factor")) |
231 | else if (!strcmp (buf, "item_power_factor")) |
949 | { |
232 | { |
950 | float tmp = atof (cp); |
233 | float tmp = atof (cp); |
951 | |
234 | |
952 | if (tmp < 0) |
235 | if (tmp < 0) |
953 | LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp); |
236 | LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp); |
954 | else |
237 | else |
955 | settings.item_power_factor = tmp; |
238 | settings.item_power_factor = tmp; |
956 | } |
239 | } |
957 | else if (!strcasecmp (buf, "pk_luck_penalty")) |
240 | else if (!strcmp (buf, "pk_luck_penalty")) |
958 | { |
241 | { |
959 | sint16 val = atoi (cp); |
242 | sint16 val = atoi (cp); |
960 | |
243 | |
961 | if (val < -100 || val > 100) |
244 | if (val < -100 || val > 100) |
962 | LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val); |
245 | LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val); |
963 | else |
246 | else |
964 | settings.pk_luck_penalty = val; |
247 | settings.pk_luck_penalty = val; |
965 | } |
248 | } |
966 | else if (!strcasecmp (buf, "set_friendly_fire")) |
249 | else if (!strcmp (buf, "set_friendly_fire")) |
967 | { |
250 | { |
968 | int val = atoi (cp); |
251 | int val = atoi (cp); |
969 | |
252 | |
970 | #if COZY_SERVER |
|
|
971 | if (val < 0 || val > 100) |
253 | if (val < 0 || val > 100) |
972 | LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val); |
254 | LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val); |
973 | #else |
|
|
974 | if (val < 1 || val > 100) |
|
|
975 | LOG (llevError, "load_settings: set_friendly_fire must be between 1 an 100" ", %d is invalid\n", val); |
|
|
976 | #endif |
|
|
977 | else |
255 | else |
978 | settings.set_friendly_fire = val; |
256 | settings.set_friendly_fire = val; |
979 | } |
257 | } |
980 | else if (!strcasecmp (buf, "armor_max_enchant")) |
258 | else if (!strcmp (buf, "armor_max_enchant")) |
981 | { |
259 | { |
982 | int max_e = atoi (cp); |
260 | int max_e = atoi (cp); |
983 | |
261 | |
984 | if (max_e <= 0) |
262 | if (max_e <= 0) |
985 | LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e); |
263 | LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e); |
986 | else |
264 | else |
987 | settings.armor_max_enchant = max_e; |
265 | settings.armor_max_enchant = max_e; |
988 | } |
266 | } |
989 | else if (!strcasecmp (buf, "armor_weight_reduction")) |
267 | else if (!strcmp (buf, "armor_weight_reduction")) |
990 | { |
268 | { |
991 | int wr = atoi (cp); |
269 | int wr = atoi (cp); |
992 | |
270 | |
993 | if (wr < 0) |
271 | if (wr < 0) |
994 | LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr); |
272 | LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr); |
995 | else |
273 | else |
996 | settings.armor_weight_reduction = wr; |
274 | settings.armor_weight_reduction = wr; |
997 | } |
275 | } |
998 | else if (!strcasecmp (buf, "armor_weight_linear")) |
276 | else if (!strcmp (buf, "armor_weight_linear")) |
999 | { |
277 | { |
1000 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
278 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
1001 | { |
279 | { |
1002 | settings.armor_weight_linear = TRUE; |
280 | settings.armor_weight_linear = TRUE; |
1003 | } |
281 | } |
1004 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
282 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
1005 | { |
283 | { |
1006 | settings.armor_weight_linear = FALSE; |
284 | settings.armor_weight_linear = FALSE; |
1007 | } |
285 | } |
1008 | else |
286 | else |
1009 | { |
287 | { |
1010 | LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); |
288 | LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); |
1011 | } |
289 | } |
1012 | |
290 | |
1013 | } |
291 | } |
1014 | else if (!strcasecmp (buf, "armor_speed_improvement")) |
292 | else if (!strcmp (buf, "armor_speed_improvement")) |
1015 | { |
293 | { |
1016 | int wr = atoi (cp); |
294 | int wr = atoi (cp); |
1017 | |
295 | |
1018 | if (wr < 0) |
296 | if (wr < 0) |
1019 | LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr); |
297 | LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr); |
1020 | else |
298 | else |
1021 | settings.armor_speed_improvement = wr; |
299 | settings.armor_speed_improvement = wr; |
1022 | } |
300 | } |
1023 | else if (!strcasecmp (buf, "armor_speed_linear")) |
301 | else if (!strcmp (buf, "armor_speed_linear")) |
1024 | { |
302 | { |
1025 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
303 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
1026 | { |
304 | { |
1027 | settings.armor_speed_linear = TRUE; |
305 | settings.armor_speed_linear = TRUE; |
1028 | } |
306 | } |
1029 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
307 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
1030 | { |
308 | { |
1031 | settings.armor_speed_linear = FALSE; |
309 | settings.armor_speed_linear = FALSE; |
1032 | } |
310 | } |
1033 | else |
311 | else |
1034 | { |
312 | { |
1035 | LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); |
313 | LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); |
1036 | } |
314 | } |
1037 | |
315 | |
1038 | } |
316 | } |
1039 | else if (!strcasecmp (buf, "no_player_stealing")) |
|
|
1040 | { |
|
|
1041 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
1042 | { |
|
|
1043 | settings.no_player_stealing = TRUE; |
|
|
1044 | } |
|
|
1045 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
1046 | { |
|
|
1047 | settings.no_player_stealing = FALSE; |
|
|
1048 | } |
|
|
1049 | else |
|
|
1050 | { |
|
|
1051 | LOG (llevError, "load_settings: unknown value for no_player_stealing: %s\n", cp); |
|
|
1052 | } |
|
|
1053 | |
|
|
1054 | } |
|
|
1055 | else if (!strcasecmp (buf, "create_home_portals")) |
|
|
1056 | { |
|
|
1057 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
1058 | { |
|
|
1059 | settings.create_home_portals = TRUE; |
|
|
1060 | } |
|
|
1061 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
1062 | { |
|
|
1063 | settings.create_home_portals = FALSE; |
|
|
1064 | } |
|
|
1065 | else |
|
|
1066 | { |
|
|
1067 | LOG (llevError, "load_settings: Unknown value for create_home_portals: %s\n", cp); |
|
|
1068 | } |
|
|
1069 | |
|
|
1070 | } |
|
|
1071 | else |
317 | else |
1072 | { |
318 | thawer.parse_error ("settings file"); |
1073 | LOG (llevError, "Unknown value in settings file: %s\n", buf); |
319 | |
1074 | } |
320 | thawer.next (); |
1075 | } |
321 | } |
1076 | close_and_delete (fp, comp); |
|
|
1077 | } |
322 | } |
1078 | |
|
|
1079 | |
323 | |
1080 | /* |
324 | /* |
1081 | * init() is called only once, when starting the program. |
325 | * init() is called only once, when starting the program. |
1082 | */ |
326 | */ |
1083 | |
|
|
1084 | void |
327 | void |
1085 | init (int argc, char **argv) |
328 | init (int argc, char **argv) |
1086 | { |
329 | { |
1087 | init_done = 0; /* Must be done before init_signal() */ |
330 | init_done = 0; /* Must be done before init_signal() */ |
1088 | logfile = stderr; |
|
|
1089 | parse_args (argc, argv, 1); /* First arg pass - right now it does |
|
|
1090 | * nothing, but in future specifying the |
|
|
1091 | * LibDir in this pass would be reasonable*/ |
|
|
1092 | |
331 | |
1093 | init_library (); /* Must be called early */ |
332 | init_environ (); |
1094 | load_settings (); /* Load the settings file */ |
333 | cfperl_init (); |
1095 | init_weather (); |
334 | init_done = 1; |
1096 | load_materials (); |
335 | } |
1097 | parse_args (argc, argv, 2); |
|
|
1098 | fprintf (logfile, "Welcome to CrossFire, v%s\n", VERSION); |
|
|
1099 | fprintf (logfile, "Copyright (C) 1994 Mark Wedel.\n"); |
|
|
1100 | fprintf (logfile, "Copyright (C) 1992 Frank Tore Johansen.\n"); |
|
|
1101 | |
336 | |
1102 | if (strcmp (settings.dm_mail, "") != 0) |
337 | /* Signal handlers: */ |
1103 | { |
|
|
1104 | fprintf (logfile, "Maintained locally by: %s\n", settings.dm_mail); |
|
|
1105 | fprintf (logfile, "Questions and bugs should be mailed to above address.\n"); |
|
|
1106 | } |
|
|
1107 | |
338 | |
1108 | SRANDOM (time (NULL)); |
339 | static void |
|
|
340 | rec_sigabrt (int i) |
|
|
341 | { |
|
|
342 | signal (SIGABRT, SIG_DFL); |
1109 | |
343 | |
1110 | init_startup (); /* Write (C), check shutdown/forbid files */ |
344 | LOG (llevError, "SIGABRT received.\n"); |
1111 | init_uuid (); |
345 | cleanup ("SIGABRT received", 1); |
1112 | init_signals (); /* Sets up signal interceptions */ |
346 | } |
1113 | init_commands (); /* Sort command tables */ |
|
|
1114 | read_map_log (); /* Load up the old temp map files */ |
|
|
1115 | init_skills (); |
|
|
1116 | |
347 | |
1117 | parse_args (argc, argv, 3); |
348 | static void |
|
|
349 | rec_sigquit (int i) |
|
|
350 | { |
|
|
351 | signal (SIGQUIT, SIG_IGN); |
1118 | |
352 | |
1119 | #ifndef WIN32 /* ***win32: no BecomeDaemon in windows */ |
353 | LOG (llevInfo, "SIGQUIT received\n"); |
1120 | if (settings.daemonmode) |
354 | cleanup ("SIGQUIT received", 1); |
1121 | logfile = BecomeDaemon (settings.logfilename[0] == '\0' ? "logfile" : settings.logfilename); |
355 | } |
|
|
356 | |
|
|
357 | static void |
|
|
358 | rec_sigsegv (int i) |
|
|
359 | { |
|
|
360 | signal (SIGSEGV, SIG_DFL); |
|
|
361 | |
|
|
362 | LOG (llevError, "SIGSEGV received.\n"); |
|
|
363 | cleanup ("SIGSEGV received", 1); |
|
|
364 | } |
|
|
365 | |
|
|
366 | static void |
|
|
367 | rec_sigbus (int i) |
|
|
368 | { |
|
|
369 | signal (SIGBUS, SIG_DFL); |
|
|
370 | |
|
|
371 | LOG (llevError, "SIGBUS received\n"); |
|
|
372 | cleanup ("SIGBUS received", 1); |
|
|
373 | } |
|
|
374 | |
|
|
375 | static void |
|
|
376 | rec_sigfpe (int i) |
|
|
377 | { |
|
|
378 | signal (SIGFPE, SIG_DFL); |
|
|
379 | |
|
|
380 | LOG (llevError, "SIGFPE received.\n"); |
|
|
381 | cleanup ("SIGFPE received", 1); |
|
|
382 | } |
|
|
383 | |
|
|
384 | void |
|
|
385 | reset_signals () |
|
|
386 | { |
|
|
387 | signal (SIGABRT, SIG_DFL); |
|
|
388 | signal (SIGQUIT, SIG_DFL); |
|
|
389 | signal (SIGSEGV, SIG_DFL); |
|
|
390 | #ifdef SIGBUS |
|
|
391 | signal (SIGBUS , SIG_DFL); |
1122 | #endif |
392 | #endif |
1123 | |
393 | signal (SIGFPE , SIG_DFL); |
1124 | init_beforeplay (); |
394 | signal (SIGINT , SIG_DFL); |
1125 | init_ericserver (); |
395 | signal (SIGTERM, SIG_DFL); |
1126 | metaserver_init (); |
|
|
1127 | init_done = 1; |
|
|
1128 | } |
396 | } |
1129 | |
397 | |
1130 | void |
398 | void |
1131 | usage (void) |
399 | init_signals () |
1132 | { |
400 | { |
1133 | (void) fprintf (logfile, "Usage: crossfire [-h] [-<flags>]...\n"); |
401 | // large stack, but it's important data we want to save, and it is not usually |
1134 | } |
402 | // being physically allocated anyways |
|
|
403 | const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ; |
1135 | |
404 | |
1136 | void |
405 | stack_t ss; |
1137 | help (void) |
406 | ss.ss_sp = malloc (stacksize); |
1138 | { |
407 | ss.ss_flags = 0; |
|
|
408 | ss.ss_size = stacksize; |
|
|
409 | sigaltstack (&ss, 0); |
1139 | |
410 | |
1140 | /* The information in usage is redundant with what is given below, so why call it? */ |
411 | struct sigaction sa; |
1141 | |
412 | |
1142 | /* usage();*/ |
413 | sigfillset (&sa.sa_mask); |
1143 | printf ("Flags:\n"); |
414 | sa.sa_flags = SA_RESTART; |
1144 | printf (" -csport <port> Specifies the port to use for the new client/server code.\n"); |
|
|
1145 | printf (" -d Turns on some debugging.\n"); |
|
|
1146 | printf (" +d Turns off debugging (useful if server compiled with debugging\n"); |
|
|
1147 | printf (" as default).\n"); |
|
|
1148 | printf (" -detach The server will go in the background, closing all\n"); |
|
|
1149 | printf (" connections to the tty.\n"); |
|
|
1150 | printf (" -h Display this information.\n"); |
|
|
1151 | printf (" -log <file> Specifies which file to send output to.\n"); |
|
|
1152 | printf (" Only has meaning if -detach is specified.\n"); |
|
|
1153 | printf (" -mon Turns on monster debugging.\n"); |
|
|
1154 | printf (" -o Prints out info on what was defined at compile time.\n"); |
|
|
1155 | printf (" -s Display the high-score list.\n"); |
|
|
1156 | printf (" -score <name or class> Displays all high scores with matching name/class.\n"); |
|
|
1157 | printf (" -v Print version and contributors.\n"); |
|
|
1158 | printf (" -data Sets the lib dir (archetypes, treasures, etc.)\n"); |
|
|
1159 | printf (" -local Read/write local data (hiscore, unique items, etc.)\n"); |
|
|
1160 | printf (" -maps Sets the directory for maps.\n"); |
|
|
1161 | printf (" -arch Sets the archetype file to use.\n"); |
|
|
1162 | printf (" -regions Sets the regions file to use.\n"); |
|
|
1163 | printf (" -playerdir Sets the directory for the player files.\n"); |
|
|
1164 | printf (" -templatedir Sets the directory for template generate maps.\n"); |
|
|
1165 | printf (" -treasures Sets the treasures file to use.\n"); |
|
|
1166 | printf (" -uniquedir Sets the unique items/maps directory.\n"); |
|
|
1167 | printf (" -tmpdir Sets the directory for temporary files (mostly maps.)\n"); |
|
|
1168 | printf (" -m Lists out suggested experience for all monsters.\n"); |
|
|
1169 | printf (" -m2 Dumps out abilities.\n"); |
|
|
1170 | printf (" -m3 Dumps out artifact information.\n"); |
|
|
1171 | printf (" -m4 Dumps out spell information.\n"); |
|
|
1172 | printf (" -m5 Dumps out skill information.\n"); |
|
|
1173 | printf (" -m6 Dumps out race information.\n"); |
|
|
1174 | printf (" -m7 Dumps out alchemy information.\n"); |
|
|
1175 | printf (" -m8 Dumps out gods information.\n"); |
|
|
1176 | printf (" -m9 Dumps out more alchemy information (formula checking).\n"); |
|
|
1177 | printf (" -mt <name> Dumps out list of treasures for a monster.\n"); |
|
|
1178 | exit (0); |
|
|
1179 | } |
|
|
1180 | |
415 | |
1181 | void |
416 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
1182 | init_beforeplay (void) |
417 | sa.sa_handler = rec_sigabrt; sigaction (SIGABRT, &sa, 0); |
1183 | { |
418 | sa.sa_handler = rec_sigquit; sigaction (SIGQUIT, &sa, 0); |
1184 | init_archetypes (); /* If not called before, reads all archetypes from file */ |
419 | #ifdef SIGBUS |
1185 | init_artifacts (); /* If not called before, reads all artifacts from file */ |
420 | sa.sa_handler = rec_sigbus; sigaction (SIGBUS, &sa, 0); |
1186 | init_spells (); /* If not called before, links archtypes used by spells */ |
|
|
1187 | init_regions (); /* If not called before, reads all regions from file */ |
|
|
1188 | init_archetype_pointers (); /* Setup global pointers to archetypes */ |
|
|
1189 | init_races (); /* overwrite race designations using entries in lib/races file */ |
|
|
1190 | init_gods (); /* init linked list of gods from archs */ |
|
|
1191 | init_readable (); /* inits useful arrays for readable texts */ |
|
|
1192 | init_formulae (); /* If not called before, reads formulae from file */ |
|
|
1193 | |
|
|
1194 | switch (settings.dumpvalues) |
|
|
1195 | { |
|
|
1196 | case 1: |
|
|
1197 | print_monsters (); |
|
|
1198 | exit (0); |
|
|
1199 | case 2: |
|
|
1200 | dump_abilities (); |
|
|
1201 | exit (0); |
|
|
1202 | case 3: |
|
|
1203 | dump_artifacts (); |
|
|
1204 | exit (0); |
|
|
1205 | case 4: |
|
|
1206 | dump_spells (); |
|
|
1207 | exit (0); |
|
|
1208 | case 5: |
|
|
1209 | exit (0); |
|
|
1210 | case 6: |
|
|
1211 | dump_races (); |
|
|
1212 | exit (0); |
|
|
1213 | case 7: |
|
|
1214 | dump_alchemy (); |
|
|
1215 | exit (0); |
|
|
1216 | case 9: |
|
|
1217 | dump_alchemy_costs (); |
|
|
1218 | exit (0); |
|
|
1219 | case 10: |
|
|
1220 | dump_monster_treasure (settings.dumparg); |
|
|
1221 | exit (0); |
|
|
1222 | } |
|
|
1223 | } |
|
|
1224 | |
|
|
1225 | void |
|
|
1226 | init_startup (void) |
|
|
1227 | { |
|
|
1228 | char buf[MAX_BUF]; |
|
|
1229 | FILE *fp; |
|
|
1230 | int comp; |
|
|
1231 | |
|
|
1232 | #ifdef SHUTDOWN_FILE |
|
|
1233 | sprintf (buf, "%s/%s", settings.confdir, SHUTDOWN_FILE); |
|
|
1234 | if ((fp = open_and_uncompress (buf, 0, &comp)) != NULL) |
|
|
1235 | { |
|
|
1236 | while (fgets (buf, MAX_BUF - 1, fp) != NULL) |
|
|
1237 | printf ("%s", buf); |
|
|
1238 | close_and_delete (fp, comp); |
|
|
1239 | exit (1); |
|
|
1240 | } |
|
|
1241 | #endif |
421 | #endif |
|
|
422 | sa.sa_handler = rec_sigfpe; sigaction (SIGFPE, &sa, 0); |
1242 | |
423 | |
1243 | if (forbid_play ()) |
424 | sa.sa_flags |= SA_ONSTACK; |
1244 | { /* Maybe showing highscore should be allowed? */ |
425 | sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0); |
1245 | LOG (llevError, "CrossFire: Playing not allowed.\n"); |
|
|
1246 | exit (-1); |
|
|
1247 | } |
|
|
1248 | } |
426 | } |
1249 | |
427 | |
1250 | /* |
428 | static racelink * |
1251 | * compile_info(): activated with the -o flag. |
429 | get_racelist () |
1252 | * It writes out information on how Imakefile and config.h was configured |
|
|
1253 | * at compile time. |
|
|
1254 | */ |
|
|
1255 | |
|
|
1256 | void |
|
|
1257 | compile_info (void) |
|
|
1258 | { |
430 | { |
1259 | int i = 0; |
431 | racelink *list = new racelink; |
1260 | |
432 | |
1261 | printf ("Non-standard include files:\n"); |
433 | list->name = 0; |
1262 | #if !defined (__STRICT_ANSI__) || defined (__sun__) |
434 | list->nrof = 0; |
1263 | # if !defined (Mips) |
435 | list->next = 0; |
1264 | printf ("<stdlib.h>\n"); |
436 | list->member = get_objectlink (); |
1265 | i = 1; |
|
|
1266 | # endif |
|
|
1267 | # if !defined (MACH) && !defined (sony) |
|
|
1268 | printf ("<malloc.h>\n"); |
|
|
1269 | i = 1; |
|
|
1270 | # endif |
|
|
1271 | #endif |
|
|
1272 | #ifndef __STRICT_ANSI__ |
|
|
1273 | # ifndef MACH |
|
|
1274 | printf ("<memory.h\n"); |
|
|
1275 | i = 1; |
|
|
1276 | # endif |
|
|
1277 | #endif |
|
|
1278 | #ifndef sgi |
|
|
1279 | printf ("<sys/timeb.h>\n"); |
|
|
1280 | i = 1; |
|
|
1281 | #endif |
|
|
1282 | if (!i) |
|
|
1283 | printf ("(none)\n"); |
|
|
1284 | printf ("Datadir:\t\t%s\n", settings.datadir); |
|
|
1285 | printf ("Localdir:\t\t%s\n", settings.localdir); |
|
|
1286 | #ifdef PERM_FILE |
|
|
1287 | printf ("Perm file:\t<ETC>/%s\n", PERM_FILE); |
|
|
1288 | #endif |
|
|
1289 | #ifdef SHUTDOWN_FILE |
|
|
1290 | printf ("Shutdown file:\t<ETC>/%s\n", SHUTDOWN_FILE); |
|
|
1291 | #endif |
|
|
1292 | printf ("Save player:\t<true>\n"); |
|
|
1293 | printf ("Save mode:\t%4.4o\n", SAVE_MODE); |
|
|
1294 | printf ("Playerdir:\t<VAR>/%s\n", settings.playerdir); |
|
|
1295 | printf ("Itemsdir:\t<VAR>/%s\n", settings.uniquedir); |
|
|
1296 | printf ("Tmpdir:\t\t%s\n", settings.tmpdir); |
|
|
1297 | printf ("Map max timeout:\t%d\n", MAP_MAXTIMEOUT); |
|
|
1298 | printf ("Max objects:\t%d\n", MAX_OBJECTS); |
|
|
1299 | #ifdef USE_CALLOC |
|
|
1300 | printf ("Use_calloc:\t<true>\n"); |
|
|
1301 | #else |
|
|
1302 | printf ("Use_calloc:\t<false>\n"); |
|
|
1303 | #endif |
|
|
1304 | |
437 | |
1305 | #ifdef X_EDITOR |
438 | return list; |
1306 | printf ("Editor:\t\t%s\n", X_EDITOR); |
|
|
1307 | #endif |
|
|
1308 | |
|
|
1309 | printf ("Max_time:\t%d\n", MAX_TIME); |
|
|
1310 | |
|
|
1311 | #ifdef WIN32 /* ***win32 compile_info(): remove execl... */ |
|
|
1312 | printf ("Logfilename:\t%s\n", settings.logfilename); |
|
|
1313 | exit (0); |
|
|
1314 | #else |
|
|
1315 | execl ("/bin/uname", "uname", "-a", NULL); |
|
|
1316 | LOG (llevError, "Oops, shouldn't have gotten here: execl(/bin/uname) failed: %s\n", strerror (errno)); |
|
|
1317 | exit (-1); |
|
|
1318 | #endif |
|
|
1319 | } |
439 | } |
1320 | |
440 | |
1321 | /* Signal handlers: */ |
441 | racelink * |
1322 | |
442 | find_racelink (const char *name) |
1323 | void |
|
|
1324 | rec_sigsegv (int i) |
|
|
1325 | { |
443 | { |
1326 | LOG (llevError, "\nSIGSEGV received.\n"); |
444 | if (name) |
1327 | fatal_signal (1, 1); |
445 | for (racelink *link = first_race; link; link = link->next) |
1328 | } |
446 | if (!link->name || !strcmp (name, link->name)) |
|
|
447 | return link; |
1329 | |
448 | |
1330 | void |
|
|
1331 | rec_sigint (int i) |
|
|
1332 | { |
|
|
1333 | LOG (llevInfo, "\nSIGINT received.\n"); |
|
|
1334 | fatal_signal (0, 1); |
|
|
1335 | } |
|
|
1336 | |
|
|
1337 | void |
|
|
1338 | rec_sighup (int i) |
|
|
1339 | { |
|
|
1340 | LOG (llevInfo, "\nSIGHUP received\n"); |
|
|
1341 | if (init_done) |
|
|
1342 | { |
|
|
1343 | emergency_save (0); |
|
|
1344 | cleanup (); |
|
|
1345 | } |
|
|
1346 | exit (0); |
|
|
1347 | } |
|
|
1348 | |
|
|
1349 | void |
|
|
1350 | rec_sigquit (int i) |
|
|
1351 | { |
|
|
1352 | LOG (llevInfo, "\nSIGQUIT received\n"); |
|
|
1353 | fatal_signal (1, 1); |
|
|
1354 | } |
|
|
1355 | |
|
|
1356 | void |
|
|
1357 | rec_sigbus (int i) |
|
|
1358 | { |
|
|
1359 | #ifdef SIGBUS |
|
|
1360 | LOG (llevError, "\nSIGBUS received\n"); |
|
|
1361 | fatal_signal (1, 1); |
|
|
1362 | #endif |
|
|
1363 | } |
|
|
1364 | |
|
|
1365 | void |
|
|
1366 | rec_sigterm (int i) |
|
|
1367 | { |
|
|
1368 | LOG (llevInfo, "\nSIGTERM received\n"); |
|
|
1369 | fatal_signal (0, 1); |
|
|
1370 | } |
|
|
1371 | |
|
|
1372 | void |
|
|
1373 | fatal_signal (int make_core, int close_sockets) |
|
|
1374 | { |
|
|
1375 | if (init_done) |
|
|
1376 | { |
|
|
1377 | emergency_save (0); |
|
|
1378 | clean_tmp_files (); |
|
|
1379 | } |
|
|
1380 | if (make_core) |
|
|
1381 | abort (); |
|
|
1382 | exit (0); |
|
|
1383 | } |
|
|
1384 | |
|
|
1385 | void |
|
|
1386 | init_signals (void) |
|
|
1387 | { |
|
|
1388 | #ifndef WIN32 /* init_signals() remove signals */ |
|
|
1389 | signal (SIGHUP, rec_sighup); |
|
|
1390 | signal (SIGINT, rec_sigint); |
|
|
1391 | signal (SIGQUIT, rec_sigquit); |
|
|
1392 | signal (SIGSEGV, rec_sigsegv); |
|
|
1393 | signal (SIGPIPE, SIG_IGN); |
|
|
1394 | # ifdef SIGBUS |
|
|
1395 | signal (SIGBUS, rec_sigbus); |
|
|
1396 | # endif |
|
|
1397 | signal (SIGTERM, rec_sigterm); |
|
|
1398 | #endif |
|
|
1399 | } |
|
|
1400 | |
|
|
1401 | /* init_races() - reads the races file in the lib/ directory, then |
|
|
1402 | * overwrites old 'race' entries. This routine allow us to quickly |
|
|
1403 | * re-configure the 'alignment' of monsters, objects. Useful for |
|
|
1404 | * putting together lists of creatures, etc that belong to gods. |
|
|
1405 | */ |
|
|
1406 | |
|
|
1407 | void |
|
|
1408 | init_races (void) |
|
|
1409 | { |
|
|
1410 | FILE *file; |
|
|
1411 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
|
|
1412 | archetype *mon = NULL; |
|
|
1413 | static int init_done = 0; |
|
|
1414 | |
|
|
1415 | if (init_done) |
|
|
1416 | return; |
449 | return 0; |
1417 | init_done = 1; |
|
|
1418 | first_race = 0; |
|
|
1419 | |
|
|
1420 | sprintf (fname, "%s/races", settings.datadir); |
|
|
1421 | LOG (llevDebug, "Reading races from %s...", fname); |
|
|
1422 | if (!(file = fopen (fname, "r"))) |
|
|
1423 | { |
|
|
1424 | LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno)); |
|
|
1425 | return; |
|
|
1426 | } |
|
|
1427 | |
|
|
1428 | while (fgets (buf, MAX_BUF, file) != NULL) |
|
|
1429 | { |
|
|
1430 | int set_race = 1, set_list = 1; |
|
|
1431 | |
|
|
1432 | if (*buf == '#') |
|
|
1433 | continue; |
|
|
1434 | |
|
|
1435 | if ((cp = strchr (buf, '\n')) != NULL) |
|
|
1436 | *cp = '\0'; |
|
|
1437 | |
|
|
1438 | cp = buf; |
|
|
1439 | while (*cp == ' ' || *cp == '!' || *cp == '@') |
|
|
1440 | { |
|
|
1441 | if (*cp == '!') |
|
|
1442 | set_race = 0; |
|
|
1443 | if (*cp == '@') |
|
|
1444 | set_list = 0; |
|
|
1445 | cp++; |
|
|
1446 | } |
|
|
1447 | |
|
|
1448 | if (sscanf (cp, "RACE %s", variable)) |
|
|
1449 | { /* set new race value */ |
|
|
1450 | strcpy (race, variable); |
|
|
1451 | } |
|
|
1452 | else |
|
|
1453 | { |
|
|
1454 | char *cp1; |
|
|
1455 | |
|
|
1456 | /* Take out beginning spaces */ |
|
|
1457 | for (cp1 = cp; *cp1 == ' '; cp1++) |
|
|
1458 | ; |
|
|
1459 | /* Remove newline and trailing spaces */ |
|
|
1460 | for (cp1 = cp + strlen (cp) - 1; *cp1 == '\n' || *cp1 == ' '; cp1--) |
|
|
1461 | { |
|
|
1462 | *cp1 = '\0'; |
|
|
1463 | if (cp == cp1) |
|
|
1464 | break; |
|
|
1465 | } |
|
|
1466 | |
|
|
1467 | if (cp[strlen (cp) - 1] == '\n') |
|
|
1468 | cp[strlen (cp) - 1] = '\0'; |
|
|
1469 | |
|
|
1470 | /* set creature race to race value */ |
|
|
1471 | if ((mon = archetype::find (cp)) == NULL) |
|
|
1472 | LOG (llevError, "\nCreature %s in race file lacks archetype", cp); |
|
|
1473 | else |
|
|
1474 | { |
|
|
1475 | if (set_race && (!mon->clone.race || strcmp (mon->clone.race, race))) |
|
|
1476 | { |
|
|
1477 | if (mon->clone.race) |
|
|
1478 | LOG (llevDebug, "\n Resetting race to %s from %s for archetype %s", race, &mon->clone.race, &mon->name); |
|
|
1479 | |
|
|
1480 | mon->clone.race = race; |
|
|
1481 | } |
|
|
1482 | |
|
|
1483 | /* if the arch is a monster, add it to the race list */ |
|
|
1484 | if (set_list && QUERY_FLAG (&mon->clone, FLAG_MONSTER)) |
|
|
1485 | add_to_racelist (race, &mon->clone); |
|
|
1486 | } |
|
|
1487 | } |
|
|
1488 | } |
|
|
1489 | |
|
|
1490 | fclose (file); |
|
|
1491 | LOG (llevDebug, "done.\n"); |
|
|
1492 | } |
450 | } |
1493 | |
451 | |
1494 | void |
452 | static void |
1495 | dump_races (void) |
|
|
1496 | { |
|
|
1497 | racelink *list; |
|
|
1498 | objectlink *tmp; |
|
|
1499 | |
|
|
1500 | for (list = first_race; list; list = list->next) |
|
|
1501 | { |
|
|
1502 | fprintf (stderr, "\nRACE %s:\t", &list->name); |
|
|
1503 | for (tmp = list->member; tmp; tmp = tmp->next) |
|
|
1504 | fprintf (stderr, "%s(%d), ", &tmp->ob->arch->name, tmp->ob->level); |
|
|
1505 | } |
|
|
1506 | |
|
|
1507 | fprintf (stderr, "\n"); |
|
|
1508 | } |
|
|
1509 | |
|
|
1510 | void |
|
|
1511 | add_to_racelist (const char *race_name, object *op) |
453 | add_to_racelist (const char *race_name, object *op) |
1512 | { |
454 | { |
1513 | racelink *race; |
455 | racelink *race; |
1514 | |
456 | |
1515 | if (!op || !race_name) |
457 | if (!op || !race_name) |
… | |
… | |
1535 | |
477 | |
1536 | race->nrof++; |
478 | race->nrof++; |
1537 | race->member->ob = op; |
479 | race->member->ob = op; |
1538 | } |
480 | } |
1539 | |
481 | |
1540 | racelink * |
482 | /* init_races() - reads the races file in the lib/ directory, then |
1541 | get_racelist () |
483 | * overwrites old 'race' entries. This routine allow us to quickly |
|
|
484 | * re-configure the 'alignment' of monsters, objects. Useful for |
|
|
485 | * putting together lists of creatures, etc that belong to gods. |
|
|
486 | */ |
|
|
487 | static void |
|
|
488 | init_races () |
1542 | { |
489 | { |
1543 | racelink *list = new racelink; |
490 | FILE *file; |
|
|
491 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
|
|
492 | archetype *mon = NULL; |
|
|
493 | static int init_done = 0; |
1544 | |
494 | |
1545 | list->name = 0; |
495 | if (init_done) |
1546 | list->nrof = 0; |
|
|
1547 | list->next = 0; |
|
|
1548 | list->member = get_objectlink (); |
|
|
1549 | |
|
|
1550 | return list; |
|
|
1551 | } |
|
|
1552 | |
|
|
1553 | racelink * |
|
|
1554 | find_racelink (const char *name) |
|
|
1555 | { |
|
|
1556 | if (name) |
|
|
1557 | for (racelink *link = first_race; link; link = link->next) |
|
|
1558 | if (!link->name || !strcmp (name, link->name)) |
|
|
1559 | return link; |
|
|
1560 | |
|
|
1561 | return 0; |
496 | return; |
|
|
497 | init_done = 1; |
|
|
498 | first_race = 0; |
|
|
499 | |
|
|
500 | sprintf (fname, "%s/races", settings.datadir); |
|
|
501 | LOG (llevDebug, "Reading races from %s...\n", fname); |
|
|
502 | if (!(file = fopen (fname, "r"))) |
|
|
503 | { |
|
|
504 | LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno)); |
|
|
505 | return; |
|
|
506 | } |
|
|
507 | |
|
|
508 | while (fgets (buf, MAX_BUF, file) != NULL) |
|
|
509 | { |
|
|
510 | int set_race = 1, set_list = 1; |
|
|
511 | |
|
|
512 | if (*buf == '#') |
|
|
513 | continue; |
|
|
514 | |
|
|
515 | if ((cp = strchr (buf, '\n')) != NULL) |
|
|
516 | *cp = '\0'; |
|
|
517 | |
|
|
518 | cp = buf; |
|
|
519 | while (*cp == ' ' || *cp == '!' || *cp == '@') |
|
|
520 | { |
|
|
521 | if (*cp == '!') set_race = 0; |
|
|
522 | if (*cp == '@') set_list = 0; |
|
|
523 | |
|
|
524 | cp++; |
|
|
525 | } |
|
|
526 | |
|
|
527 | if (sscanf (cp, "RACE %s", variable)) |
|
|
528 | /* set new race value */ |
|
|
529 | strcpy (race, variable); |
|
|
530 | else |
|
|
531 | { |
|
|
532 | char *cp1; |
|
|
533 | |
|
|
534 | /* Take out beginning spaces */ |
|
|
535 | for (cp1 = cp; *cp1 == ' '; cp1++) |
|
|
536 | ; |
|
|
537 | /* Remove newline and trailing spaces */ |
|
|
538 | for (cp1 = cp + strlen (cp) - 1; *cp1 == '\n' || *cp1 == ' '; cp1--) |
|
|
539 | { |
|
|
540 | *cp1 = '\0'; |
|
|
541 | if (cp == cp1) |
|
|
542 | break; |
|
|
543 | } |
|
|
544 | |
|
|
545 | if (cp[strlen (cp) - 1] == '\n') |
|
|
546 | cp[strlen (cp) - 1] = '\0'; |
|
|
547 | |
|
|
548 | /* set creature race to race value */ |
|
|
549 | if ((mon = archetype::find (cp)) == NULL) |
|
|
550 | LOG (llevError, "Creature %s in race file lacks archetype\n", cp); |
|
|
551 | else |
|
|
552 | { |
|
|
553 | if (set_race && (!mon->race || strcmp (&mon->race, race))) |
|
|
554 | { |
|
|
555 | if (mon->race) |
|
|
556 | LOG (llevDebug, "Resetting race to %s from %s for archetype %s\n", race, &mon->race, &mon->archname); |
|
|
557 | |
|
|
558 | mon->race = race; |
|
|
559 | } |
|
|
560 | |
|
|
561 | /* if the arch is a monster, add it to the race list */ |
|
|
562 | if (set_list && mon->flag [FLAG_MONSTER]) |
|
|
563 | add_to_racelist (race, mon); |
|
|
564 | } |
|
|
565 | } |
|
|
566 | } |
|
|
567 | |
|
|
568 | fclose (file); |
|
|
569 | LOG (llevDebug, "done.\n"); |
1562 | } |
570 | } |
|
|
571 | |
|
|
572 | void |
|
|
573 | init_beforeplay () |
|
|
574 | { |
|
|
575 | init_artifacts (); /* If not called before, reads all artifacts from file */ |
|
|
576 | init_races (); /* overwrite race designations using entries in lib/races file */ |
|
|
577 | init_gods (); /* init linked list of gods from archs */ |
|
|
578 | init_readable (); /* inits useful arrays for readable texts */ |
|
|
579 | init_formulae (); /* If not called before, reads formulae from file */ |
|
|
580 | } |
|
|
581 | |