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