… | |
… | |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <material.h> |
25 | #include <material.h> |
26 | #include <loader.h> |
26 | #include <loader.h> |
27 | #ifndef __CEXTRACT__ |
|
|
28 | # include <sproto.h> |
27 | #include <sproto.h> |
29 | #endif |
|
|
30 | |
|
|
31 | /* global weathermap */ |
|
|
32 | weathermap_t **weathermap; |
|
|
33 | |
28 | |
34 | void |
29 | void |
35 | set_logfile (char *val) |
30 | set_logfile (char *val) |
36 | { |
31 | { |
37 | settings.logfilename = val; |
32 | settings.logfilename = val; |
… | |
… | |
241 | * pass system very easy, and it is very easy to add in new options. |
236 | * pass system very easy, and it is very easy to add in new options. |
242 | */ |
237 | */ |
243 | struct Command_Line_Options options[] = { |
238 | struct Command_Line_Options options[] = { |
244 | |
239 | |
245 | /* Pass 1 functions - STuff that can/should be called before we actually |
240 | /* Pass 1 functions - STuff that can/should be called before we actually |
246 | * initialize any data. |
241 | * initialise any data. |
247 | */ |
242 | */ |
248 | {"-h", 0, 1, help}, |
243 | {"-h", 0, 1, help}, |
249 | |
244 | |
250 | /* Honor -help also, since it is somewhat common */ |
245 | /* Honor -help also, since it is somewhat common */ |
251 | {"-help", 0, 1, help}, |
246 | {"-help", 0, 1, help}, |
… | |
… | |
384 | FILE *fp; |
379 | FILE *fp; |
385 | materialtype_t *mt; |
380 | materialtype_t *mt; |
386 | int i, value; |
381 | int i, value; |
387 | |
382 | |
388 | sprintf (filename, "%s/materials", settings.datadir); |
383 | sprintf (filename, "%s/materials", settings.datadir); |
389 | LOG (llevDebug, "Reading material type data from %s...", filename); |
384 | LOG (llevDebug, "Reading material type data from %s...\n", filename); |
390 | if ((fp = fopen (filename, "r")) == NULL) |
385 | if ((fp = fopen (filename, "r")) == NULL) |
391 | { |
386 | { |
392 | LOG (llevError, "Cannot open %s for reading\n", filename); |
387 | LOG (llevError, "Cannot open %s for reading\n", filename); |
393 | mt = get_empty_mat (); |
388 | mt = get_empty_mat (); |
394 | mt->next = NULL; |
389 | mt->next = NULL; |
… | |
… | |
1015 | * LibDir in this pass would be reasonable*/ |
1010 | * LibDir in this pass would be reasonable*/ |
1016 | |
1011 | |
1017 | cfperl_init (); |
1012 | cfperl_init (); |
1018 | init_library (); /* Must be called early */ |
1013 | init_library (); /* Must be called early */ |
1019 | load_settings (); /* Load the settings file */ |
1014 | load_settings (); /* Load the settings file */ |
1020 | init_weather (); |
|
|
1021 | load_materials (); |
1015 | load_materials (); |
1022 | parse_args (argc, argv, 2); |
1016 | parse_args (argc, argv, 2); |
1023 | fprintf (logfile, "Welcome to CrossFire, v%s\n", VERSION); |
1017 | fprintf (logfile, "Welcome to CrossFire, v%s\n", VERSION); |
|
|
1018 | fprintf (logfile, "Copyright (C) 2005, 2006, 2007 Marc Lehmann.\n"); |
1024 | fprintf (logfile, "Copyright (C) 1994 Mark Wedel.\n"); |
1019 | fprintf (logfile, "Copyright (C) 1994 Mark Wedel.\n"); |
1025 | fprintf (logfile, "Copyright (C) 1992 Frank Tore Johansen.\n"); |
1020 | fprintf (logfile, "Copyright (C) 1992 Frank Tore Johansen.\n"); |
1026 | |
1021 | |
1027 | if (strcmp (settings.dm_mail, "") != 0) |
1022 | if (strcmp (settings.dm_mail, "") != 0) |
1028 | { |
1023 | { |
… | |
… | |
1034 | |
1029 | |
1035 | init_startup (); /* Write (C), check shutdown/forbid files */ |
1030 | init_startup (); /* Write (C), check shutdown/forbid files */ |
1036 | init_uuid (); |
1031 | init_uuid (); |
1037 | init_signals (); /* Sets up signal interceptions */ |
1032 | init_signals (); /* Sets up signal interceptions */ |
1038 | init_commands (); /* Sort command tables */ |
1033 | init_commands (); /* Sort command tables */ |
1039 | read_map_log (); /* Load up the old temp map files */ |
|
|
1040 | init_skills (); |
1034 | init_skills (); |
1041 | |
1035 | |
1042 | parse_args (argc, argv, 3); |
1036 | parse_args (argc, argv, 3); |
1043 | |
1037 | |
1044 | if (settings.daemonmode) |
1038 | if (settings.daemonmode) |
… | |
… | |
1214 | printf ("Save player:\t<true>\n"); |
1208 | printf ("Save player:\t<true>\n"); |
1215 | printf ("Save mode:\t%4.4o\n", SAVE_MODE); |
1209 | printf ("Save mode:\t%4.4o\n", SAVE_MODE); |
1216 | printf ("Playerdir:\t<VAR>/%s\n", settings.playerdir); |
1210 | printf ("Playerdir:\t<VAR>/%s\n", settings.playerdir); |
1217 | printf ("Itemsdir:\t<VAR>/%s\n", settings.uniquedir); |
1211 | printf ("Itemsdir:\t<VAR>/%s\n", settings.uniquedir); |
1218 | printf ("Tmpdir:\t\t%s\n", settings.tmpdir); |
1212 | 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 |
1213 | #ifdef USE_CALLOC |
1222 | printf ("Use_calloc:\t<true>\n"); |
1214 | printf ("Use_calloc:\t<true>\n"); |
1223 | #else |
1215 | #else |
1224 | printf ("Use_calloc:\t<false>\n"); |
1216 | printf ("Use_calloc:\t<false>\n"); |
1225 | #endif |
1217 | #endif |
… | |
… | |
1239 | |
1231 | |
1240 | void |
1232 | void |
1241 | rec_sigsegv (int i) |
1233 | rec_sigsegv (int i) |
1242 | { |
1234 | { |
1243 | LOG (llevError, "SIGSEGV received.\n"); |
1235 | LOG (llevError, "SIGSEGV received.\n"); |
1244 | fatal_signal (1, 1); |
1236 | cleanup ("SIGSEGV received", 1); |
1245 | } |
1237 | } |
1246 | |
1238 | |
1247 | void |
1239 | void |
1248 | rec_sigint (int i) |
1240 | rec_sigint (int i) |
1249 | { |
1241 | { |
1250 | LOG (llevInfo, "SIGINT received.\n"); |
1242 | LOG (llevInfo, "SIGINT received.\n"); |
1251 | fatal_signal (0, 1); |
1243 | cleanup ("SIGINT received", 0); |
1252 | } |
1244 | } |
1253 | |
1245 | |
1254 | void |
1246 | void |
1255 | rec_sighup (int i) |
1247 | rec_sighup (int i) |
1256 | { |
1248 | { |
1257 | LOG (llevInfo, "SIGHUP received\n"); |
1249 | LOG (llevInfo, "SIGHUP received\n"); |
1258 | |
1250 | |
1259 | if (init_done) |
1251 | cleanup ("SIGHUP received", 0); |
1260 | cleanup (); |
|
|
1261 | |
|
|
1262 | exit (0); |
|
|
1263 | } |
1252 | } |
1264 | |
1253 | |
1265 | void |
1254 | void |
1266 | rec_sigquit (int i) |
1255 | rec_sigquit (int i) |
1267 | { |
1256 | { |
1268 | LOG (llevInfo, "SIGQUIT received\n"); |
1257 | LOG (llevInfo, "SIGQUIT received\n"); |
1269 | fatal_signal (1, 1); |
1258 | cleanup ("SIGQUIT received", 1); |
1270 | } |
1259 | } |
1271 | |
1260 | |
1272 | void |
1261 | void |
1273 | rec_sigbus (int i) |
1262 | rec_sigbus (int i) |
1274 | { |
1263 | { |
1275 | #ifdef SIGBUS |
|
|
1276 | LOG (llevError, "SIGBUS received\n"); |
1264 | LOG (llevError, "SIGBUS received\n"); |
1277 | fatal_signal (1, 1); |
1265 | cleanup ("SIGBUS received", 1); |
1278 | #endif |
|
|
1279 | } |
1266 | } |
1280 | |
1267 | |
1281 | void |
1268 | void |
1282 | rec_sigterm (int i) |
1269 | rec_sigterm (int i) |
1283 | { |
1270 | { |
1284 | LOG (llevInfo, "SIGTERM received\n"); |
1271 | LOG (llevInfo, "SIGTERM received\n"); |
1285 | fatal_signal (0, 1); |
1272 | cleanup ("SIGTERM received", 0); |
1286 | } |
|
|
1287 | |
|
|
1288 | void |
|
|
1289 | fatal_signal (int make_core, int close_sockets) |
|
|
1290 | { |
|
|
1291 | cleanup (make_core); |
|
|
1292 | } |
1273 | } |
1293 | |
1274 | |
1294 | void |
1275 | void |
1295 | init_signals (void) |
1276 | init_signals (void) |
1296 | { |
1277 | { |
|
|
1278 | signal (SIGPIPE, SIG_IGN); |
1297 | signal (SIGHUP, rec_sighup); |
1279 | signal (SIGHUP, rec_sighup); |
1298 | signal (SIGINT, rec_sigint); |
1280 | signal (SIGINT, rec_sigint); |
1299 | signal (SIGQUIT, rec_sigquit); |
1281 | signal (SIGQUIT, rec_sigquit); |
1300 | signal (SIGSEGV, rec_sigsegv); |
1282 | signal (SIGSEGV, rec_sigsegv); |
1301 | signal (SIGPIPE, SIG_IGN); |
|
|
1302 | #ifdef SIGBUS |
|
|
1303 | signal (SIGBUS, rec_sigbus); |
1283 | signal (SIGBUS, rec_sigbus); |
1304 | #endif |
|
|
1305 | signal (SIGTERM, rec_sigterm); |
1284 | signal (SIGTERM, rec_sigterm); |
1306 | } |
1285 | } |
1307 | |
1286 | |
1308 | /* init_races() - reads the races file in the lib/ directory, then |
1287 | /* init_races() - reads the races file in the lib/ directory, then |
1309 | * overwrites old 'race' entries. This routine allow us to quickly |
1288 | * overwrites old 'race' entries. This routine allow us to quickly |
1310 | * re-configure the 'alignment' of monsters, objects. Useful for |
1289 | * re-configure the 'alignment' of monsters, objects. Useful for |
1311 | * putting together lists of creatures, etc that belong to gods. |
1290 | * putting together lists of creatures, etc that belong to gods. |
1312 | */ |
1291 | */ |
1313 | |
|
|
1314 | void |
1292 | void |
1315 | init_races (void) |
1293 | init_races (void) |
1316 | { |
1294 | { |
1317 | FILE *file; |
1295 | FILE *file; |
1318 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
1296 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
… | |
… | |
1323 | return; |
1301 | return; |
1324 | init_done = 1; |
1302 | init_done = 1; |
1325 | first_race = 0; |
1303 | first_race = 0; |
1326 | |
1304 | |
1327 | sprintf (fname, "%s/races", settings.datadir); |
1305 | sprintf (fname, "%s/races", settings.datadir); |
1328 | LOG (llevDebug, "Reading races from %s...", fname); |
1306 | LOG (llevDebug, "Reading races from %s...\n", fname); |
1329 | if (!(file = fopen (fname, "r"))) |
1307 | if (!(file = fopen (fname, "r"))) |
1330 | { |
1308 | { |
1331 | LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno)); |
1309 | LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno)); |
1332 | return; |
1310 | return; |
1333 | } |
1311 | } |
… | |
… | |
1374 | if (cp[strlen (cp) - 1] == '\n') |
1352 | if (cp[strlen (cp) - 1] == '\n') |
1375 | cp[strlen (cp) - 1] = '\0'; |
1353 | cp[strlen (cp) - 1] = '\0'; |
1376 | |
1354 | |
1377 | /* set creature race to race value */ |
1355 | /* set creature race to race value */ |
1378 | if ((mon = archetype::find (cp)) == NULL) |
1356 | if ((mon = archetype::find (cp)) == NULL) |
1379 | LOG (llevError, "\nCreature %s in race file lacks archetype", cp); |
1357 | LOG (llevError, "Creature %s in race file lacks archetype\n", cp); |
1380 | else |
1358 | else |
1381 | { |
1359 | { |
1382 | if (set_race && (!mon->clone.race || strcmp (mon->clone.race, race))) |
1360 | if (set_race && (!mon->clone.race || strcmp (mon->clone.race, race))) |
1383 | { |
1361 | { |
1384 | if (mon->clone.race) |
1362 | if (mon->clone.race) |
1385 | LOG (llevDebug, "\n Resetting race to %s from %s for archetype %s", race, &mon->clone.race, &mon->name); |
1363 | LOG (llevDebug, "Resetting race to %s from %s for archetype %s\n", race, &mon->clone.race, &mon->name); |
1386 | |
1364 | |
1387 | mon->clone.race = race; |
1365 | mon->clone.race = race; |
1388 | } |
1366 | } |
1389 | |
1367 | |
1390 | /* if the arch is a monster, add it to the race list */ |
1368 | /* if the arch is a monster, add it to the race list */ |