… | |
… | |
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; |
… | |
… | |
211 | |
206 | |
212 | void |
207 | void |
213 | set_csport (char *val) |
208 | set_csport (char *val) |
214 | { |
209 | { |
215 | settings.csport = atoi (val); |
210 | 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)) |
211 | if (settings.csport <= 0 || settings.csport > 32765 || (settings.csport < 1024 && getuid () != 0)) |
218 | { |
212 | { |
219 | LOG (llevError, "%d is an invalid csport number.\n", settings.csport); |
213 | LOG (llevError, "%d is an invalid csport number.\n", settings.csport); |
220 | exit (1); |
214 | exit (1); |
221 | } |
215 | } |
222 | #endif /* win32 */ |
|
|
223 | } |
216 | } |
224 | |
217 | |
225 | /* Most of this is shamelessly stolen from XSysStats. But since that is |
218 | /* Most of this is shamelessly stolen from XSysStats. But since that is |
226 | * also my program, no problem. |
219 | * also my program, no problem. |
227 | */ |
220 | */ |
… | |
… | |
243 | * 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. |
244 | */ |
237 | */ |
245 | struct Command_Line_Options options[] = { |
238 | struct Command_Line_Options options[] = { |
246 | |
239 | |
247 | /* 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 |
248 | * initialize any data. |
241 | * initialise any data. |
249 | */ |
242 | */ |
250 | {"-h", 0, 1, help}, |
243 | {"-h", 0, 1, help}, |
251 | |
244 | |
252 | /* Honor -help also, since it is somewhat common */ |
245 | /* Honor -help also, since it is somewhat common */ |
253 | {"-help", 0, 1, help}, |
246 | {"-help", 0, 1, help}, |
… | |
… | |
265 | {"-treasures", 1, 1, (void (*)()) set_treasures}, |
258 | {"-treasures", 1, 1, (void (*)()) set_treasures}, |
266 | {"-uniquedir", 1, 1, (void (*)()) set_uniquedir}, |
259 | {"-uniquedir", 1, 1, (void (*)()) set_uniquedir}, |
267 | {"-templatedir", 1, 1, (void (*)()) set_templatedir}, |
260 | {"-templatedir", 1, 1, (void (*)()) set_templatedir}, |
268 | {"-tmpdir", 1, 1, (void (*)()) set_tmpdir}, |
261 | {"-tmpdir", 1, 1, (void (*)()) set_tmpdir}, |
269 | {"-log", 1, 1, (void (*)()) set_logfile}, |
262 | {"-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 | |
263 | |
279 | /* Pass 2 functions. Most of these could probably be in pass 1, |
264 | /* 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. |
265 | * as they don't require much of anything to bet set up. |
281 | */ |
266 | */ |
282 | {"-csport", 1, 2, (void (*)()) set_csport}, |
267 | {"-csport", 1, 2, (void (*)()) set_csport}, |
… | |
… | |
394 | FILE *fp; |
379 | FILE *fp; |
395 | materialtype_t *mt; |
380 | materialtype_t *mt; |
396 | int i, value; |
381 | int i, value; |
397 | |
382 | |
398 | sprintf (filename, "%s/materials", settings.datadir); |
383 | sprintf (filename, "%s/materials", settings.datadir); |
399 | LOG (llevDebug, "Reading material type data from %s...", filename); |
384 | LOG (llevDebug, "Reading material type data from %s...\n", filename); |
400 | if ((fp = fopen (filename, "r")) == NULL) |
385 | if ((fp = fopen (filename, "r")) == NULL) |
401 | { |
386 | { |
402 | LOG (llevError, "Cannot open %s for reading\n", filename); |
387 | LOG (llevError, "Cannot open %s for reading\n", filename); |
403 | mt = get_empty_mat (); |
388 | mt = get_empty_mat (); |
404 | mt->next = NULL; |
389 | mt->next = NULL; |
… | |
… | |
770 | else |
755 | else |
771 | { |
756 | { |
772 | LOG (llevError, "load_settings: Unknown value for " "real_wiz: %s\n", cp); |
757 | LOG (llevError, "load_settings: Unknown value for " "real_wiz: %s\n", cp); |
773 | } |
758 | } |
774 | } |
759 | } |
775 | else if (!strcasecmp (buf, "recycle_tmp_maps")) |
|
|
776 | { |
|
|
777 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
778 | { |
|
|
779 | settings.recycle_tmp_maps = TRUE; |
|
|
780 | } |
|
|
781 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
782 | { |
|
|
783 | settings.recycle_tmp_maps = FALSE; |
|
|
784 | } |
|
|
785 | else |
|
|
786 | { |
|
|
787 | LOG (llevError, "load_settings: Unknown value for " "recycle_tmp_maps: %s\n", cp); |
|
|
788 | } |
|
|
789 | } |
|
|
790 | else if (!strcasecmp (buf, "explore_mode")) |
760 | else if (!strcasecmp (buf, "explore_mode")) |
791 | { |
761 | { |
792 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
762 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
793 | { |
763 | { |
794 | settings.explore_mode = TRUE; |
764 | settings.explore_mode = TRUE; |
… | |
… | |
799 | } |
769 | } |
800 | else |
770 | else |
801 | { |
771 | { |
802 | LOG (llevError, "load_settings: Unknown value for " "explore_mode: %s\n", cp); |
772 | LOG (llevError, "load_settings: Unknown value for " "explore_mode: %s\n", cp); |
803 | } |
773 | } |
804 | } |
|
|
805 | else if (!strcasecmp (buf, "who_format")) |
|
|
806 | { |
|
|
807 | if (has_val) |
|
|
808 | strcpy (settings.who_format, cp); |
|
|
809 | } |
|
|
810 | else if (!strcasecmp (buf, "who_wiz_format")) |
|
|
811 | { |
|
|
812 | if (has_val) |
|
|
813 | strcpy (settings.who_wiz_format, cp); |
|
|
814 | } |
774 | } |
815 | else if (!strcasecmp (buf, "spellpoint_level_depend")) |
775 | else if (!strcasecmp (buf, "spellpoint_level_depend")) |
816 | { |
776 | { |
817 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
777 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
818 | { |
778 | { |
… | |
… | |
1029 | else |
989 | else |
1030 | { |
990 | { |
1031 | LOG (llevError, "Unknown value in settings file: %s\n", buf); |
991 | LOG (llevError, "Unknown value in settings file: %s\n", buf); |
1032 | } |
992 | } |
1033 | } |
993 | } |
|
|
994 | |
1034 | close_and_delete (fp, comp); |
995 | close_and_delete (fp, comp); |
1035 | } |
996 | } |
1036 | |
997 | |
1037 | |
998 | |
1038 | /* |
999 | /* |
… | |
… | |
1049 | * LibDir in this pass would be reasonable*/ |
1010 | * LibDir in this pass would be reasonable*/ |
1050 | |
1011 | |
1051 | cfperl_init (); |
1012 | cfperl_init (); |
1052 | init_library (); /* Must be called early */ |
1013 | init_library (); /* Must be called early */ |
1053 | load_settings (); /* Load the settings file */ |
1014 | load_settings (); /* Load the settings file */ |
1054 | init_weather (); |
|
|
1055 | load_materials (); |
1015 | load_materials (); |
1056 | parse_args (argc, argv, 2); |
1016 | parse_args (argc, argv, 2); |
1057 | 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"); |
1058 | fprintf (logfile, "Copyright (C) 1994 Mark Wedel.\n"); |
1019 | fprintf (logfile, "Copyright (C) 1994 Mark Wedel.\n"); |
1059 | fprintf (logfile, "Copyright (C) 1992 Frank Tore Johansen.\n"); |
1020 | fprintf (logfile, "Copyright (C) 1992 Frank Tore Johansen.\n"); |
1060 | |
1021 | |
1061 | if (strcmp (settings.dm_mail, "") != 0) |
1022 | if (strcmp (settings.dm_mail, "") != 0) |
1062 | { |
1023 | { |
… | |
… | |
1068 | |
1029 | |
1069 | init_startup (); /* Write (C), check shutdown/forbid files */ |
1030 | init_startup (); /* Write (C), check shutdown/forbid files */ |
1070 | init_uuid (); |
1031 | init_uuid (); |
1071 | init_signals (); /* Sets up signal interceptions */ |
1032 | init_signals (); /* Sets up signal interceptions */ |
1072 | init_commands (); /* Sort command tables */ |
1033 | init_commands (); /* Sort command tables */ |
1073 | read_map_log (); /* Load up the old temp map files */ |
|
|
1074 | init_skills (); |
1034 | init_skills (); |
1075 | |
1035 | |
1076 | parse_args (argc, argv, 3); |
1036 | parse_args (argc, argv, 3); |
1077 | |
1037 | |
1078 | #ifndef WIN32 /* ***win32: no BecomeDaemon in windows */ |
|
|
1079 | if (settings.daemonmode) |
1038 | if (settings.daemonmode) |
1080 | logfile = BecomeDaemon (settings.logfilename[0] == '\0' ? "logfile" : settings.logfilename); |
1039 | logfile = BecomeDaemon (settings.logfilename[0] == '\0' ? "logfile" : settings.logfilename); |
1081 | #endif |
|
|
1082 | |
1040 | |
1083 | init_beforeplay (); |
1041 | init_beforeplay (); |
1084 | init_ericserver (); |
1042 | init_ericserver (); |
1085 | init_done = 1; |
1043 | init_done = 1; |
1086 | } |
1044 | } |
… | |
… | |
1250 | printf ("Save player:\t<true>\n"); |
1208 | printf ("Save player:\t<true>\n"); |
1251 | printf ("Save mode:\t%4.4o\n", SAVE_MODE); |
1209 | printf ("Save mode:\t%4.4o\n", SAVE_MODE); |
1252 | printf ("Playerdir:\t<VAR>/%s\n", settings.playerdir); |
1210 | printf ("Playerdir:\t<VAR>/%s\n", settings.playerdir); |
1253 | printf ("Itemsdir:\t<VAR>/%s\n", settings.uniquedir); |
1211 | printf ("Itemsdir:\t<VAR>/%s\n", settings.uniquedir); |
1254 | printf ("Tmpdir:\t\t%s\n", settings.tmpdir); |
1212 | printf ("Tmpdir:\t\t%s\n", settings.tmpdir); |
1255 | printf ("Map max timeout:\t%d\n", MAP_MAXTIMEOUT); |
|
|
1256 | printf ("Max objects:\t%d\n", MAX_OBJECTS); |
|
|
1257 | #ifdef USE_CALLOC |
1213 | #ifdef USE_CALLOC |
1258 | printf ("Use_calloc:\t<true>\n"); |
1214 | printf ("Use_calloc:\t<true>\n"); |
1259 | #else |
1215 | #else |
1260 | printf ("Use_calloc:\t<false>\n"); |
1216 | printf ("Use_calloc:\t<false>\n"); |
1261 | #endif |
1217 | #endif |
… | |
… | |
1264 | printf ("Editor:\t\t%s\n", X_EDITOR); |
1220 | printf ("Editor:\t\t%s\n", X_EDITOR); |
1265 | #endif |
1221 | #endif |
1266 | |
1222 | |
1267 | printf ("Max_time:\t%d\n", MAX_TIME); |
1223 | printf ("Max_time:\t%d\n", MAX_TIME); |
1268 | |
1224 | |
1269 | #ifdef WIN32 /* ***win32 compile_info(): remove execl... */ |
|
|
1270 | printf ("Logfilename:\t%s\n", settings.logfilename); |
|
|
1271 | exit (0); |
|
|
1272 | #else |
|
|
1273 | execl ("/bin/uname", "uname", "-a", NULL); |
1225 | execl ("/bin/uname", "uname", "-a", NULL); |
1274 | LOG (llevError, "Oops, shouldn't have gotten here: execl(/bin/uname) failed: %s\n", strerror (errno)); |
1226 | LOG (llevError, "Oops, shouldn't have gotten here: execl(/bin/uname) failed: %s\n", strerror (errno)); |
1275 | exit (-1); |
1227 | exit (-1); |
1276 | #endif |
|
|
1277 | } |
1228 | } |
1278 | |
1229 | |
1279 | /* Signal handlers: */ |
1230 | /* Signal handlers: */ |
1280 | |
1231 | |
1281 | void |
1232 | void |
1282 | rec_sigsegv (int i) |
1233 | rec_sigsegv (int i) |
1283 | { |
1234 | { |
1284 | LOG (llevError, "\nSIGSEGV received.\n"); |
1235 | LOG (llevError, "SIGSEGV received.\n"); |
1285 | fatal_signal (1, 1); |
1236 | fatal_signal (1, 1); |
1286 | } |
1237 | } |
1287 | |
1238 | |
1288 | void |
1239 | void |
1289 | rec_sigint (int i) |
1240 | rec_sigint (int i) |
1290 | { |
1241 | { |
1291 | LOG (llevInfo, "\nSIGINT received.\n"); |
1242 | LOG (llevInfo, "SIGINT received.\n"); |
1292 | fatal_signal (0, 1); |
1243 | fatal_signal (0, 1); |
1293 | } |
1244 | } |
1294 | |
1245 | |
1295 | void |
1246 | void |
1296 | rec_sighup (int i) |
1247 | rec_sighup (int i) |
1297 | { |
1248 | { |
1298 | LOG (llevInfo, "\nSIGHUP received\n"); |
1249 | LOG (llevInfo, "SIGHUP received\n"); |
|
|
1250 | |
1299 | if (init_done) |
1251 | if (init_done) |
1300 | { |
|
|
1301 | emergency_save (0); |
|
|
1302 | cleanup (); |
1252 | cleanup (0); |
1303 | } |
1253 | |
1304 | exit (0); |
1254 | exit (0); |
1305 | } |
1255 | } |
1306 | |
1256 | |
1307 | void |
1257 | void |
1308 | rec_sigquit (int i) |
1258 | rec_sigquit (int i) |
1309 | { |
1259 | { |
1310 | LOG (llevInfo, "\nSIGQUIT received\n"); |
1260 | LOG (llevInfo, "SIGQUIT received\n"); |
1311 | fatal_signal (1, 1); |
1261 | fatal_signal (1, 1); |
1312 | } |
1262 | } |
1313 | |
1263 | |
1314 | void |
1264 | void |
1315 | rec_sigbus (int i) |
1265 | rec_sigbus (int i) |
1316 | { |
1266 | { |
1317 | #ifdef SIGBUS |
1267 | #ifdef SIGBUS |
1318 | LOG (llevError, "\nSIGBUS received\n"); |
1268 | LOG (llevError, "SIGBUS received\n"); |
1319 | fatal_signal (1, 1); |
1269 | fatal_signal (1, 1); |
1320 | #endif |
1270 | #endif |
1321 | } |
1271 | } |
1322 | |
1272 | |
1323 | void |
1273 | void |
1324 | rec_sigterm (int i) |
1274 | rec_sigterm (int i) |
1325 | { |
1275 | { |
1326 | LOG (llevInfo, "\nSIGTERM received\n"); |
1276 | LOG (llevInfo, "SIGTERM received\n"); |
1327 | fatal_signal (0, 1); |
1277 | fatal_signal (0, 1); |
1328 | } |
1278 | } |
1329 | |
1279 | |
1330 | void |
1280 | void |
1331 | fatal_signal (int make_core, int close_sockets) |
1281 | fatal_signal (int make_core, int close_sockets) |
1332 | { |
1282 | { |
1333 | if (init_done) |
1283 | cleanup (make_core); |
1334 | { |
|
|
1335 | emergency_save (0); |
|
|
1336 | clean_tmp_files (); |
|
|
1337 | } |
|
|
1338 | if (make_core) |
|
|
1339 | abort (); |
|
|
1340 | exit (0); |
|
|
1341 | } |
1284 | } |
1342 | |
1285 | |
1343 | void |
1286 | void |
1344 | init_signals (void) |
1287 | init_signals (void) |
1345 | { |
1288 | { |
1346 | #ifndef WIN32 /* init_signals() remove signals */ |
|
|
1347 | signal (SIGHUP, rec_sighup); |
1289 | signal (SIGHUP, rec_sighup); |
1348 | signal (SIGINT, rec_sigint); |
1290 | signal (SIGINT, rec_sigint); |
1349 | signal (SIGQUIT, rec_sigquit); |
1291 | signal (SIGQUIT, rec_sigquit); |
1350 | signal (SIGSEGV, rec_sigsegv); |
1292 | signal (SIGSEGV, rec_sigsegv); |
1351 | signal (SIGPIPE, SIG_IGN); |
1293 | signal (SIGPIPE, SIG_IGN); |
1352 | # ifdef SIGBUS |
1294 | #ifdef SIGBUS |
1353 | signal (SIGBUS, rec_sigbus); |
1295 | signal (SIGBUS, rec_sigbus); |
1354 | # endif |
1296 | #endif |
1355 | signal (SIGTERM, rec_sigterm); |
1297 | signal (SIGTERM, rec_sigterm); |
1356 | #endif |
|
|
1357 | } |
1298 | } |
1358 | |
1299 | |
1359 | /* init_races() - reads the races file in the lib/ directory, then |
1300 | /* init_races() - reads the races file in the lib/ directory, then |
1360 | * overwrites old 'race' entries. This routine allow us to quickly |
1301 | * overwrites old 'race' entries. This routine allow us to quickly |
1361 | * re-configure the 'alignment' of monsters, objects. Useful for |
1302 | * re-configure the 'alignment' of monsters, objects. Useful for |
… | |
… | |
1374 | return; |
1315 | return; |
1375 | init_done = 1; |
1316 | init_done = 1; |
1376 | first_race = 0; |
1317 | first_race = 0; |
1377 | |
1318 | |
1378 | sprintf (fname, "%s/races", settings.datadir); |
1319 | sprintf (fname, "%s/races", settings.datadir); |
1379 | LOG (llevDebug, "Reading races from %s...", fname); |
1320 | LOG (llevDebug, "Reading races from %s...\n", fname); |
1380 | if (!(file = fopen (fname, "r"))) |
1321 | if (!(file = fopen (fname, "r"))) |
1381 | { |
1322 | { |
1382 | LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno)); |
1323 | LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno)); |
1383 | return; |
1324 | return; |
1384 | } |
1325 | } |
… | |
… | |
1425 | if (cp[strlen (cp) - 1] == '\n') |
1366 | if (cp[strlen (cp) - 1] == '\n') |
1426 | cp[strlen (cp) - 1] = '\0'; |
1367 | cp[strlen (cp) - 1] = '\0'; |
1427 | |
1368 | |
1428 | /* set creature race to race value */ |
1369 | /* set creature race to race value */ |
1429 | if ((mon = archetype::find (cp)) == NULL) |
1370 | if ((mon = archetype::find (cp)) == NULL) |
1430 | LOG (llevError, "\nCreature %s in race file lacks archetype", cp); |
1371 | LOG (llevError, "Creature %s in race file lacks archetype\n", cp); |
1431 | else |
1372 | else |
1432 | { |
1373 | { |
1433 | if (set_race && (!mon->clone.race || strcmp (mon->clone.race, race))) |
1374 | if (set_race && (!mon->clone.race || strcmp (mon->clone.race, race))) |
1434 | { |
1375 | { |
1435 | if (mon->clone.race) |
1376 | if (mon->clone.race) |
1436 | LOG (llevDebug, "\n Resetting race to %s from %s for archetype %s", race, &mon->clone.race, &mon->name); |
1377 | LOG (llevDebug, "Resetting race to %s from %s for archetype %s\n", race, &mon->clone.race, &mon->name); |
1437 | |
1378 | |
1438 | mon->clone.race = race; |
1379 | mon->clone.race = race; |
1439 | } |
1380 | } |
1440 | |
1381 | |
1441 | /* if the arch is a monster, add it to the race list */ |
1382 | /* if the arch is a monster, add it to the race list */ |