ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/init.C
Revision: 1.14
Committed: Sat Sep 30 23:48:57 2006 UTC (17 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.13: +1 -0 lines
Log Message:
let perl use the correct directory stetings at startup

File Contents

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