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.9 by root, Sun Sep 10 15:59:57 2006 UTC vs.
Revision 1.88 by root, Sat Nov 17 23:40:04 2018 UTC

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