1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
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@schmorp.de> |
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 | #include <sproto.h> |
28 | #include <sproto.h> |
… | |
… | |
755 | else |
756 | else |
756 | { |
757 | { |
757 | 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); |
758 | } |
759 | } |
759 | } |
760 | } |
760 | else if (!strcasecmp (buf, "explore_mode")) |
|
|
761 | { |
|
|
762 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
763 | { |
|
|
764 | settings.explore_mode = TRUE; |
|
|
765 | } |
|
|
766 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
767 | { |
|
|
768 | settings.explore_mode = FALSE; |
|
|
769 | } |
|
|
770 | else |
|
|
771 | { |
|
|
772 | LOG (llevError, "load_settings: Unknown value for " "explore_mode: %s\n", cp); |
|
|
773 | } |
|
|
774 | } |
|
|
775 | else if (!strcasecmp (buf, "spellpoint_level_depend")) |
761 | else if (!strcasecmp (buf, "spellpoint_level_depend")) |
776 | { |
762 | { |
777 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
763 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
778 | { |
764 | { |
779 | settings.spellpoint_level_depend = TRUE; |
765 | settings.spellpoint_level_depend = TRUE; |
… | |
… | |
1001 | */ |
987 | */ |
1002 | |
988 | |
1003 | void |
989 | void |
1004 | init (int argc, char **argv) |
990 | init (int argc, char **argv) |
1005 | { |
991 | { |
|
|
992 | rndm.seed (time (0)); |
|
|
993 | |
1006 | init_done = 0; /* Must be done before init_signal() */ |
994 | init_done = 0; /* Must be done before init_signal() */ |
1007 | logfile = stderr; |
995 | logfile = stderr; |
1008 | parse_args (argc, argv, 1); /* First arg pass - right now it does |
996 | parse_args (argc, argv, 1); /* First arg pass - right now it does |
1009 | * nothing, but in future specifying the |
997 | * nothing, but in future specifying the |
1010 | * LibDir in this pass would be reasonable*/ |
998 | * LibDir in this pass would be reasonable*/ |
… | |
… | |
1022 | if (strcmp (settings.dm_mail, "") != 0) |
1010 | if (strcmp (settings.dm_mail, "") != 0) |
1023 | { |
1011 | { |
1024 | fprintf (logfile, "Maintained locally by: %s\n", settings.dm_mail); |
1012 | fprintf (logfile, "Maintained locally by: %s\n", settings.dm_mail); |
1025 | fprintf (logfile, "Questions and bugs should be mailed to above address.\n"); |
1013 | fprintf (logfile, "Questions and bugs should be mailed to above address.\n"); |
1026 | } |
1014 | } |
1027 | |
|
|
1028 | SRANDOM (time (NULL)); |
|
|
1029 | |
1015 | |
1030 | init_startup (); /* Write (C), check shutdown/forbid files */ |
1016 | init_startup (); /* Write (C), check shutdown/forbid files */ |
1031 | init_uuid (); |
1017 | init_uuid (); |
1032 | init_signals (); /* Sets up signal interceptions */ |
1018 | init_signals (); /* Sets up signal interceptions */ |
1033 | init_commands (); /* Sort command tables */ |
1019 | init_commands (); /* Sort command tables */ |
… | |
… | |
1228 | } |
1214 | } |
1229 | |
1215 | |
1230 | /* Signal handlers: */ |
1216 | /* Signal handlers: */ |
1231 | |
1217 | |
1232 | void |
1218 | void |
|
|
1219 | rec_sigabrt (int i) |
|
|
1220 | { |
|
|
1221 | signal (SIGABRT, SIG_DFL); |
|
|
1222 | |
|
|
1223 | LOG (llevError, "SIGABRT received.\n"); |
|
|
1224 | cleanup ("SIGABRT received", 1); |
|
|
1225 | } |
|
|
1226 | |
|
|
1227 | void |
1233 | rec_sigsegv (int i) |
1228 | rec_sigsegv (int i) |
1234 | { |
1229 | { |
|
|
1230 | signal (SIGSEGV, SIG_DFL); |
|
|
1231 | |
1235 | LOG (llevError, "SIGSEGV received.\n"); |
1232 | LOG (llevError, "SIGSEGV received.\n"); |
1236 | fatal_signal (1, 1); |
1233 | cleanup ("SIGSEGV received", 1); |
1237 | } |
|
|
1238 | |
|
|
1239 | void |
|
|
1240 | rec_sigint (int i) |
|
|
1241 | { |
|
|
1242 | LOG (llevInfo, "SIGINT received.\n"); |
|
|
1243 | fatal_signal (0, 1); |
|
|
1244 | } |
|
|
1245 | |
|
|
1246 | void |
|
|
1247 | rec_sighup (int i) |
|
|
1248 | { |
|
|
1249 | LOG (llevInfo, "SIGHUP received\n"); |
|
|
1250 | |
|
|
1251 | if (init_done) |
|
|
1252 | cleanup (0); |
|
|
1253 | |
|
|
1254 | exit (0); |
|
|
1255 | } |
1234 | } |
1256 | |
1235 | |
1257 | void |
1236 | void |
1258 | rec_sigquit (int i) |
1237 | rec_sigquit (int i) |
1259 | { |
1238 | { |
|
|
1239 | signal (SIGQUIT, SIG_IGN); |
|
|
1240 | |
1260 | LOG (llevInfo, "SIGQUIT received\n"); |
1241 | LOG (llevInfo, "SIGQUIT received\n"); |
1261 | fatal_signal (1, 1); |
1242 | cleanup ("SIGQUIT received", 1); |
1262 | } |
1243 | } |
1263 | |
1244 | |
1264 | void |
1245 | void |
1265 | rec_sigbus (int i) |
1246 | rec_sigbus (int i) |
1266 | { |
1247 | { |
1267 | #ifdef SIGBUS |
1248 | signal (SIGBUS, SIG_DFL); |
|
|
1249 | |
1268 | LOG (llevError, "SIGBUS received\n"); |
1250 | LOG (llevError, "SIGBUS received\n"); |
1269 | fatal_signal (1, 1); |
1251 | cleanup ("SIGBUS received", 1); |
1270 | #endif |
|
|
1271 | } |
|
|
1272 | |
|
|
1273 | void |
|
|
1274 | rec_sigterm (int i) |
|
|
1275 | { |
|
|
1276 | LOG (llevInfo, "SIGTERM received\n"); |
|
|
1277 | fatal_signal (0, 1); |
|
|
1278 | } |
|
|
1279 | |
|
|
1280 | void |
|
|
1281 | fatal_signal (int make_core, int close_sockets) |
|
|
1282 | { |
|
|
1283 | cleanup (make_core); |
|
|
1284 | } |
1252 | } |
1285 | |
1253 | |
1286 | void |
1254 | void |
1287 | init_signals (void) |
1255 | init_signals (void) |
1288 | { |
1256 | { |
1289 | signal (SIGHUP, rec_sighup); |
1257 | signal (SIGPIPE, SIG_IGN); |
1290 | signal (SIGINT, rec_sigint); |
1258 | signal (SIGABRT, rec_sigabrt); |
1291 | signal (SIGQUIT, rec_sigquit); |
1259 | signal (SIGQUIT, rec_sigquit); |
1292 | signal (SIGSEGV, rec_sigsegv); |
1260 | signal (SIGSEGV, rec_sigsegv); |
1293 | signal (SIGPIPE, SIG_IGN); |
|
|
1294 | #ifdef SIGBUS |
|
|
1295 | signal (SIGBUS, rec_sigbus); |
1261 | signal (SIGBUS, rec_sigbus); |
1296 | #endif |
|
|
1297 | signal (SIGTERM, rec_sigterm); |
|
|
1298 | } |
1262 | } |
1299 | |
1263 | |
1300 | /* init_races() - reads the races file in the lib/ directory, then |
1264 | /* init_races() - reads the races file in the lib/ directory, then |
1301 | * overwrites old 'race' entries. This routine allow us to quickly |
1265 | * overwrites old 'race' entries. This routine allow us to quickly |
1302 | * re-configure the 'alignment' of monsters, objects. Useful for |
1266 | * re-configure the 'alignment' of monsters, objects. Useful for |
1303 | * putting together lists of creatures, etc that belong to gods. |
1267 | * putting together lists of creatures, etc that belong to gods. |
1304 | */ |
1268 | */ |
1305 | |
|
|
1306 | void |
1269 | void |
1307 | init_races (void) |
1270 | init_races (void) |
1308 | { |
1271 | { |
1309 | FILE *file; |
1272 | FILE *file; |
1310 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
1273 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |