… | |
… | |
16 | |
16 | |
17 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
20 | |
21 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
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> |
… | |
… | |
211 | |
211 | |
212 | void |
212 | void |
213 | set_csport (char *val) |
213 | set_csport (char *val) |
214 | { |
214 | { |
215 | settings.csport = atoi (val); |
215 | 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)) |
216 | if (settings.csport <= 0 || settings.csport > 32765 || (settings.csport < 1024 && getuid () != 0)) |
218 | { |
217 | { |
219 | LOG (llevError, "%d is an invalid csport number.\n", settings.csport); |
218 | LOG (llevError, "%d is an invalid csport number.\n", settings.csport); |
220 | exit (1); |
219 | exit (1); |
221 | } |
220 | } |
222 | #endif /* win32 */ |
|
|
223 | } |
221 | } |
224 | |
222 | |
225 | /* Most of this is shamelessly stolen from XSysStats. But since that is |
223 | /* Most of this is shamelessly stolen from XSysStats. But since that is |
226 | * also my program, no problem. |
224 | * also my program, no problem. |
227 | */ |
225 | */ |
… | |
… | |
265 | {"-treasures", 1, 1, (void (*)()) set_treasures}, |
263 | {"-treasures", 1, 1, (void (*)()) set_treasures}, |
266 | {"-uniquedir", 1, 1, (void (*)()) set_uniquedir}, |
264 | {"-uniquedir", 1, 1, (void (*)()) set_uniquedir}, |
267 | {"-templatedir", 1, 1, (void (*)()) set_templatedir}, |
265 | {"-templatedir", 1, 1, (void (*)()) set_templatedir}, |
268 | {"-tmpdir", 1, 1, (void (*)()) set_tmpdir}, |
266 | {"-tmpdir", 1, 1, (void (*)()) set_tmpdir}, |
269 | {"-log", 1, 1, (void (*)()) set_logfile}, |
267 | {"-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 | |
268 | |
279 | /* Pass 2 functions. Most of these could probably be in pass 1, |
269 | /* 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. |
270 | * as they don't require much of anything to bet set up. |
281 | */ |
271 | */ |
282 | {"-csport", 1, 2, (void (*)()) set_csport}, |
272 | {"-csport", 1, 2, (void (*)()) set_csport}, |
… | |
… | |
564 | { |
554 | { |
565 | cp = ""; |
555 | cp = ""; |
566 | has_val = 0; |
556 | has_val = 0; |
567 | } |
557 | } |
568 | |
558 | |
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")) |
559 | if (!strcasecmp (buf, "motd")) |
592 | { |
560 | { |
593 | if (has_val) |
561 | if (has_val) |
594 | strcpy (settings.motd, cp); |
562 | strcpy (settings.motd, cp); |
595 | else |
563 | else |
596 | LOG (llevError, "load_settings: motd must have a value.\n"); |
564 | LOG (llevError, "load_settings: motd must have a value.\n"); |
… | |
… | |
600 | if (has_val) |
568 | if (has_val) |
601 | strcpy (settings.dm_mail, cp); |
569 | strcpy (settings.dm_mail, cp); |
602 | else |
570 | else |
603 | LOG (llevError, "load_settings: dm_mail must have a value.\n"); |
571 | LOG (llevError, "load_settings: dm_mail must have a value.\n"); |
604 | } |
572 | } |
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")) |
573 | else if (!strcasecmp (buf, "worldmapstartx")) |
626 | { |
574 | { |
627 | int size = atoi (cp); |
575 | int size = atoi (cp); |
628 | |
576 | |
629 | if (size < 0) |
577 | if (size < 0) |
… | |
… | |
812 | else |
760 | else |
813 | { |
761 | { |
814 | LOG (llevError, "load_settings: Unknown value for " "real_wiz: %s\n", cp); |
762 | LOG (llevError, "load_settings: Unknown value for " "real_wiz: %s\n", cp); |
815 | } |
763 | } |
816 | } |
764 | } |
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")) |
765 | else if (!strcasecmp (buf, "explore_mode")) |
833 | { |
766 | { |
834 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
767 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
835 | { |
768 | { |
836 | settings.explore_mode = TRUE; |
769 | settings.explore_mode = TRUE; |
… | |
… | |
841 | } |
774 | } |
842 | else |
775 | else |
843 | { |
776 | { |
844 | LOG (llevError, "load_settings: Unknown value for " "explore_mode: %s\n", cp); |
777 | LOG (llevError, "load_settings: Unknown value for " "explore_mode: %s\n", cp); |
845 | } |
778 | } |
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 | } |
779 | } |
857 | else if (!strcasecmp (buf, "spellpoint_level_depend")) |
780 | else if (!strcasecmp (buf, "spellpoint_level_depend")) |
858 | { |
781 | { |
859 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
782 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
860 | { |
783 | { |
… | |
… | |
1071 | else |
994 | else |
1072 | { |
995 | { |
1073 | LOG (llevError, "Unknown value in settings file: %s\n", buf); |
996 | LOG (llevError, "Unknown value in settings file: %s\n", buf); |
1074 | } |
997 | } |
1075 | } |
998 | } |
|
|
999 | |
1076 | close_and_delete (fp, comp); |
1000 | close_and_delete (fp, comp); |
1077 | } |
1001 | } |
1078 | |
1002 | |
1079 | |
1003 | |
1080 | /* |
1004 | /* |
… | |
… | |
1088 | logfile = stderr; |
1012 | logfile = stderr; |
1089 | parse_args (argc, argv, 1); /* First arg pass - right now it does |
1013 | parse_args (argc, argv, 1); /* First arg pass - right now it does |
1090 | * nothing, but in future specifying the |
1014 | * nothing, but in future specifying the |
1091 | * LibDir in this pass would be reasonable*/ |
1015 | * LibDir in this pass would be reasonable*/ |
1092 | |
1016 | |
|
|
1017 | cfperl_init (); |
1093 | init_library (); /* Must be called early */ |
1018 | init_library (); /* Must be called early */ |
1094 | load_settings (); /* Load the settings file */ |
1019 | load_settings (); /* Load the settings file */ |
1095 | init_weather (); |
1020 | init_weather (); |
1096 | load_materials (); |
1021 | load_materials (); |
1097 | parse_args (argc, argv, 2); |
1022 | parse_args (argc, argv, 2); |
… | |
… | |
1114 | read_map_log (); /* Load up the old temp map files */ |
1039 | read_map_log (); /* Load up the old temp map files */ |
1115 | init_skills (); |
1040 | init_skills (); |
1116 | |
1041 | |
1117 | parse_args (argc, argv, 3); |
1042 | parse_args (argc, argv, 3); |
1118 | |
1043 | |
1119 | #ifndef WIN32 /* ***win32: no BecomeDaemon in windows */ |
|
|
1120 | if (settings.daemonmode) |
1044 | if (settings.daemonmode) |
1121 | logfile = BecomeDaemon (settings.logfilename[0] == '\0' ? "logfile" : settings.logfilename); |
1045 | logfile = BecomeDaemon (settings.logfilename[0] == '\0' ? "logfile" : settings.logfilename); |
1122 | #endif |
|
|
1123 | |
1046 | |
1124 | init_beforeplay (); |
1047 | init_beforeplay (); |
1125 | init_ericserver (); |
1048 | init_ericserver (); |
1126 | metaserver_init (); |
|
|
1127 | init_done = 1; |
1049 | init_done = 1; |
1128 | } |
1050 | } |
1129 | |
1051 | |
1130 | void |
1052 | void |
1131 | usage (void) |
1053 | usage (void) |
… | |
… | |
1306 | printf ("Editor:\t\t%s\n", X_EDITOR); |
1228 | printf ("Editor:\t\t%s\n", X_EDITOR); |
1307 | #endif |
1229 | #endif |
1308 | |
1230 | |
1309 | printf ("Max_time:\t%d\n", MAX_TIME); |
1231 | printf ("Max_time:\t%d\n", MAX_TIME); |
1310 | |
1232 | |
1311 | #ifdef WIN32 /* ***win32 compile_info(): remove execl... */ |
|
|
1312 | printf ("Logfilename:\t%s\n", settings.logfilename); |
|
|
1313 | exit (0); |
|
|
1314 | #else |
|
|
1315 | execl ("/bin/uname", "uname", "-a", NULL); |
1233 | execl ("/bin/uname", "uname", "-a", NULL); |
1316 | LOG (llevError, "Oops, shouldn't have gotten here: execl(/bin/uname) failed: %s\n", strerror (errno)); |
1234 | LOG (llevError, "Oops, shouldn't have gotten here: execl(/bin/uname) failed: %s\n", strerror (errno)); |
1317 | exit (-1); |
1235 | exit (-1); |
1318 | #endif |
|
|
1319 | } |
1236 | } |
1320 | |
1237 | |
1321 | /* Signal handlers: */ |
1238 | /* Signal handlers: */ |
1322 | |
1239 | |
1323 | void |
1240 | void |
1324 | rec_sigsegv (int i) |
1241 | rec_sigsegv (int i) |
1325 | { |
1242 | { |
1326 | LOG (llevError, "\nSIGSEGV received.\n"); |
1243 | LOG (llevError, "SIGSEGV received.\n"); |
1327 | fatal_signal (1, 1); |
1244 | fatal_signal (1, 1); |
1328 | } |
1245 | } |
1329 | |
1246 | |
1330 | void |
1247 | void |
1331 | rec_sigint (int i) |
1248 | rec_sigint (int i) |
1332 | { |
1249 | { |
1333 | LOG (llevInfo, "\nSIGINT received.\n"); |
1250 | LOG (llevInfo, "SIGINT received.\n"); |
1334 | fatal_signal (0, 1); |
1251 | fatal_signal (0, 1); |
1335 | } |
1252 | } |
1336 | |
1253 | |
1337 | void |
1254 | void |
1338 | rec_sighup (int i) |
1255 | rec_sighup (int i) |
1339 | { |
1256 | { |
1340 | LOG (llevInfo, "\nSIGHUP received\n"); |
1257 | LOG (llevInfo, "SIGHUP received\n"); |
|
|
1258 | |
1341 | if (init_done) |
1259 | if (init_done) |
1342 | { |
|
|
1343 | emergency_save (0); |
|
|
1344 | cleanup (); |
1260 | cleanup (); |
1345 | } |
1261 | |
1346 | exit (0); |
1262 | exit (0); |
1347 | } |
1263 | } |
1348 | |
1264 | |
1349 | void |
1265 | void |
1350 | rec_sigquit (int i) |
1266 | rec_sigquit (int i) |
1351 | { |
1267 | { |
1352 | LOG (llevInfo, "\nSIGQUIT received\n"); |
1268 | LOG (llevInfo, "SIGQUIT received\n"); |
1353 | fatal_signal (1, 1); |
1269 | fatal_signal (1, 1); |
1354 | } |
1270 | } |
1355 | |
1271 | |
1356 | void |
1272 | void |
1357 | rec_sigbus (int i) |
1273 | rec_sigbus (int i) |
1358 | { |
1274 | { |
1359 | #ifdef SIGBUS |
1275 | #ifdef SIGBUS |
1360 | LOG (llevError, "\nSIGBUS received\n"); |
1276 | LOG (llevError, "SIGBUS received\n"); |
1361 | fatal_signal (1, 1); |
1277 | fatal_signal (1, 1); |
1362 | #endif |
1278 | #endif |
1363 | } |
1279 | } |
1364 | |
1280 | |
1365 | void |
1281 | void |
1366 | rec_sigterm (int i) |
1282 | rec_sigterm (int i) |
1367 | { |
1283 | { |
1368 | LOG (llevInfo, "\nSIGTERM received\n"); |
1284 | LOG (llevInfo, "SIGTERM received\n"); |
1369 | fatal_signal (0, 1); |
1285 | fatal_signal (0, 1); |
1370 | } |
1286 | } |
1371 | |
1287 | |
1372 | void |
1288 | void |
1373 | fatal_signal (int make_core, int close_sockets) |
1289 | fatal_signal (int make_core, int close_sockets) |
1374 | { |
1290 | { |
1375 | if (init_done) |
1291 | cleanup (make_core); |
1376 | { |
|
|
1377 | emergency_save (0); |
|
|
1378 | clean_tmp_files (); |
|
|
1379 | } |
|
|
1380 | if (make_core) |
|
|
1381 | abort (); |
|
|
1382 | exit (0); |
|
|
1383 | } |
1292 | } |
1384 | |
1293 | |
1385 | void |
1294 | void |
1386 | init_signals (void) |
1295 | init_signals (void) |
1387 | { |
1296 | { |
1388 | #ifndef WIN32 /* init_signals() remove signals */ |
|
|
1389 | signal (SIGHUP, rec_sighup); |
1297 | signal (SIGHUP, rec_sighup); |
1390 | signal (SIGINT, rec_sigint); |
1298 | signal (SIGINT, rec_sigint); |
1391 | signal (SIGQUIT, rec_sigquit); |
1299 | signal (SIGQUIT, rec_sigquit); |
1392 | signal (SIGSEGV, rec_sigsegv); |
1300 | signal (SIGSEGV, rec_sigsegv); |
1393 | signal (SIGPIPE, SIG_IGN); |
1301 | signal (SIGPIPE, SIG_IGN); |
1394 | # ifdef SIGBUS |
1302 | #ifdef SIGBUS |
1395 | signal (SIGBUS, rec_sigbus); |
1303 | signal (SIGBUS, rec_sigbus); |
1396 | # endif |
1304 | #endif |
1397 | signal (SIGTERM, rec_sigterm); |
1305 | signal (SIGTERM, rec_sigterm); |
1398 | #endif |
|
|
1399 | } |
1306 | } |
1400 | |
1307 | |
1401 | /* init_races() - reads the races file in the lib/ directory, then |
1308 | /* init_races() - reads the races file in the lib/ directory, then |
1402 | * overwrites old 'race' entries. This routine allow us to quickly |
1309 | * overwrites old 'race' entries. This routine allow us to quickly |
1403 | * re-configure the 'alignment' of monsters, objects. Useful for |
1310 | * re-configure the 'alignment' of monsters, objects. Useful for |
… | |
… | |
1466 | |
1373 | |
1467 | if (cp[strlen (cp) - 1] == '\n') |
1374 | if (cp[strlen (cp) - 1] == '\n') |
1468 | cp[strlen (cp) - 1] = '\0'; |
1375 | cp[strlen (cp) - 1] = '\0'; |
1469 | |
1376 | |
1470 | /* set creature race to race value */ |
1377 | /* set creature race to race value */ |
1471 | if ((mon = find_archetype (cp)) == NULL) |
1378 | if ((mon = archetype::find (cp)) == NULL) |
1472 | LOG (llevError, "\nCreature %s in race file lacks archetype", cp); |
1379 | LOG (llevError, "\nCreature %s in race file lacks archetype", cp); |
1473 | else |
1380 | else |
1474 | { |
1381 | { |
1475 | if (set_race && (!mon->clone.race || strcmp (mon->clone.race, race))) |
1382 | if (set_race && (!mon->clone.race || strcmp (mon->clone.race, race))) |
1476 | { |
1383 | { |