ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/init.C
(Generate patch)

Comparing deliantra/server/server/init.C (file contents):
Revision 1.18 by root, Sat Dec 16 17:16:52 2006 UTC vs.
Revision 1.88 by root, Sat Nov 17 23:40:04 2018 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines