1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * 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 | * 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 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #include <material.h> |
26 | #include <material.h> |
26 | #include <loader.h> |
27 | #include <loader.h> |
27 | #ifndef __CEXTRACT__ |
|
|
28 | # include <sproto.h> |
28 | #include <sproto.h> |
29 | #endif |
|
|
30 | |
|
|
31 | /* global weathermap */ |
|
|
32 | weathermap_t **weathermap; |
|
|
33 | |
29 | |
34 | void |
30 | void |
35 | set_logfile (char *val) |
31 | set_logfile (char *val) |
36 | { |
32 | { |
37 | settings.logfilename = val; |
33 | settings.logfilename = val; |
… | |
… | |
211 | |
207 | |
212 | void |
208 | void |
213 | set_csport (char *val) |
209 | set_csport (char *val) |
214 | { |
210 | { |
215 | settings.csport = atoi (val); |
211 | 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)) |
212 | if (settings.csport <= 0 || settings.csport > 32765 || (settings.csport < 1024 && getuid () != 0)) |
218 | { |
213 | { |
219 | LOG (llevError, "%d is an invalid csport number.\n", settings.csport); |
214 | LOG (llevError, "%d is an invalid csport number.\n", settings.csport); |
220 | exit (1); |
215 | exit (1); |
221 | } |
216 | } |
222 | #endif /* win32 */ |
|
|
223 | } |
217 | } |
224 | |
218 | |
225 | /* Most of this is shamelessly stolen from XSysStats. But since that is |
219 | /* Most of this is shamelessly stolen from XSysStats. But since that is |
226 | * also my program, no problem. |
220 | * also my program, no problem. |
227 | */ |
221 | */ |
… | |
… | |
243 | * pass system very easy, and it is very easy to add in new options. |
237 | * pass system very easy, and it is very easy to add in new options. |
244 | */ |
238 | */ |
245 | struct Command_Line_Options options[] = { |
239 | struct Command_Line_Options options[] = { |
246 | |
240 | |
247 | /* Pass 1 functions - STuff that can/should be called before we actually |
241 | /* Pass 1 functions - STuff that can/should be called before we actually |
248 | * initialize any data. |
242 | * initialise any data. |
249 | */ |
243 | */ |
250 | {"-h", 0, 1, help}, |
244 | {"-h", 0, 1, help}, |
251 | |
245 | |
252 | /* Honor -help also, since it is somewhat common */ |
246 | /* Honor -help also, since it is somewhat common */ |
253 | {"-help", 0, 1, help}, |
247 | {"-help", 0, 1, help}, |
… | |
… | |
265 | {"-treasures", 1, 1, (void (*)()) set_treasures}, |
259 | {"-treasures", 1, 1, (void (*)()) set_treasures}, |
266 | {"-uniquedir", 1, 1, (void (*)()) set_uniquedir}, |
260 | {"-uniquedir", 1, 1, (void (*)()) set_uniquedir}, |
267 | {"-templatedir", 1, 1, (void (*)()) set_templatedir}, |
261 | {"-templatedir", 1, 1, (void (*)()) set_templatedir}, |
268 | {"-tmpdir", 1, 1, (void (*)()) set_tmpdir}, |
262 | {"-tmpdir", 1, 1, (void (*)()) set_tmpdir}, |
269 | {"-log", 1, 1, (void (*)()) set_logfile}, |
263 | {"-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 | |
264 | |
279 | /* Pass 2 functions. Most of these could probably be in pass 1, |
265 | /* 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. |
266 | * as they don't require much of anything to bet set up. |
281 | */ |
267 | */ |
282 | {"-csport", 1, 2, (void (*)()) set_csport}, |
268 | {"-csport", 1, 2, (void (*)()) set_csport}, |
… | |
… | |
394 | FILE *fp; |
380 | FILE *fp; |
395 | materialtype_t *mt; |
381 | materialtype_t *mt; |
396 | int i, value; |
382 | int i, value; |
397 | |
383 | |
398 | sprintf (filename, "%s/materials", settings.datadir); |
384 | sprintf (filename, "%s/materials", settings.datadir); |
399 | LOG (llevDebug, "Reading material type data from %s...", filename); |
385 | LOG (llevDebug, "Reading material type data from %s...\n", filename); |
400 | if ((fp = fopen (filename, "r")) == NULL) |
386 | if ((fp = fopen (filename, "r")) == NULL) |
401 | { |
387 | { |
402 | LOG (llevError, "Cannot open %s for reading\n", filename); |
388 | LOG (llevError, "Cannot open %s for reading\n", filename); |
403 | mt = get_empty_mat (); |
389 | mt = get_empty_mat (); |
404 | mt->next = NULL; |
390 | mt->next = NULL; |
… | |
… | |
564 | { |
550 | { |
565 | cp = ""; |
551 | cp = ""; |
566 | has_val = 0; |
552 | has_val = 0; |
567 | } |
553 | } |
568 | |
554 | |
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")) |
555 | if (!strcasecmp (buf, "motd")) |
592 | { |
556 | { |
593 | if (has_val) |
557 | if (has_val) |
594 | strcpy (settings.motd, cp); |
558 | strcpy (settings.motd, cp); |
595 | else |
559 | else |
596 | LOG (llevError, "load_settings: motd must have a value.\n"); |
560 | LOG (llevError, "load_settings: motd must have a value.\n"); |
… | |
… | |
600 | if (has_val) |
564 | if (has_val) |
601 | strcpy (settings.dm_mail, cp); |
565 | strcpy (settings.dm_mail, cp); |
602 | else |
566 | else |
603 | LOG (llevError, "load_settings: dm_mail must have a value.\n"); |
567 | LOG (llevError, "load_settings: dm_mail must have a value.\n"); |
604 | } |
568 | } |
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")) |
569 | else if (!strcasecmp (buf, "worldmapstartx")) |
626 | { |
570 | { |
627 | int size = atoi (cp); |
571 | int size = atoi (cp); |
628 | |
572 | |
629 | if (size < 0) |
573 | if (size < 0) |
… | |
… | |
811 | } |
755 | } |
812 | else |
756 | else |
813 | { |
757 | { |
814 | LOG (llevError, "load_settings: Unknown value for " "real_wiz: %s\n", cp); |
758 | LOG (llevError, "load_settings: Unknown value for " "real_wiz: %s\n", cp); |
815 | } |
759 | } |
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 | } |
760 | } |
857 | else if (!strcasecmp (buf, "spellpoint_level_depend")) |
761 | else if (!strcasecmp (buf, "spellpoint_level_depend")) |
858 | { |
762 | { |
859 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
763 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
860 | { |
764 | { |
… | |
… | |
1071 | else |
975 | else |
1072 | { |
976 | { |
1073 | LOG (llevError, "Unknown value in settings file: %s\n", buf); |
977 | LOG (llevError, "Unknown value in settings file: %s\n", buf); |
1074 | } |
978 | } |
1075 | } |
979 | } |
|
|
980 | |
1076 | close_and_delete (fp, comp); |
981 | close_and_delete (fp, comp); |
1077 | } |
982 | } |
1078 | |
|
|
1079 | |
983 | |
1080 | /* |
984 | /* |
1081 | * init() is called only once, when starting the program. |
985 | * init() is called only once, when starting the program. |
1082 | */ |
986 | */ |
1083 | |
987 | |
1084 | void |
988 | void |
1085 | init (int argc, char **argv) |
989 | init (int argc, char **argv) |
1086 | { |
990 | { |
1087 | |
|
|
1088 | init_done = 0; /* Must be done before init_signal() */ |
991 | init_done = 0; /* Must be done before init_signal() */ |
|
|
992 | rndm.seed (time (0)); |
|
|
993 | |
1089 | logfile = stderr; |
994 | logfile = stderr; |
1090 | parse_args (argc, argv, 1); /* First arg pass - right now it does |
995 | parse_args (argc, argv, 1); /* First arg pass - right now it does |
1091 | * nothing, but in future specifying the |
996 | * nothing, but in future specifying the |
1092 | * LibDir in this pass would be reasonable*/ |
997 | * LibDir in this pass would be reasonable*/ |
1093 | |
998 | |
|
|
999 | cfperl_init (); |
1094 | init_library (); /* Must be called early */ |
1000 | init_library (); /* Must be called early */ |
1095 | load_settings (); /* Load the settings file */ |
1001 | load_settings (); /* Load the settings file */ |
1096 | init_weather (); |
|
|
1097 | load_materials (); |
1002 | load_materials (); |
1098 | parse_args (argc, argv, 2); |
1003 | parse_args (argc, argv, 2); |
1099 | fprintf (logfile, "Welcome to CrossFire, v%s\n", VERSION); |
1004 | fprintf (logfile, "Welcome to CrossFire, v%s\n", VERSION); |
|
|
1005 | fprintf (logfile, "Copyright (C) 2005, 2006, 2007 Marc Lehmann.\n"); |
1100 | fprintf (logfile, "Copyright (C) 1994 Mark Wedel.\n"); |
1006 | fprintf (logfile, "Copyright (C) 1994 Mark Wedel.\n"); |
1101 | fprintf (logfile, "Copyright (C) 1992 Frank Tore Johansen.\n"); |
1007 | fprintf (logfile, "Copyright (C) 1992 Frank Tore Johansen.\n"); |
1102 | |
1008 | |
1103 | if (strcmp (settings.dm_mail, "") != 0) |
1009 | if (strcmp (settings.dm_mail, "") != 0) |
1104 | { |
1010 | { |
1105 | fprintf (logfile, "Maintained locally by: %s\n", settings.dm_mail); |
1011 | fprintf (logfile, "Maintained locally by: %s\n", settings.dm_mail); |
1106 | fprintf (logfile, "Questions and bugs should be mailed to above address.\n"); |
1012 | fprintf (logfile, "Questions and bugs should be mailed to above address.\n"); |
1107 | } |
1013 | } |
1108 | SRANDOM (time (NULL)); |
|
|
1109 | |
1014 | |
1110 | init_startup (); /* Write (C), check shutdown/forbid files */ |
1015 | init_startup (); /* Write (C), check shutdown/forbid files */ |
|
|
1016 | init_uuid (); |
1111 | init_signals (); /* Sets up signal interceptions */ |
1017 | init_signals (); /* Sets up signal interceptions */ |
1112 | init_commands (); /* Sort command tables */ |
1018 | init_commands (); /* Sort command tables */ |
1113 | read_map_log (); /* Load up the old temp map files */ |
|
|
1114 | init_skills (); |
1019 | init_skills (); |
1115 | |
1020 | |
1116 | parse_args (argc, argv, 3); |
1021 | parse_args (argc, argv, 3); |
1117 | |
1022 | |
1118 | #ifndef WIN32 /* ***win32: no BecomeDaemon in windows */ |
|
|
1119 | if (settings.daemonmode) |
1023 | if (settings.daemonmode) |
1120 | logfile = BecomeDaemon (settings.logfilename[0] == '\0' ? "logfile" : settings.logfilename); |
1024 | logfile = BecomeDaemon (settings.logfilename[0] == '\0' ? "logfile" : settings.logfilename); |
1121 | #endif |
|
|
1122 | |
1025 | |
1123 | init_beforeplay (); |
1026 | init_beforeplay (); |
1124 | init_ericserver (); |
1027 | init_ericserver (); |
1125 | metaserver_init (); |
|
|
1126 | init_done = 1; |
1028 | init_done = 1; |
1127 | } |
1029 | } |
1128 | |
1030 | |
1129 | void |
1031 | void |
1130 | usage (void) |
1032 | usage (void) |
… | |
… | |
1291 | printf ("Save player:\t<true>\n"); |
1193 | printf ("Save player:\t<true>\n"); |
1292 | printf ("Save mode:\t%4.4o\n", SAVE_MODE); |
1194 | printf ("Save mode:\t%4.4o\n", SAVE_MODE); |
1293 | printf ("Playerdir:\t<VAR>/%s\n", settings.playerdir); |
1195 | printf ("Playerdir:\t<VAR>/%s\n", settings.playerdir); |
1294 | printf ("Itemsdir:\t<VAR>/%s\n", settings.uniquedir); |
1196 | printf ("Itemsdir:\t<VAR>/%s\n", settings.uniquedir); |
1295 | printf ("Tmpdir:\t\t%s\n", settings.tmpdir); |
1197 | printf ("Tmpdir:\t\t%s\n", settings.tmpdir); |
1296 | printf ("Map max timeout:\t%d\n", MAP_MAXTIMEOUT); |
|
|
1297 | printf ("Max objects:\t%d\n", MAX_OBJECTS); |
|
|
1298 | #ifdef USE_CALLOC |
1198 | #ifdef USE_CALLOC |
1299 | printf ("Use_calloc:\t<true>\n"); |
1199 | printf ("Use_calloc:\t<true>\n"); |
1300 | #else |
1200 | #else |
1301 | printf ("Use_calloc:\t<false>\n"); |
1201 | printf ("Use_calloc:\t<false>\n"); |
1302 | #endif |
1202 | #endif |
… | |
… | |
1305 | printf ("Editor:\t\t%s\n", X_EDITOR); |
1205 | printf ("Editor:\t\t%s\n", X_EDITOR); |
1306 | #endif |
1206 | #endif |
1307 | |
1207 | |
1308 | printf ("Max_time:\t%d\n", MAX_TIME); |
1208 | printf ("Max_time:\t%d\n", MAX_TIME); |
1309 | |
1209 | |
1310 | #ifdef WIN32 /* ***win32 compile_info(): remove execl... */ |
|
|
1311 | printf ("Logfilename:\t%s\n", settings.logfilename); |
|
|
1312 | exit (0); |
|
|
1313 | #else |
|
|
1314 | execl ("/bin/uname", "uname", "-a", NULL); |
1210 | execl ("/bin/uname", "uname", "-a", NULL); |
1315 | LOG (llevError, "Oops, shouldn't have gotten here: execl(/bin/uname) failed: %s\n", strerror (errno)); |
1211 | LOG (llevError, "Oops, shouldn't have gotten here: execl(/bin/uname) failed: %s\n", strerror (errno)); |
1316 | exit (-1); |
1212 | exit (-1); |
1317 | #endif |
|
|
1318 | } |
1213 | } |
1319 | |
1214 | |
1320 | /* Signal handlers: */ |
1215 | /* Signal handlers: */ |
1321 | |
1216 | |
1322 | void |
1217 | void |
|
|
1218 | rec_sigabrt (int i) |
|
|
1219 | { |
|
|
1220 | signal (SIGABRT, SIG_DFL); |
|
|
1221 | |
|
|
1222 | LOG (llevError, "SIGABRT received.\n"); |
|
|
1223 | cleanup ("SIGABRT received", 1); |
|
|
1224 | } |
|
|
1225 | |
|
|
1226 | void |
1323 | rec_sigsegv (int i) |
1227 | rec_sigsegv (int i) |
1324 | { |
1228 | { |
|
|
1229 | signal (SIGSEGV, SIG_DFL); |
|
|
1230 | |
1325 | LOG (llevError, "\nSIGSEGV received.\n"); |
1231 | LOG (llevError, "SIGSEGV received.\n"); |
1326 | fatal_signal (1, 1); |
1232 | cleanup ("SIGSEGV received", 1); |
1327 | } |
|
|
1328 | |
|
|
1329 | void |
|
|
1330 | rec_sigint (int i) |
|
|
1331 | { |
|
|
1332 | LOG (llevInfo, "\nSIGINT received.\n"); |
|
|
1333 | fatal_signal (0, 1); |
|
|
1334 | } |
|
|
1335 | |
|
|
1336 | void |
|
|
1337 | rec_sighup (int i) |
|
|
1338 | { |
|
|
1339 | LOG (llevInfo, "\nSIGHUP received\n"); |
|
|
1340 | if (init_done) |
|
|
1341 | { |
|
|
1342 | emergency_save (0); |
|
|
1343 | cleanup (); |
|
|
1344 | } |
|
|
1345 | exit (0); |
|
|
1346 | } |
1233 | } |
1347 | |
1234 | |
1348 | void |
1235 | void |
1349 | rec_sigquit (int i) |
1236 | rec_sigquit (int i) |
1350 | { |
1237 | { |
|
|
1238 | signal (SIGQUIT, SIG_IGN); |
|
|
1239 | |
1351 | LOG (llevInfo, "\nSIGQUIT received\n"); |
1240 | LOG (llevInfo, "SIGQUIT received\n"); |
1352 | fatal_signal (1, 1); |
1241 | cleanup ("SIGQUIT received", 1); |
1353 | } |
1242 | } |
1354 | |
1243 | |
1355 | void |
1244 | void |
1356 | rec_sigbus (int i) |
1245 | rec_sigbus (int i) |
1357 | { |
1246 | { |
1358 | #ifdef SIGBUS |
1247 | signal (SIGBUS, SIG_DFL); |
|
|
1248 | |
1359 | LOG (llevError, "\nSIGBUS received\n"); |
1249 | LOG (llevError, "SIGBUS received\n"); |
1360 | fatal_signal (1, 1); |
1250 | cleanup ("SIGBUS received", 1); |
1361 | #endif |
|
|
1362 | } |
|
|
1363 | |
|
|
1364 | void |
|
|
1365 | rec_sigterm (int i) |
|
|
1366 | { |
|
|
1367 | LOG (llevInfo, "\nSIGTERM received\n"); |
|
|
1368 | fatal_signal (0, 1); |
|
|
1369 | } |
|
|
1370 | |
|
|
1371 | void |
|
|
1372 | fatal_signal (int make_core, int close_sockets) |
|
|
1373 | { |
|
|
1374 | if (init_done) |
|
|
1375 | { |
|
|
1376 | emergency_save (0); |
|
|
1377 | clean_tmp_files (); |
|
|
1378 | } |
|
|
1379 | if (make_core) |
|
|
1380 | abort (); |
|
|
1381 | exit (0); |
|
|
1382 | } |
1251 | } |
1383 | |
1252 | |
1384 | void |
1253 | void |
1385 | init_signals (void) |
1254 | init_signals (void) |
1386 | { |
1255 | { |
1387 | #ifndef WIN32 /* init_signals() remove signals */ |
1256 | // large stack, but it's important data we want to save, and it is not usually |
1388 | signal (SIGHUP, rec_sighup); |
1257 | // being physically allocated anyways |
1389 | signal (SIGINT, rec_sigint); |
1258 | const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ; |
1390 | signal (SIGQUIT, rec_sigquit); |
1259 | |
1391 | signal (SIGSEGV, rec_sigsegv); |
1260 | stack_t ss; |
1392 | signal (SIGPIPE, SIG_IGN); |
1261 | ss.ss_sp = malloc (stacksize); |
1393 | # ifdef SIGBUS |
1262 | ss.ss_flags = 0; |
1394 | signal (SIGBUS, rec_sigbus); |
1263 | ss.ss_size = stacksize; |
1395 | # endif |
1264 | sigaltstack (&ss, 0); |
1396 | signal (SIGTERM, rec_sigterm); |
1265 | |
1397 | #endif |
1266 | struct sigaction sa; |
|
|
1267 | |
|
|
1268 | sigfillset (&sa.sa_mask); |
|
|
1269 | sa.sa_flags = SA_ONSTACK | SA_RESTART; |
|
|
1270 | |
|
|
1271 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
|
|
1272 | sa.sa_handler = rec_sigabrt; sigaction (SIGABRT, &sa, 0); |
|
|
1273 | sa.sa_handler = rec_sigquit; sigaction (SIGQUIT, &sa, 0); |
|
|
1274 | sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0); |
|
|
1275 | sa.sa_handler = rec_sigbus; sigaction (SIGBUS, &sa, 0); |
1398 | } |
1276 | } |
1399 | |
1277 | |
1400 | /* init_races() - reads the races file in the lib/ directory, then |
1278 | /* init_races() - reads the races file in the lib/ directory, then |
1401 | * overwrites old 'race' entries. This routine allow us to quickly |
1279 | * overwrites old 'race' entries. This routine allow us to quickly |
1402 | * re-configure the 'alignment' of monsters, objects. Useful for |
1280 | * re-configure the 'alignment' of monsters, objects. Useful for |
1403 | * putting together lists of creatures, etc that belong to gods. |
1281 | * putting together lists of creatures, etc that belong to gods. |
1404 | */ |
1282 | */ |
1405 | |
|
|
1406 | void |
1283 | void |
1407 | init_races (void) |
1284 | init_races (void) |
1408 | { |
1285 | { |
1409 | FILE *file; |
1286 | FILE *file; |
1410 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
1287 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
… | |
… | |
1415 | return; |
1292 | return; |
1416 | init_done = 1; |
1293 | init_done = 1; |
1417 | first_race = 0; |
1294 | first_race = 0; |
1418 | |
1295 | |
1419 | sprintf (fname, "%s/races", settings.datadir); |
1296 | sprintf (fname, "%s/races", settings.datadir); |
1420 | LOG (llevDebug, "Reading races from %s...", fname); |
1297 | LOG (llevDebug, "Reading races from %s...\n", fname); |
1421 | if (!(file = fopen (fname, "r"))) |
1298 | if (!(file = fopen (fname, "r"))) |
1422 | { |
1299 | { |
1423 | LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno)); |
1300 | LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno)); |
1424 | return; |
1301 | return; |
1425 | } |
1302 | } |
… | |
… | |
1465 | |
1342 | |
1466 | if (cp[strlen (cp) - 1] == '\n') |
1343 | if (cp[strlen (cp) - 1] == '\n') |
1467 | cp[strlen (cp) - 1] = '\0'; |
1344 | cp[strlen (cp) - 1] = '\0'; |
1468 | |
1345 | |
1469 | /* set creature race to race value */ |
1346 | /* set creature race to race value */ |
1470 | if ((mon = find_archetype (cp)) == NULL) |
1347 | if ((mon = archetype::find (cp)) == NULL) |
1471 | LOG (llevError, "\nCreature %s in race file lacks archetype", cp); |
1348 | LOG (llevError, "Creature %s in race file lacks archetype\n", cp); |
1472 | else |
1349 | else |
1473 | { |
1350 | { |
1474 | if (set_race && (!mon->clone.race || strcmp (mon->clone.race, race))) |
1351 | if (set_race && (!mon->clone.race || strcmp (mon->clone.race, race))) |
1475 | { |
1352 | { |
1476 | if (mon->clone.race) |
1353 | if (mon->clone.race) |
1477 | LOG (llevDebug, "\n Resetting race to %s from %s for archetype %s", race, &mon->clone.race, &mon->name); |
1354 | LOG (llevDebug, "Resetting race to %s from %s for archetype %s\n", race, &mon->clone.race, &mon->name); |
1478 | |
1355 | |
1479 | mon->clone.race = race; |
1356 | mon->clone.race = race; |
1480 | } |
1357 | } |
1481 | |
1358 | |
1482 | /* if the arch is a monster, add it to the race list */ |
1359 | /* if the arch is a monster, add it to the race list */ |