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.22 by root, Tue Dec 26 08:55:00 2006 UTC vs.
Revision 1.83 by root, Sat Apr 23 04:56:56 2011 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 (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
8 it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
9 the Free Software Foundation; either version 2 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
10 (at your option) any later version. 11 * option) any later version.
11 12 *
12 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
18 along with this program; if not, write to the Free Software 19 * and the GNU General Public License along with this program. If not, see
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
20 21 *
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22*/ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <material.h> 26#include <material.h>
26#include <loader.h>
27#include <sproto.h> 27#include <sproto.h>
28
29/* global weathermap */
30weathermap_t **weathermap;
31
32void
33set_logfile (char *val)
34{
35 settings.logfilename = val;
36}
37
38void
39call_version (void)
40{
41 version (NULL);
42 exit (0);
43}
44
45void
46showscores (void)
47{
48 display_high_score (NULL, 9999, NULL);
49 exit (0);
50}
51
52void
53set_debug (void)
54{
55 settings.debug = llevDebug;
56}
57
58void
59unset_debug (void)
60{
61 settings.debug = llevInfo;
62}
63
64void
65set_mondebug (void)
66{
67 settings.debug = llevMonster;
68}
69
70void
71set_dumpmon1 (void)
72{
73 settings.dumpvalues = 1;
74}
75
76void
77set_dumpmon2 (void)
78{
79 settings.dumpvalues = 2;
80}
81
82void
83set_dumpmon3 (void)
84{
85 settings.dumpvalues = 3;
86}
87
88void
89set_dumpmon4 (void)
90{
91 settings.dumpvalues = 4;
92}
93
94void
95set_dumpmon5 (void)
96{
97 settings.dumpvalues = 5;
98}
99
100void
101set_dumpmon6 (void)
102{
103 settings.dumpvalues = 6;
104}
105
106void
107set_dumpmon7 (void)
108{
109 settings.dumpvalues = 7;
110}
111
112void
113set_dumpmon8 (void)
114{
115 settings.dumpvalues = 8;
116}
117
118void
119set_dumpmon9 (void)
120{
121 settings.dumpvalues = 9;
122}
123
124void
125set_dumpmont (char *name)
126{
127 settings.dumpvalues = 10;
128 settings.dumparg = name;
129}
130
131void
132set_daemon (void)
133{
134 settings.daemonmode = 1;
135}
136
137void
138set_datadir (char *path)
139{
140 settings.datadir = path;
141}
142
143void
144set_confdir (char *path)
145{
146 settings.confdir = path;
147}
148
149void
150set_localdir (char *path)
151{
152 settings.localdir = path;
153}
154
155void
156set_mapdir (char *path)
157{
158 settings.mapdir = path;
159}
160
161void
162set_archetypes (char *path)
163{
164 settings.archetypes = path;
165}
166
167void
168set_regions (char *path)
169{
170 settings.regions = path;
171}
172
173void
174set_treasures (char *path)
175{
176 settings.treasures = path;
177}
178
179void
180set_uniquedir (char *path)
181{
182 settings.uniquedir = path;
183}
184
185void
186set_templatedir (char *path)
187{
188 settings.templatedir = path;
189}
190
191void
192set_playerdir (char *path)
193{
194 settings.playerdir = path;
195}
196
197void
198set_tmpdir (char *path)
199{
200 settings.tmpdir = path;
201}
202
203void
204showscoresparm (char *data)
205{
206 display_high_score (NULL, 9999, data);
207 exit (0);
208}
209
210void
211set_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 */
224struct 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 */
241struct 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 */
296static void
297parse_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
350static materialtype_t *
351get_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
378static void
379load_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 28
508/* This loads the settings file. There could be debate whether this should 29/* This loads the settings file. There could be debate whether this should
509 * be here or in the common directory - but since only the server needs this 30 * be here or in the common directory - but since only the server needs this
510 * information, having it here probably makes more sense. 31 * information, having it here probably makes more sense.
511 */ 32 */
512static void 33void
513load_settings (void) 34load_settings ()
514{ 35{
515 char buf[MAX_BUF], *cp; 36 object_thawer thawer (settings.confdir, "settings");
516 int has_val, comp;
517 FILE *fp;
518 37
519 sprintf (buf, "%s/settings", settings.confdir); 38 if (!thawer)
520
521 /* We don't require a settings file at current time, but down the road,
522 * there will probably be so many values that not having a settings file
523 * will not be a good thing.
524 */
525 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
526 { 39 {
527 LOG (llevError, "Warning: No settings file found\n"); 40 LOG (llevError, "Error: No settings file found\n");
528 return; 41 exit (1);
529 } 42 }
530 while (fgets (buf, MAX_BUF - 1, fp) != NULL) 43
44 while (thawer.kw)
531 { 45 {
532 if (buf[0] == '#') 46 const char *buf = thawer.kw_str;
533 continue; 47 const char *cp = thawer.value_nn;
534 /* eliminate newline */
535 if ((cp = strrchr (buf, '\n')) != NULL)
536 *cp = '\0';
537 48
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")) 49 if (!strcmp (buf, "not_permadeth"))
644 { 50 {
645 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 51 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
646 { 52 {
647 settings.not_permadeth = TRUE; 53 settings.not_permadeth = TRUE;
648 } 54 }
649 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 55 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
650 { 56 {
651 settings.not_permadeth = FALSE; 57 settings.not_permadeth = FALSE;
652 } 58 }
653 else 59 else
654 { 60 {
655 LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp); 61 LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp);
656 } 62 }
657 } 63 }
658 else if (!strcasecmp (buf, "resurrection")) 64 else if (!strcmp (buf, "resurrection"))
659 { 65 {
660 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 66 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
661 { 67 {
662 settings.resurrection = TRUE; 68 settings.resurrection = TRUE;
663 } 69 }
664 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 70 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
665 { 71 {
666 settings.resurrection = FALSE; 72 settings.resurrection = FALSE;
667 } 73 }
668 else 74 else
669 { 75 {
670 LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp); 76 LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp);
671 } 77 }
672 } 78 }
673 else if (!strcasecmp (buf, "set_title")) 79 else if (!strcmp (buf, "set_title"))
674 { 80 {
675 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 81 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
676 { 82 {
677 settings.set_title = TRUE; 83 settings.set_title = TRUE;
678 } 84 }
679 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 85 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
680 { 86 {
681 settings.set_title = FALSE; 87 settings.set_title = FALSE;
682 } 88 }
683 else 89 else
684 { 90 {
685 LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp); 91 LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp);
686 } 92 }
687 } 93 }
688 else if (!strcasecmp (buf, "search_items")) 94 else if (!strcmp (buf, "search_items"))
689 { 95 {
690 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 96 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
691 { 97 {
692 settings.search_items = TRUE; 98 settings.search_items = TRUE;
693 } 99 }
694 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 100 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
695 { 101 {
696 settings.search_items = FALSE; 102 settings.search_items = FALSE;
697 } 103 }
698 else 104 else
699 { 105 {
700 LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp); 106 LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp);
701 } 107 }
702 } 108 }
703 else if (!strcasecmp (buf, "spell_encumbrance")) 109 else if (!strcmp (buf, "spell_encumbrance"))
704 { 110 {
705 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 111 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
706 { 112 {
707 settings.spell_encumbrance = TRUE; 113 settings.spell_encumbrance = TRUE;
708 } 114 }
709 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 115 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
710 { 116 {
711 settings.spell_encumbrance = FALSE; 117 settings.spell_encumbrance = FALSE;
712 } 118 }
713 else 119 else
714 { 120 {
715 LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp); 121 LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp);
716 } 122 }
717 } 123 }
718 else if (!strcasecmp (buf, "spell_failure_effects")) 124 else if (!strcmp (buf, "spell_failure_effects"))
719 { 125 {
720 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 126 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
721 { 127 {
722 settings.spell_failure_effects = TRUE; 128 settings.spell_failure_effects = TRUE;
723 } 129 }
724 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 130 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
725 { 131 {
726 settings.spell_failure_effects = FALSE; 132 settings.spell_failure_effects = FALSE;
727 } 133 }
728 else 134 else
729 { 135 {
730 LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp); 136 LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp);
731 } 137 }
732 } 138 }
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")) 139 else if (!strcmp (buf, "spellpoint_level_depend"))
779 { 140 {
780 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 141 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
781 { 142 {
782 settings.spellpoint_level_depend = TRUE; 143 settings.spellpoint_level_depend = TRUE;
783 } 144 }
784 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 145 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
785 { 146 {
786 settings.spellpoint_level_depend = FALSE; 147 settings.spellpoint_level_depend = FALSE;
787 } 148 }
788 else 149 else
789 { 150 {
790 LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp); 151 LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp);
791 } 152 }
792 } 153 }
793 else if (!strcasecmp (buf, "stat_loss_on_death")) 154 else if (!strcmp (buf, "stat_loss_on_death"))
794 { 155 {
795 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 156 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
796 { 157 {
797 settings.stat_loss_on_death = TRUE; 158 settings.stat_loss_on_death = TRUE;
798 } 159 }
799 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 160 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
800 { 161 {
801 settings.stat_loss_on_death = FALSE; 162 settings.stat_loss_on_death = FALSE;
802 } 163 }
803 else 164 else
804 { 165 {
805 LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp); 166 LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp);
806 } 167 }
807 } 168 }
808 else if (!strcasecmp (buf, "use_permanent_experience")) 169 else if (!strcmp (buf, "use_permanent_experience"))
809 { 170 {
810 LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n"); 171 LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n");
811 } 172 }
812 else if (!strcasecmp (buf, "permanent_experience_percentage")) 173 else if (!strcmp (buf, "permanent_experience_percentage"))
813 { 174 {
814 int val = atoi (cp); 175 int val = atoi (cp);
815 176
816 if (val < 0 || val > 100) 177 if (val < 0 || val > 100)
817 LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val); 178 LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val);
818 else 179 else
819 settings.permanent_exp_ratio = val; 180 settings.permanent_exp_ratio = val;
820 } 181 }
821 else if (!strcasecmp (buf, "death_penalty_percentage")) 182 else if (!strcmp (buf, "death_penalty_percentage"))
822 { 183 {
823 int val = atoi (cp); 184 int val = atoi (cp);
824 185
825 if (val < 0 || val > 100) 186 if (val < 0 || val > 100)
826 LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val); 187 LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val);
827 else 188 else
828 settings.death_penalty_ratio = val; 189 settings.death_penalty_ratio = val;
829 } 190 }
830 else if (!strcasecmp (buf, "death_penalty_levels")) 191 else if (!strcmp (buf, "death_penalty_levels"))
831 { 192 {
832 int val = atoi (cp); 193 int val = atoi (cp);
833 194
834 if (val < 0 || val > 255) 195 if (val < 0 || val > 255)
835 LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val); 196 LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val);
836 else 197 else
837 settings.death_penalty_level = val; 198 settings.death_penalty_level = val;
838 } 199 }
839 else if (!strcasecmp (buf, "balanced_stat_loss")) 200 else if (!strcmp (buf, "balanced_stat_loss"))
840 { 201 {
841 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 202 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
842 { 203 {
843 settings.balanced_stat_loss = TRUE; 204 settings.balanced_stat_loss = TRUE;
844 } 205 }
845 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 206 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
846 { 207 {
847 settings.balanced_stat_loss = FALSE; 208 settings.balanced_stat_loss = FALSE;
848 } 209 }
849 else 210 else
850 { 211 {
851 LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp); 212 LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp);
852 } 213 }
853 } 214 }
854 else if (!strcasecmp (buf, "simple_exp")) 215 else if (!strcmp (buf, "simple_exp"))
855 { 216 {
856 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 217 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
857 { 218 {
858 settings.simple_exp = TRUE; 219 settings.simple_exp = TRUE;
859 } 220 }
860 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 221 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
861 { 222 {
862 settings.simple_exp = FALSE; 223 settings.simple_exp = FALSE;
863 } 224 }
864 else 225 else
865 { 226 {
866 LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp); 227 LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp);
867 } 228 }
868 } 229 }
869 else if (!strcasecmp (buf, "item_power_factor")) 230 else if (!strcmp (buf, "item_power_factor"))
870 { 231 {
871 float tmp = atof (cp); 232 float tmp = atof (cp);
872 233
873 if (tmp < 0) 234 if (tmp < 0)
874 LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp); 235 LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp);
875 else 236 else
876 settings.item_power_factor = tmp; 237 settings.item_power_factor = tmp;
877 } 238 }
878 else if (!strcasecmp (buf, "pk_luck_penalty")) 239 else if (!strcmp (buf, "pk_luck_penalty"))
879 { 240 {
880 sint16 val = atoi (cp); 241 sint16 val = atoi (cp);
881 242
882 if (val < -100 || val > 100) 243 if (val < -100 || val > 100)
883 LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val); 244 LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val);
884 else 245 else
885 settings.pk_luck_penalty = val; 246 settings.pk_luck_penalty = val;
886 } 247 }
887 else if (!strcasecmp (buf, "set_friendly_fire")) 248 else if (!strcmp (buf, "set_friendly_fire"))
888 { 249 {
889 int val = atoi (cp); 250 int val = atoi (cp);
890 251
891#if COZY_SERVER
892 if (val < 0 || val > 100) 252 if (val < 0 || val > 100)
893 LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val); 253 LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val);
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 254 else
899 settings.set_friendly_fire = val; 255 settings.set_friendly_fire = val;
900 } 256 }
901 else if (!strcasecmp (buf, "armor_max_enchant")) 257 else if (!strcmp (buf, "armor_max_enchant"))
902 { 258 {
903 int max_e = atoi (cp); 259 int max_e = atoi (cp);
904 260
905 if (max_e <= 0) 261 if (max_e <= 0)
906 LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e); 262 LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e);
907 else 263 else
908 settings.armor_max_enchant = max_e; 264 settings.armor_max_enchant = max_e;
909 } 265 }
910 else if (!strcasecmp (buf, "armor_weight_reduction")) 266 else if (!strcmp (buf, "armor_weight_reduction"))
911 { 267 {
912 int wr = atoi (cp); 268 int wr = atoi (cp);
913 269
914 if (wr < 0) 270 if (wr < 0)
915 LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr); 271 LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr);
916 else 272 else
917 settings.armor_weight_reduction = wr; 273 settings.armor_weight_reduction = wr;
918 } 274 }
919 else if (!strcasecmp (buf, "armor_weight_linear")) 275 else if (!strcmp (buf, "armor_weight_linear"))
920 { 276 {
921 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 277 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
922 { 278 {
923 settings.armor_weight_linear = TRUE; 279 settings.armor_weight_linear = TRUE;
924 } 280 }
925 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 281 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
926 { 282 {
927 settings.armor_weight_linear = FALSE; 283 settings.armor_weight_linear = FALSE;
928 } 284 }
929 else 285 else
930 { 286 {
931 LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); 287 LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp);
932 } 288 }
933 289
934 } 290 }
935 else if (!strcasecmp (buf, "armor_speed_improvement")) 291 else if (!strcmp (buf, "armor_speed_improvement"))
936 { 292 {
937 int wr = atoi (cp); 293 int wr = atoi (cp);
938 294
939 if (wr < 0) 295 if (wr < 0)
940 LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr); 296 LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr);
941 else 297 else
942 settings.armor_speed_improvement = wr; 298 settings.armor_speed_improvement = wr;
943 } 299 }
944 else if (!strcasecmp (buf, "armor_speed_linear")) 300 else if (!strcmp (buf, "armor_speed_linear"))
945 { 301 {
946 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 302 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
947 { 303 {
948 settings.armor_speed_linear = TRUE; 304 settings.armor_speed_linear = TRUE;
949 } 305 }
950 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 306 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
951 { 307 {
952 settings.armor_speed_linear = FALSE; 308 settings.armor_speed_linear = FALSE;
953 } 309 }
954 else 310 else
955 { 311 {
956 LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); 312 LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp);
957 } 313 }
958 314
959 } 315 }
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 316 else
993 { 317 thawer.parse_error ("settings file");
994 LOG (llevError, "Unknown value in settings file: %s\n", buf); 318
995 } 319 thawer.next ();
996 } 320 }
997
998 close_and_delete (fp, comp);
999} 321}
1000
1001 322
1002/* 323/*
1003 * init() is called only once, when starting the program. 324 * init() is called only once, when starting the program.
1004 */ 325 */
1005
1006void 326void
1007init (int argc, char **argv) 327init (int argc, char **argv)
1008{ 328{
1009 init_done = 0; /* Must be done before init_signal() */ 329 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 330
331 init_environ ();
1015 cfperl_init (); 332 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; 333 init_done = 1;
1048} 334}
1049 335
336/* Signal handlers: */
337
338static void
339rec_sigabrt (int i)
340{
341 signal (SIGABRT, SIG_DFL);
342
343 LOG (llevError, "SIGABRT received.\n");
344 cleanup ("SIGABRT received", 1);
345}
346
347static void
348rec_sigsegv (int i)
349{
350 signal (SIGSEGV, SIG_DFL);
351
352 LOG (llevError, "SIGSEGV received.\n");
353 cleanup ("SIGSEGV received", 1);
354}
355
356static void
357rec_sigquit (int i)
358{
359 signal (SIGQUIT, SIG_IGN);
360
361 LOG (llevInfo, "SIGQUIT received\n");
362 cleanup ("SIGQUIT received", 1);
363}
364
365static void
366rec_sigbus (int i)
367{
368 signal (SIGBUS, SIG_DFL);
369
370 LOG (llevError, "SIGBUS received\n");
371 cleanup ("SIGBUS received", 1);
372}
373
1050void 374void
1051usage (void) 375reset_signals ()
1052{ 376{
1053 (void) fprintf (logfile, "Usage: crossfire [-h] [-<flags>]...\n"); 377 signal (SIGABRT, SIG_DFL);
378 signal (SIGQUIT, SIG_DFL);
379 signal (SIGSEGV, SIG_DFL);
380 signal (SIGBUS , SIG_DFL);
381 signal (SIGINT , SIG_DFL);
382 signal (SIGTERM, SIG_DFL);
1054} 383}
1055 384
1056void 385void
1057help (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
1101void
1102init_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
1145void
1146init_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
1176void
1177compile_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
1238void
1239rec_sigsegv (int i)
1240{
1241 LOG (llevError, "SIGSEGV received.\n");
1242 fatal_signal (1, 1);
1243}
1244
1245void
1246rec_sigint (int i)
1247{
1248 LOG (llevInfo, "SIGINT received.\n");
1249 fatal_signal (0, 1);
1250}
1251
1252void
1253rec_sighup (int i)
1254{
1255 LOG (llevInfo, "SIGHUP received\n");
1256
1257 if (init_done)
1258 cleanup ();
1259
1260 exit (0);
1261}
1262
1263void
1264rec_sigquit (int i)
1265{
1266 LOG (llevInfo, "SIGQUIT received\n");
1267 fatal_signal (1, 1);
1268}
1269
1270void
1271rec_sigbus (int i)
1272{
1273#ifdef SIGBUS
1274 LOG (llevError, "SIGBUS received\n");
1275 fatal_signal (1, 1);
1276#endif
1277}
1278
1279void
1280rec_sigterm (int i)
1281{
1282 LOG (llevInfo, "SIGTERM received\n");
1283 fatal_signal (0, 1);
1284}
1285
1286void
1287fatal_signal (int make_core, int close_sockets)
1288{
1289 cleanup (make_core);
1290}
1291
1292void
1293init_signals (void) 386init_signals ()
1294{ 387{
1295 signal (SIGHUP, rec_sighup); 388 // large stack, but it's important data we want to save, and it is not usually
1296 signal (SIGINT, rec_sigint); 389 // being physically allocated anyways
1297 signal (SIGQUIT, rec_sigquit); 390 const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ;
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 391
1306/* init_races() - reads the races file in the lib/ directory, then 392 stack_t ss;
1307 * overwrites old 'race' entries. This routine allow us to quickly 393 ss.ss_sp = malloc (stacksize);
1308 * re-configure the 'alignment' of monsters, objects. Useful for 394 ss.ss_flags = 0;
1309 * putting together lists of creatures, etc that belong to gods. 395 ss.ss_size = stacksize;
1310 */ 396 sigaltstack (&ss, 0);
1311 397
1312void 398 struct sigaction sa;
1313init_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 399
1320 if (init_done) 400 sigfillset (&sa.sa_mask);
401 sa.sa_flags = SA_RESTART;
402
403 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
404 sa.sa_handler = rec_sigabrt; sigaction (SIGABRT, &sa, 0);
405 sa.sa_handler = rec_sigquit; sigaction (SIGQUIT, &sa, 0);
406 sa.sa_handler = rec_sigbus; sigaction (SIGBUS, &sa, 0);
407
408 sa.sa_flags |= SA_ONSTACK;
409 sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0);
410}
411
412static racelink *
413get_racelist ()
414{
415 racelink *list = new racelink;
416
417 list->name = 0;
418 list->nrof = 0;
419 list->next = 0;
420 list->member = get_objectlink ();
421
422 return list;
423}
424
425 racelink *
426find_racelink (const char *name)
427{
428 if (name)
429 for (racelink *link = first_race; link; link = link->next)
430 if (!link->name || !strcmp (name, link->name))
431 return link;
432
1321 return; 433 return 0;
1322 init_done = 1;
1323 first_race = 0;
1324
1325 sprintf (fname, "%s/races", settings.datadir);
1326 LOG (llevDebug, "Reading races from %s...", fname);
1327 if (!(file = fopen (fname, "r")))
1328 {
1329 LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno));
1330 return;
1331 }
1332
1333 while (fgets (buf, MAX_BUF, file) != NULL)
1334 {
1335 int set_race = 1, set_list = 1;
1336
1337 if (*buf == '#')
1338 continue;
1339
1340 if ((cp = strchr (buf, '\n')) != NULL)
1341 *cp = '\0';
1342
1343 cp = buf;
1344 while (*cp == ' ' || *cp == '!' || *cp == '@')
1345 {
1346 if (*cp == '!')
1347 set_race = 0;
1348 if (*cp == '@')
1349 set_list = 0;
1350 cp++;
1351 }
1352
1353 if (sscanf (cp, "RACE %s", variable))
1354 { /* set new race value */
1355 strcpy (race, variable);
1356 }
1357 else
1358 {
1359 char *cp1;
1360
1361 /* Take out beginning spaces */
1362 for (cp1 = cp; *cp1 == ' '; cp1++)
1363 ;
1364 /* Remove newline and trailing spaces */
1365 for (cp1 = cp + strlen (cp) - 1; *cp1 == '\n' || *cp1 == ' '; cp1--)
1366 {
1367 *cp1 = '\0';
1368 if (cp == cp1)
1369 break;
1370 }
1371
1372 if (cp[strlen (cp) - 1] == '\n')
1373 cp[strlen (cp) - 1] = '\0';
1374
1375 /* set creature race to race value */
1376 if ((mon = archetype::find (cp)) == NULL)
1377 LOG (llevError, "\nCreature %s in race file lacks archetype", cp);
1378 else
1379 {
1380 if (set_race && (!mon->clone.race || strcmp (mon->clone.race, race)))
1381 {
1382 if (mon->clone.race)
1383 LOG (llevDebug, "\n Resetting race to %s from %s for archetype %s", race, &mon->clone.race, &mon->name);
1384
1385 mon->clone.race = race;
1386 }
1387
1388 /* if the arch is a monster, add it to the race list */
1389 if (set_list && QUERY_FLAG (&mon->clone, FLAG_MONSTER))
1390 add_to_racelist (race, &mon->clone);
1391 }
1392 }
1393 }
1394
1395 fclose (file);
1396 LOG (llevDebug, "done.\n");
1397} 434}
1398 435
1399void 436static void
1400dump_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
1415void
1416add_to_racelist (const char *race_name, object *op) 437add_to_racelist (const char *race_name, object *op)
1417{ 438{
1418 racelink *race; 439 racelink *race;
1419 440
1420 if (!op || !race_name) 441 if (!op || !race_name)
1440 461
1441 race->nrof++; 462 race->nrof++;
1442 race->member->ob = op; 463 race->member->ob = op;
1443} 464}
1444 465
1445racelink * 466/* init_races() - reads the races file in the lib/ directory, then
1446get_racelist () 467 * overwrites old 'race' entries. This routine allow us to quickly
468 * re-configure the 'alignment' of monsters, objects. Useful for
469 * putting together lists of creatures, etc that belong to gods.
470 */
471static void
472init_races ()
1447{ 473{
1448 racelink *list = new racelink; 474 FILE *file;
475 char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF];
476 archetype *mon = NULL;
477 static int init_done = 0;
1449 478
1450 list->name = 0; 479 if (init_done)
1451 list->nrof = 0;
1452 list->next = 0;
1453 list->member = get_objectlink ();
1454
1455 return list;
1456}
1457
1458racelink *
1459find_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; 480 return;
481 init_done = 1;
482 first_race = 0;
483
484 sprintf (fname, "%s/races", settings.datadir);
485 LOG (llevDebug, "Reading races from %s...\n", fname);
486 if (!(file = fopen (fname, "r")))
487 {
488 LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno));
489 return;
490 }
491
492 while (fgets (buf, MAX_BUF, file) != NULL)
493 {
494 int set_race = 1, set_list = 1;
495
496 if (*buf == '#')
497 continue;
498
499 if ((cp = strchr (buf, '\n')) != NULL)
500 *cp = '\0';
501
502 cp = buf;
503 while (*cp == ' ' || *cp == '!' || *cp == '@')
504 {
505 if (*cp == '!') set_race = 0;
506 if (*cp == '@') set_list = 0;
507
508 cp++;
509 }
510
511 if (sscanf (cp, "RACE %s", variable))
512 /* set new race value */
513 strcpy (race, variable);
514 else
515 {
516 char *cp1;
517
518 /* Take out beginning spaces */
519 for (cp1 = cp; *cp1 == ' '; cp1++)
520 ;
521 /* Remove newline and trailing spaces */
522 for (cp1 = cp + strlen (cp) - 1; *cp1 == '\n' || *cp1 == ' '; cp1--)
523 {
524 *cp1 = '\0';
525 if (cp == cp1)
526 break;
527 }
528
529 if (cp[strlen (cp) - 1] == '\n')
530 cp[strlen (cp) - 1] = '\0';
531
532 /* set creature race to race value */
533 if ((mon = archetype::find (cp)) == NULL)
534 LOG (llevError, "Creature %s in race file lacks archetype\n", cp);
535 else
536 {
537 if (set_race && (!mon->race || strcmp (&mon->race, race)))
538 {
539 if (mon->race)
540 LOG (llevDebug, "Resetting race to %s from %s for archetype %s\n", race, &mon->race, &mon->archname);
541
542 mon->race = race;
543 }
544
545 /* if the arch is a monster, add it to the race list */
546 if (set_list && mon->flag [FLAG_MONSTER])
547 add_to_racelist (race, mon);
548 }
549 }
550 }
551
552 fclose (file);
553 LOG (llevDebug, "done.\n");
1467} 554}
555
556void
557init_beforeplay ()
558{
559 init_artifacts (); /* If not called before, reads all artifacts from file */
560 init_races (); /* overwrite race designations using entries in lib/races file */
561 init_gods (); /* init linked list of gods from archs */
562 init_readable (); /* inits useful arrays for readable texts */
563 init_formulae (); /* If not called before, reads formulae from file */
564}
565

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines