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