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 | #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; |
… | |
… | |
241 | * 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. |
242 | */ |
238 | */ |
243 | struct Command_Line_Options options[] = { |
239 | struct Command_Line_Options options[] = { |
244 | |
240 | |
245 | /* 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 |
246 | * initialize any data. |
242 | * initialise any data. |
247 | */ |
243 | */ |
248 | {"-h", 0, 1, help}, |
244 | {"-h", 0, 1, help}, |
249 | |
245 | |
250 | /* Honor -help also, since it is somewhat common */ |
246 | /* Honor -help also, since it is somewhat common */ |
251 | {"-help", 0, 1, help}, |
247 | {"-help", 0, 1, help}, |
… | |
… | |
384 | FILE *fp; |
380 | FILE *fp; |
385 | materialtype_t *mt; |
381 | materialtype_t *mt; |
386 | int i, value; |
382 | int i, value; |
387 | |
383 | |
388 | sprintf (filename, "%s/materials", settings.datadir); |
384 | sprintf (filename, "%s/materials", settings.datadir); |
389 | LOG (llevDebug, "Reading material type data from %s...", filename); |
385 | LOG (llevDebug, "Reading material type data from %s...\n", filename); |
390 | if ((fp = fopen (filename, "r")) == NULL) |
386 | if ((fp = fopen (filename, "r")) == NULL) |
391 | { |
387 | { |
392 | LOG (llevError, "Cannot open %s for reading\n", filename); |
388 | LOG (llevError, "Cannot open %s for reading\n", filename); |
393 | mt = get_empty_mat (); |
389 | mt = get_empty_mat (); |
394 | mt->next = NULL; |
390 | mt->next = NULL; |
… | |
… | |
760 | else |
756 | else |
761 | { |
757 | { |
762 | 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); |
763 | } |
759 | } |
764 | } |
760 | } |
765 | else if (!strcasecmp (buf, "explore_mode")) |
|
|
766 | { |
|
|
767 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
768 | { |
|
|
769 | settings.explore_mode = TRUE; |
|
|
770 | } |
|
|
771 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
772 | { |
|
|
773 | settings.explore_mode = FALSE; |
|
|
774 | } |
|
|
775 | else |
|
|
776 | { |
|
|
777 | LOG (llevError, "load_settings: Unknown value for " "explore_mode: %s\n", cp); |
|
|
778 | } |
|
|
779 | } |
|
|
780 | else if (!strcasecmp (buf, "spellpoint_level_depend")) |
761 | else if (!strcasecmp (buf, "spellpoint_level_depend")) |
781 | { |
762 | { |
782 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
763 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
783 | { |
764 | { |
784 | settings.spellpoint_level_depend = TRUE; |
765 | settings.spellpoint_level_depend = TRUE; |
… | |
… | |
1006 | */ |
987 | */ |
1007 | |
988 | |
1008 | void |
989 | void |
1009 | init (int argc, char **argv) |
990 | init (int argc, char **argv) |
1010 | { |
991 | { |
|
|
992 | rndm.seed (time (0)); |
|
|
993 | |
1011 | init_done = 0; /* Must be done before init_signal() */ |
994 | init_done = 0; /* Must be done before init_signal() */ |
1012 | logfile = stderr; |
995 | logfile = stderr; |
1013 | 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 |
1014 | * nothing, but in future specifying the |
997 | * nothing, but in future specifying the |
1015 | * LibDir in this pass would be reasonable*/ |
998 | * LibDir in this pass would be reasonable*/ |
1016 | |
999 | |
1017 | cfperl_init (); |
1000 | cfperl_init (); |
1018 | init_library (); /* Must be called early */ |
1001 | init_library (); /* Must be called early */ |
1019 | load_settings (); /* Load the settings file */ |
1002 | load_settings (); /* Load the settings file */ |
1020 | init_weather (); |
|
|
1021 | load_materials (); |
1003 | load_materials (); |
1022 | parse_args (argc, argv, 2); |
1004 | parse_args (argc, argv, 2); |
1023 | fprintf (logfile, "Welcome to CrossFire, v%s\n", VERSION); |
1005 | fprintf (logfile, "Welcome to CrossFire, v%s\n", VERSION); |
|
|
1006 | fprintf (logfile, "Copyright (C) 2005, 2006, 2007 Marc Lehmann.\n"); |
1024 | fprintf (logfile, "Copyright (C) 1994 Mark Wedel.\n"); |
1007 | fprintf (logfile, "Copyright (C) 1994 Mark Wedel.\n"); |
1025 | fprintf (logfile, "Copyright (C) 1992 Frank Tore Johansen.\n"); |
1008 | fprintf (logfile, "Copyright (C) 1992 Frank Tore Johansen.\n"); |
1026 | |
1009 | |
1027 | if (strcmp (settings.dm_mail, "") != 0) |
1010 | if (strcmp (settings.dm_mail, "") != 0) |
1028 | { |
1011 | { |
1029 | fprintf (logfile, "Maintained locally by: %s\n", settings.dm_mail); |
1012 | fprintf (logfile, "Maintained locally by: %s\n", settings.dm_mail); |
1030 | 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"); |
1031 | } |
1014 | } |
1032 | |
1015 | |
1033 | SRANDOM (time (NULL)); |
|
|
1034 | |
|
|
1035 | init_startup (); /* Write (C), check shutdown/forbid files */ |
1016 | init_startup (); /* Write (C), check shutdown/forbid files */ |
1036 | init_uuid (); |
1017 | init_uuid (); |
1037 | init_signals (); /* Sets up signal interceptions */ |
1018 | init_signals (); /* Sets up signal interceptions */ |
1038 | init_commands (); /* Sort command tables */ |
1019 | init_commands (); /* Sort command tables */ |
1039 | read_map_log (); /* Load up the old temp map files */ |
|
|
1040 | init_skills (); |
1020 | init_skills (); |
1041 | |
1021 | |
1042 | parse_args (argc, argv, 3); |
1022 | parse_args (argc, argv, 3); |
1043 | |
1023 | |
1044 | if (settings.daemonmode) |
1024 | if (settings.daemonmode) |
… | |
… | |
1214 | printf ("Save player:\t<true>\n"); |
1194 | printf ("Save player:\t<true>\n"); |
1215 | printf ("Save mode:\t%4.4o\n", SAVE_MODE); |
1195 | printf ("Save mode:\t%4.4o\n", SAVE_MODE); |
1216 | printf ("Playerdir:\t<VAR>/%s\n", settings.playerdir); |
1196 | printf ("Playerdir:\t<VAR>/%s\n", settings.playerdir); |
1217 | printf ("Itemsdir:\t<VAR>/%s\n", settings.uniquedir); |
1197 | printf ("Itemsdir:\t<VAR>/%s\n", settings.uniquedir); |
1218 | printf ("Tmpdir:\t\t%s\n", settings.tmpdir); |
1198 | printf ("Tmpdir:\t\t%s\n", settings.tmpdir); |
1219 | printf ("Map max timeout:\t%d\n", MAP_MAXTIMEOUT); |
|
|
1220 | printf ("Max objects:\t%d\n", MAX_OBJECTS); |
|
|
1221 | #ifdef USE_CALLOC |
1199 | #ifdef USE_CALLOC |
1222 | printf ("Use_calloc:\t<true>\n"); |
1200 | printf ("Use_calloc:\t<true>\n"); |
1223 | #else |
1201 | #else |
1224 | printf ("Use_calloc:\t<false>\n"); |
1202 | printf ("Use_calloc:\t<false>\n"); |
1225 | #endif |
1203 | #endif |
… | |
… | |
1236 | } |
1214 | } |
1237 | |
1215 | |
1238 | /* Signal handlers: */ |
1216 | /* Signal handlers: */ |
1239 | |
1217 | |
1240 | 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 |
1241 | rec_sigsegv (int i) |
1228 | rec_sigsegv (int i) |
1242 | { |
1229 | { |
|
|
1230 | signal (SIGSEGV, SIG_DFL); |
|
|
1231 | |
1243 | LOG (llevError, "SIGSEGV received.\n"); |
1232 | LOG (llevError, "SIGSEGV received.\n"); |
1244 | fatal_signal (1, 1); |
1233 | cleanup ("SIGSEGV received", 1); |
1245 | } |
|
|
1246 | |
|
|
1247 | void |
|
|
1248 | rec_sigint (int i) |
|
|
1249 | { |
|
|
1250 | LOG (llevInfo, "SIGINT received.\n"); |
|
|
1251 | fatal_signal (0, 1); |
|
|
1252 | } |
|
|
1253 | |
|
|
1254 | void |
|
|
1255 | rec_sighup (int i) |
|
|
1256 | { |
|
|
1257 | LOG (llevInfo, "SIGHUP received\n"); |
|
|
1258 | |
|
|
1259 | if (init_done) |
|
|
1260 | cleanup (); |
|
|
1261 | |
|
|
1262 | exit (0); |
|
|
1263 | } |
1234 | } |
1264 | |
1235 | |
1265 | void |
1236 | void |
1266 | rec_sigquit (int i) |
1237 | rec_sigquit (int i) |
1267 | { |
1238 | { |
|
|
1239 | signal (SIGQUIT, SIG_IGN); |
|
|
1240 | |
1268 | LOG (llevInfo, "SIGQUIT received\n"); |
1241 | LOG (llevInfo, "SIGQUIT received\n"); |
1269 | fatal_signal (1, 1); |
1242 | cleanup ("SIGQUIT received", 1); |
1270 | } |
1243 | } |
1271 | |
1244 | |
1272 | void |
1245 | void |
1273 | rec_sigbus (int i) |
1246 | rec_sigbus (int i) |
1274 | { |
1247 | { |
1275 | #ifdef SIGBUS |
1248 | signal (SIGBUS, SIG_DFL); |
|
|
1249 | |
1276 | LOG (llevError, "SIGBUS received\n"); |
1250 | LOG (llevError, "SIGBUS received\n"); |
1277 | fatal_signal (1, 1); |
1251 | cleanup ("SIGBUS received", 1); |
1278 | #endif |
|
|
1279 | } |
|
|
1280 | |
|
|
1281 | void |
|
|
1282 | rec_sigterm (int i) |
|
|
1283 | { |
|
|
1284 | LOG (llevInfo, "SIGTERM received\n"); |
|
|
1285 | fatal_signal (0, 1); |
|
|
1286 | } |
|
|
1287 | |
|
|
1288 | void |
|
|
1289 | fatal_signal (int make_core, int close_sockets) |
|
|
1290 | { |
|
|
1291 | cleanup (make_core); |
|
|
1292 | } |
1252 | } |
1293 | |
1253 | |
1294 | void |
1254 | void |
1295 | init_signals (void) |
1255 | init_signals (void) |
1296 | { |
1256 | { |
1297 | signal (SIGHUP, rec_sighup); |
1257 | signal (SIGPIPE, SIG_IGN); |
1298 | signal (SIGINT, rec_sigint); |
1258 | signal (SIGABRT, rec_sigabrt); |
1299 | signal (SIGQUIT, rec_sigquit); |
1259 | signal (SIGQUIT, rec_sigquit); |
1300 | signal (SIGSEGV, rec_sigsegv); |
1260 | signal (SIGSEGV, rec_sigsegv); |
1301 | signal (SIGPIPE, SIG_IGN); |
|
|
1302 | #ifdef SIGBUS |
|
|
1303 | signal (SIGBUS, rec_sigbus); |
1261 | signal (SIGBUS, rec_sigbus); |
1304 | #endif |
|
|
1305 | signal (SIGTERM, rec_sigterm); |
|
|
1306 | } |
1262 | } |
1307 | |
1263 | |
1308 | /* init_races() - reads the races file in the lib/ directory, then |
1264 | /* init_races() - reads the races file in the lib/ directory, then |
1309 | * overwrites old 'race' entries. This routine allow us to quickly |
1265 | * overwrites old 'race' entries. This routine allow us to quickly |
1310 | * re-configure the 'alignment' of monsters, objects. Useful for |
1266 | * re-configure the 'alignment' of monsters, objects. Useful for |
1311 | * putting together lists of creatures, etc that belong to gods. |
1267 | * putting together lists of creatures, etc that belong to gods. |
1312 | */ |
1268 | */ |
1313 | |
|
|
1314 | void |
1269 | void |
1315 | init_races (void) |
1270 | init_races (void) |
1316 | { |
1271 | { |
1317 | FILE *file; |
1272 | FILE *file; |
1318 | 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]; |
… | |
… | |
1323 | return; |
1278 | return; |
1324 | init_done = 1; |
1279 | init_done = 1; |
1325 | first_race = 0; |
1280 | first_race = 0; |
1326 | |
1281 | |
1327 | sprintf (fname, "%s/races", settings.datadir); |
1282 | sprintf (fname, "%s/races", settings.datadir); |
1328 | LOG (llevDebug, "Reading races from %s...", fname); |
1283 | LOG (llevDebug, "Reading races from %s...\n", fname); |
1329 | if (!(file = fopen (fname, "r"))) |
1284 | if (!(file = fopen (fname, "r"))) |
1330 | { |
1285 | { |
1331 | LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno)); |
1286 | LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno)); |
1332 | return; |
1287 | return; |
1333 | } |
1288 | } |
… | |
… | |
1374 | if (cp[strlen (cp) - 1] == '\n') |
1329 | if (cp[strlen (cp) - 1] == '\n') |
1375 | cp[strlen (cp) - 1] = '\0'; |
1330 | cp[strlen (cp) - 1] = '\0'; |
1376 | |
1331 | |
1377 | /* set creature race to race value */ |
1332 | /* set creature race to race value */ |
1378 | if ((mon = archetype::find (cp)) == NULL) |
1333 | if ((mon = archetype::find (cp)) == NULL) |
1379 | LOG (llevError, "\nCreature %s in race file lacks archetype", cp); |
1334 | LOG (llevError, "Creature %s in race file lacks archetype\n", cp); |
1380 | else |
1335 | else |
1381 | { |
1336 | { |
1382 | if (set_race && (!mon->clone.race || strcmp (mon->clone.race, race))) |
1337 | if (set_race && (!mon->clone.race || strcmp (mon->clone.race, race))) |
1383 | { |
1338 | { |
1384 | if (mon->clone.race) |
1339 | if (mon->clone.race) |
1385 | LOG (llevDebug, "\n Resetting race to %s from %s for archetype %s", race, &mon->clone.race, &mon->name); |
1340 | LOG (llevDebug, "Resetting race to %s from %s for archetype %s\n", race, &mon->clone.race, &mon->name); |
1386 | |
1341 | |
1387 | mon->clone.race = race; |
1342 | mon->clone.race = race; |
1388 | } |
1343 | } |
1389 | |
1344 | |
1390 | /* if the arch is a monster, add it to the race list */ |
1345 | /* if the arch is a monster, add it to the race list */ |