1 |
/* |
2 |
CrossFire, A Multiplayer game for X-windows |
3 |
|
4 |
Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 |
Copyright (C) 1992 Frank Tore Johansen |
6 |
|
7 |
This program is free software; you can redistribute it and/or modify |
8 |
it under the terms of the GNU General Public License as published by |
9 |
the Free Software Foundation; either version 2 of the License, or |
10 |
(at your option) any later version. |
11 |
|
12 |
This program is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
16 |
|
17 |
You should have received a copy of the GNU General Public License |
18 |
along with this program; if not, write to the Free Software |
19 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 |
|
21 |
The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 |
*/ |
23 |
|
24 |
#include <global.h> |
25 |
#include <material.h> |
26 |
#include <loader.h> |
27 |
#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 |
|
508 |
/* 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 |
510 |
* information, having it here probably makes more sense. |
511 |
*/ |
512 |
static void |
513 |
load_settings (void) |
514 |
{ |
515 |
char buf[MAX_BUF], *cp; |
516 |
int has_val, comp; |
517 |
FILE *fp; |
518 |
|
519 |
sprintf (buf, "%s/settings", settings.confdir); |
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 |
{ |
527 |
LOG (llevError, "Warning: No settings file found\n"); |
528 |
return; |
529 |
} |
530 |
while (fgets (buf, MAX_BUF - 1, fp) != NULL) |
531 |
{ |
532 |
if (buf[0] == '#') |
533 |
continue; |
534 |
/* eliminate newline */ |
535 |
if ((cp = strrchr (buf, '\n')) != NULL) |
536 |
*cp = '\0'; |
537 |
|
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")) |
644 |
{ |
645 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
646 |
{ |
647 |
settings.not_permadeth = TRUE; |
648 |
} |
649 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
650 |
{ |
651 |
settings.not_permadeth = FALSE; |
652 |
} |
653 |
else |
654 |
{ |
655 |
LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp); |
656 |
} |
657 |
} |
658 |
else if (!strcasecmp (buf, "resurrection")) |
659 |
{ |
660 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
661 |
{ |
662 |
settings.resurrection = TRUE; |
663 |
} |
664 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
665 |
{ |
666 |
settings.resurrection = FALSE; |
667 |
} |
668 |
else |
669 |
{ |
670 |
LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp); |
671 |
} |
672 |
} |
673 |
else if (!strcasecmp (buf, "set_title")) |
674 |
{ |
675 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
676 |
{ |
677 |
settings.set_title = TRUE; |
678 |
} |
679 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
680 |
{ |
681 |
settings.set_title = FALSE; |
682 |
} |
683 |
else |
684 |
{ |
685 |
LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp); |
686 |
} |
687 |
} |
688 |
else if (!strcasecmp (buf, "search_items")) |
689 |
{ |
690 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
691 |
{ |
692 |
settings.search_items = TRUE; |
693 |
} |
694 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
695 |
{ |
696 |
settings.search_items = FALSE; |
697 |
} |
698 |
else |
699 |
{ |
700 |
LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp); |
701 |
} |
702 |
} |
703 |
else if (!strcasecmp (buf, "spell_encumbrance")) |
704 |
{ |
705 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
706 |
{ |
707 |
settings.spell_encumbrance = TRUE; |
708 |
} |
709 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
710 |
{ |
711 |
settings.spell_encumbrance = FALSE; |
712 |
} |
713 |
else |
714 |
{ |
715 |
LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp); |
716 |
} |
717 |
} |
718 |
else if (!strcasecmp (buf, "spell_failure_effects")) |
719 |
{ |
720 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
721 |
{ |
722 |
settings.spell_failure_effects = TRUE; |
723 |
} |
724 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
725 |
{ |
726 |
settings.spell_failure_effects = FALSE; |
727 |
} |
728 |
else |
729 |
{ |
730 |
LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp); |
731 |
} |
732 |
} |
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")) |
779 |
{ |
780 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
781 |
{ |
782 |
settings.spellpoint_level_depend = TRUE; |
783 |
} |
784 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
785 |
{ |
786 |
settings.spellpoint_level_depend = FALSE; |
787 |
} |
788 |
else |
789 |
{ |
790 |
LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp); |
791 |
} |
792 |
} |
793 |
else if (!strcasecmp (buf, "stat_loss_on_death")) |
794 |
{ |
795 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
796 |
{ |
797 |
settings.stat_loss_on_death = TRUE; |
798 |
} |
799 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
800 |
{ |
801 |
settings.stat_loss_on_death = FALSE; |
802 |
} |
803 |
else |
804 |
{ |
805 |
LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp); |
806 |
} |
807 |
} |
808 |
else if (!strcasecmp (buf, "use_permanent_experience")) |
809 |
{ |
810 |
LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n"); |
811 |
} |
812 |
else if (!strcasecmp (buf, "permanent_experience_percentage")) |
813 |
{ |
814 |
int val = atoi (cp); |
815 |
|
816 |
if (val < 0 || val > 100) |
817 |
LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val); |
818 |
else |
819 |
settings.permanent_exp_ratio = val; |
820 |
} |
821 |
else if (!strcasecmp (buf, "death_penalty_percentage")) |
822 |
{ |
823 |
int val = atoi (cp); |
824 |
|
825 |
if (val < 0 || val > 100) |
826 |
LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val); |
827 |
else |
828 |
settings.death_penalty_ratio = val; |
829 |
} |
830 |
else if (!strcasecmp (buf, "death_penalty_levels")) |
831 |
{ |
832 |
int val = atoi (cp); |
833 |
|
834 |
if (val < 0 || val > 255) |
835 |
LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val); |
836 |
else |
837 |
settings.death_penalty_level = val; |
838 |
} |
839 |
else if (!strcasecmp (buf, "balanced_stat_loss")) |
840 |
{ |
841 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
842 |
{ |
843 |
settings.balanced_stat_loss = TRUE; |
844 |
} |
845 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
846 |
{ |
847 |
settings.balanced_stat_loss = FALSE; |
848 |
} |
849 |
else |
850 |
{ |
851 |
LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp); |
852 |
} |
853 |
} |
854 |
else if (!strcasecmp (buf, "simple_exp")) |
855 |
{ |
856 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
857 |
{ |
858 |
settings.simple_exp = TRUE; |
859 |
} |
860 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
861 |
{ |
862 |
settings.simple_exp = FALSE; |
863 |
} |
864 |
else |
865 |
{ |
866 |
LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp); |
867 |
} |
868 |
} |
869 |
else if (!strcasecmp (buf, "item_power_factor")) |
870 |
{ |
871 |
float tmp = atof (cp); |
872 |
|
873 |
if (tmp < 0) |
874 |
LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp); |
875 |
else |
876 |
settings.item_power_factor = tmp; |
877 |
} |
878 |
else if (!strcasecmp (buf, "pk_luck_penalty")) |
879 |
{ |
880 |
sint16 val = atoi (cp); |
881 |
|
882 |
if (val < -100 || val > 100) |
883 |
LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val); |
884 |
else |
885 |
settings.pk_luck_penalty = val; |
886 |
} |
887 |
else if (!strcasecmp (buf, "set_friendly_fire")) |
888 |
{ |
889 |
int val = atoi (cp); |
890 |
|
891 |
#if COZY_SERVER |
892 |
if (val < 0 || val > 100) |
893 |
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 |
899 |
settings.set_friendly_fire = val; |
900 |
} |
901 |
else if (!strcasecmp (buf, "armor_max_enchant")) |
902 |
{ |
903 |
int max_e = atoi (cp); |
904 |
|
905 |
if (max_e <= 0) |
906 |
LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e); |
907 |
else |
908 |
settings.armor_max_enchant = max_e; |
909 |
} |
910 |
else if (!strcasecmp (buf, "armor_weight_reduction")) |
911 |
{ |
912 |
int wr = atoi (cp); |
913 |
|
914 |
if (wr < 0) |
915 |
LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr); |
916 |
else |
917 |
settings.armor_weight_reduction = wr; |
918 |
} |
919 |
else if (!strcasecmp (buf, "armor_weight_linear")) |
920 |
{ |
921 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
922 |
{ |
923 |
settings.armor_weight_linear = TRUE; |
924 |
} |
925 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
926 |
{ |
927 |
settings.armor_weight_linear = FALSE; |
928 |
} |
929 |
else |
930 |
{ |
931 |
LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); |
932 |
} |
933 |
|
934 |
} |
935 |
else if (!strcasecmp (buf, "armor_speed_improvement")) |
936 |
{ |
937 |
int wr = atoi (cp); |
938 |
|
939 |
if (wr < 0) |
940 |
LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr); |
941 |
else |
942 |
settings.armor_speed_improvement = wr; |
943 |
} |
944 |
else if (!strcasecmp (buf, "armor_speed_linear")) |
945 |
{ |
946 |
if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
947 |
{ |
948 |
settings.armor_speed_linear = TRUE; |
949 |
} |
950 |
else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
951 |
{ |
952 |
settings.armor_speed_linear = FALSE; |
953 |
} |
954 |
else |
955 |
{ |
956 |
LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); |
957 |
} |
958 |
|
959 |
} |
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 |
993 |
{ |
994 |
LOG (llevError, "Unknown value in settings file: %s\n", buf); |
995 |
} |
996 |
} |
997 |
|
998 |
close_and_delete (fp, comp); |
999 |
} |
1000 |
|
1001 |
|
1002 |
/* |
1003 |
* init() is called only once, when starting the program. |
1004 |
*/ |
1005 |
|
1006 |
void |
1007 |
init (int argc, char **argv) |
1008 |
{ |
1009 |
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 |
|
1015 |
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; |
1048 |
} |
1049 |
|
1050 |
void |
1051 |
usage (void) |
1052 |
{ |
1053 |
(void) fprintf (logfile, "Usage: crossfire [-h] [-<flags>]...\n"); |
1054 |
} |
1055 |
|
1056 |
void |
1057 |
help (void) |
1058 |
{ |
1059 |
|
1060 |
/* The information in usage is redundant with what is given below, so why call it? */ |
1061 |
|
1062 |
/* usage();*/ |
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 |
|
1101 |
void |
1102 |
init_beforeplay (void) |
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 |
|
1114 |
switch (settings.dumpvalues) |
1115 |
{ |
1116 |
case 1: |
1117 |
print_monsters (); |
1118 |
exit (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 |
1162 |
|
1163 |
if (forbid_play ()) |
1164 |
{ /* Maybe showing highscore should be allowed? */ |
1165 |
LOG (llevError, "CrossFire: Playing not allowed.\n"); |
1166 |
exit (-1); |
1167 |
} |
1168 |
} |
1169 |
|
1170 |
/* |
1171 |
* compile_info(): activated with the -o flag. |
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 |
{ |
1179 |
int i = 0; |
1180 |
|
1181 |
printf ("Non-standard include files:\n"); |
1182 |
#if !defined (__STRICT_ANSI__) || defined (__sun__) |
1183 |
# if !defined (Mips) |
1184 |
printf ("<stdlib.h>\n"); |
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 |
|
1225 |
#ifdef X_EDITOR |
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 |
} |
1235 |
|
1236 |
/* Signal handlers: */ |
1237 |
|
1238 |
void |
1239 |
rec_sigsegv (int i) |
1240 |
{ |
1241 |
LOG (llevError, "SIGSEGV received.\n"); |
1242 |
fatal_signal (1, 1); |
1243 |
} |
1244 |
|
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; |
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 |
} |
1398 |
|
1399 |
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) |
1417 |
{ |
1418 |
racelink *race; |
1419 |
|
1420 |
if (!op || !race_name) |
1421 |
return; |
1422 |
|
1423 |
race = find_racelink (race_name); |
1424 |
|
1425 |
if (!race) |
1426 |
{ /* add in a new race list */ |
1427 |
race = get_racelist (); |
1428 |
race->next = first_race; |
1429 |
first_race = race; |
1430 |
race->name = race_name; |
1431 |
} |
1432 |
|
1433 |
if (race->member->ob) |
1434 |
{ |
1435 |
objectlink *tmp = get_objectlink (); |
1436 |
|
1437 |
tmp->next = race->member; |
1438 |
race->member = tmp; |
1439 |
} |
1440 |
|
1441 |
race->nrof++; |
1442 |
race->member->ob = op; |
1443 |
} |
1444 |
|
1445 |
racelink * |
1446 |
get_racelist () |
1447 |
{ |
1448 |
racelink *list = new racelink; |
1449 |
|
1450 |
list->name = 0; |
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; |
1467 |
} |