ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/init.C
(Generate patch)

Comparing deliantra/server/server/init.C (file contents):
Revision 1.13 by root, Thu Sep 14 22:34:04 2006 UTC vs.
Revision 1.28 by pippijn, Wed Jan 3 00:46:53 2007 UTC

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 */
32weathermap_t **weathermap;
33 28
34void 29void
35set_logfile (char *val) 30set_logfile (char *val)
36{ 31{
37 settings.logfilename = val; 32 settings.logfilename = val;
211 206
212void 207void
213set_csport (char *val) 208set_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 */
245struct Command_Line_Options options[] = { 238struct 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;
564 { 549 {
565 cp = ""; 550 cp = "";
566 has_val = 0; 551 has_val = 0;
567 } 552 }
568 553
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")) 554 if (!strcasecmp (buf, "motd"))
592 { 555 {
593 if (has_val) 556 if (has_val)
594 strcpy (settings.motd, cp); 557 strcpy (settings.motd, cp);
595 else 558 else
596 LOG (llevError, "load_settings: motd must have a value.\n"); 559 LOG (llevError, "load_settings: motd must have a value.\n");
600 if (has_val) 563 if (has_val)
601 strcpy (settings.dm_mail, cp); 564 strcpy (settings.dm_mail, cp);
602 else 565 else
603 LOG (llevError, "load_settings: dm_mail must have a value.\n"); 566 LOG (llevError, "load_settings: dm_mail must have a value.\n");
604 } 567 }
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")) 568 else if (!strcasecmp (buf, "worldmapstartx"))
626 { 569 {
627 int size = atoi (cp); 570 int size = atoi (cp);
628 571
629 if (size < 0) 572 if (size < 0)
812 else 755 else
813 { 756 {
814 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);
815 } 758 }
816 } 759 }
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")) 760 else if (!strcasecmp (buf, "explore_mode"))
833 { 761 {
834 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 762 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
835 { 763 {
836 settings.explore_mode = TRUE; 764 settings.explore_mode = TRUE;
841 } 769 }
842 else 770 else
843 { 771 {
844 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);
845 } 773 }
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 } 774 }
857 else if (!strcasecmp (buf, "spellpoint_level_depend")) 775 else if (!strcasecmp (buf, "spellpoint_level_depend"))
858 { 776 {
859 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 777 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
860 { 778 {
1071 else 989 else
1072 { 990 {
1073 LOG (llevError, "Unknown value in settings file: %s\n", buf); 991 LOG (llevError, "Unknown value in settings file: %s\n", buf);
1074 } 992 }
1075 } 993 }
994
1076 close_and_delete (fp, comp); 995 close_and_delete (fp, comp);
1077} 996}
1078 997
1079 998
1080/* 999/*
1088 logfile = stderr; 1007 logfile = stderr;
1089 parse_args (argc, argv, 1); /* First arg pass - right now it does 1008 parse_args (argc, argv, 1); /* First arg pass - right now it does
1090 * nothing, but in future specifying the 1009 * nothing, but in future specifying the
1091 * LibDir in this pass would be reasonable*/ 1010 * LibDir in this pass would be reasonable*/
1092 1011
1012 cfperl_init ();
1093 init_library (); /* Must be called early */ 1013 init_library (); /* Must be called early */
1094 load_settings (); /* Load the settings file */ 1014 load_settings (); /* Load the settings file */
1095 init_weather ();
1096 load_materials (); 1015 load_materials ();
1097 parse_args (argc, argv, 2); 1016 parse_args (argc, argv, 2);
1098 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");
1099 fprintf (logfile, "Copyright (C) 1994 Mark Wedel.\n"); 1019 fprintf (logfile, "Copyright (C) 1994 Mark Wedel.\n");
1100 fprintf (logfile, "Copyright (C) 1992 Frank Tore Johansen.\n"); 1020 fprintf (logfile, "Copyright (C) 1992 Frank Tore Johansen.\n");
1101 1021
1102 if (strcmp (settings.dm_mail, "") != 0) 1022 if (strcmp (settings.dm_mail, "") != 0)
1103 { 1023 {
1109 1029
1110 init_startup (); /* Write (C), check shutdown/forbid files */ 1030 init_startup (); /* Write (C), check shutdown/forbid files */
1111 init_uuid (); 1031 init_uuid ();
1112 init_signals (); /* Sets up signal interceptions */ 1032 init_signals (); /* Sets up signal interceptions */
1113 init_commands (); /* Sort command tables */ 1033 init_commands (); /* Sort command tables */
1114 read_map_log (); /* Load up the old temp map files */
1115 init_skills (); 1034 init_skills ();
1116 1035
1117 parse_args (argc, argv, 3); 1036 parse_args (argc, argv, 3);
1118 1037
1119#ifndef WIN32 /* ***win32: no BecomeDaemon in windows */
1120 if (settings.daemonmode) 1038 if (settings.daemonmode)
1121 logfile = BecomeDaemon (settings.logfilename[0] == '\0' ? "logfile" : settings.logfilename); 1039 logfile = BecomeDaemon (settings.logfilename[0] == '\0' ? "logfile" : settings.logfilename);
1122#endif
1123 1040
1124 init_beforeplay (); 1041 init_beforeplay ();
1125 init_ericserver (); 1042 init_ericserver ();
1126 metaserver_init ();
1127 init_done = 1; 1043 init_done = 1;
1128} 1044}
1129 1045
1130void 1046void
1131usage (void) 1047usage (void)
1292 printf ("Save player:\t<true>\n"); 1208 printf ("Save player:\t<true>\n");
1293 printf ("Save mode:\t%4.4o\n", SAVE_MODE); 1209 printf ("Save mode:\t%4.4o\n", SAVE_MODE);
1294 printf ("Playerdir:\t<VAR>/%s\n", settings.playerdir); 1210 printf ("Playerdir:\t<VAR>/%s\n", settings.playerdir);
1295 printf ("Itemsdir:\t<VAR>/%s\n", settings.uniquedir); 1211 printf ("Itemsdir:\t<VAR>/%s\n", settings.uniquedir);
1296 printf ("Tmpdir:\t\t%s\n", settings.tmpdir); 1212 printf ("Tmpdir:\t\t%s\n", settings.tmpdir);
1297 printf ("Map max timeout:\t%d\n", MAP_MAXTIMEOUT);
1298 printf ("Max objects:\t%d\n", MAX_OBJECTS);
1299#ifdef USE_CALLOC 1213#ifdef USE_CALLOC
1300 printf ("Use_calloc:\t<true>\n"); 1214 printf ("Use_calloc:\t<true>\n");
1301#else 1215#else
1302 printf ("Use_calloc:\t<false>\n"); 1216 printf ("Use_calloc:\t<false>\n");
1303#endif 1217#endif
1306 printf ("Editor:\t\t%s\n", X_EDITOR); 1220 printf ("Editor:\t\t%s\n", X_EDITOR);
1307#endif 1221#endif
1308 1222
1309 printf ("Max_time:\t%d\n", MAX_TIME); 1223 printf ("Max_time:\t%d\n", MAX_TIME);
1310 1224
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); 1225 execl ("/bin/uname", "uname", "-a", NULL);
1316 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));
1317 exit (-1); 1227 exit (-1);
1318#endif
1319} 1228}
1320 1229
1321/* Signal handlers: */ 1230/* Signal handlers: */
1322 1231
1323void 1232void
1324rec_sigsegv (int i) 1233rec_sigsegv (int i)
1325{ 1234{
1326 LOG (llevError, "\nSIGSEGV received.\n"); 1235 LOG (llevError, "SIGSEGV received.\n");
1327 fatal_signal (1, 1); 1236 fatal_signal (1, 1);
1328} 1237}
1329 1238
1330void 1239void
1331rec_sigint (int i) 1240rec_sigint (int i)
1332{ 1241{
1333 LOG (llevInfo, "\nSIGINT received.\n"); 1242 LOG (llevInfo, "SIGINT received.\n");
1334 fatal_signal (0, 1); 1243 fatal_signal (0, 1);
1335} 1244}
1336 1245
1337void 1246void
1338rec_sighup (int i) 1247rec_sighup (int i)
1339{ 1248{
1340 LOG (llevInfo, "\nSIGHUP received\n"); 1249 LOG (llevInfo, "SIGHUP received\n");
1250
1341 if (init_done) 1251 if (init_done)
1342 {
1343 emergency_save (0);
1344 cleanup (); 1252 cleanup (0);
1345 } 1253
1346 exit (0); 1254 exit (0);
1347} 1255}
1348 1256
1349void 1257void
1350rec_sigquit (int i) 1258rec_sigquit (int i)
1351{ 1259{
1352 LOG (llevInfo, "\nSIGQUIT received\n"); 1260 LOG (llevInfo, "SIGQUIT received\n");
1353 fatal_signal (1, 1); 1261 fatal_signal (1, 1);
1354} 1262}
1355 1263
1356void 1264void
1357rec_sigbus (int i) 1265rec_sigbus (int i)
1358{ 1266{
1359#ifdef SIGBUS 1267#ifdef SIGBUS
1360 LOG (llevError, "\nSIGBUS received\n"); 1268 LOG (llevError, "SIGBUS received\n");
1361 fatal_signal (1, 1); 1269 fatal_signal (1, 1);
1362#endif 1270#endif
1363} 1271}
1364 1272
1365void 1273void
1366rec_sigterm (int i) 1274rec_sigterm (int i)
1367{ 1275{
1368 LOG (llevInfo, "\nSIGTERM received\n"); 1276 LOG (llevInfo, "SIGTERM received\n");
1369 fatal_signal (0, 1); 1277 fatal_signal (0, 1);
1370} 1278}
1371 1279
1372void 1280void
1373fatal_signal (int make_core, int close_sockets) 1281fatal_signal (int make_core, int close_sockets)
1374{ 1282{
1375 if (init_done) 1283 cleanup (make_core);
1376 {
1377 emergency_save (0);
1378 clean_tmp_files ();
1379 }
1380 if (make_core)
1381 abort ();
1382 exit (0);
1383} 1284}
1384 1285
1385void 1286void
1386init_signals (void) 1287init_signals (void)
1387{ 1288{
1388#ifndef WIN32 /* init_signals() remove signals */
1389 signal (SIGHUP, rec_sighup); 1289 signal (SIGHUP, rec_sighup);
1390 signal (SIGINT, rec_sigint); 1290 signal (SIGINT, rec_sigint);
1391 signal (SIGQUIT, rec_sigquit); 1291 signal (SIGQUIT, rec_sigquit);
1392 signal (SIGSEGV, rec_sigsegv); 1292 signal (SIGSEGV, rec_sigsegv);
1393 signal (SIGPIPE, SIG_IGN); 1293 signal (SIGPIPE, SIG_IGN);
1394# ifdef SIGBUS 1294#ifdef SIGBUS
1395 signal (SIGBUS, rec_sigbus); 1295 signal (SIGBUS, rec_sigbus);
1396# endif 1296#endif
1397 signal (SIGTERM, rec_sigterm); 1297 signal (SIGTERM, rec_sigterm);
1398#endif
1399} 1298}
1400 1299
1401/* init_races() - reads the races file in the lib/ directory, then 1300/* init_races() - reads the races file in the lib/ directory, then
1402 * overwrites old 'race' entries. This routine allow us to quickly 1301 * overwrites old 'race' entries. This routine allow us to quickly
1403 * re-configure the 'alignment' of monsters, objects. Useful for 1302 * re-configure the 'alignment' of monsters, objects. Useful for
1416 return; 1315 return;
1417 init_done = 1; 1316 init_done = 1;
1418 first_race = 0; 1317 first_race = 0;
1419 1318
1420 sprintf (fname, "%s/races", settings.datadir); 1319 sprintf (fname, "%s/races", settings.datadir);
1421 LOG (llevDebug, "Reading races from %s...", fname); 1320 LOG (llevDebug, "Reading races from %s...\n", fname);
1422 if (!(file = fopen (fname, "r"))) 1321 if (!(file = fopen (fname, "r")))
1423 { 1322 {
1424 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));
1425 return; 1324 return;
1426 } 1325 }
1467 if (cp[strlen (cp) - 1] == '\n') 1366 if (cp[strlen (cp) - 1] == '\n')
1468 cp[strlen (cp) - 1] = '\0'; 1367 cp[strlen (cp) - 1] = '\0';
1469 1368
1470 /* set creature race to race value */ 1369 /* set creature race to race value */
1471 if ((mon = archetype::find (cp)) == NULL) 1370 if ((mon = archetype::find (cp)) == NULL)
1472 LOG (llevError, "\nCreature %s in race file lacks archetype", cp); 1371 LOG (llevError, "Creature %s in race file lacks archetype\n", cp);
1473 else 1372 else
1474 { 1373 {
1475 if (set_race && (!mon->clone.race || strcmp (mon->clone.race, race))) 1374 if (set_race && (!mon->clone.race || strcmp (mon->clone.race, race)))
1476 { 1375 {
1477 if (mon->clone.race) 1376 if (mon->clone.race)
1478 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);
1479 1378
1480 mon->clone.race = race; 1379 mon->clone.race = race;
1481 } 1380 }
1482 1381
1483 /* 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 */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines