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.14 by root, Sat Sep 30 23:48:57 2006 UTC vs.
Revision 1.21 by root, Wed Dec 20 09:14:22 2006 UTC

211 211
212void 212void
213set_csport (char *val) 213set_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/*
1115 read_map_log (); /* Load up the old temp map files */ 1039 read_map_log (); /* Load up the old temp map files */
1116 init_skills (); 1040 init_skills ();
1117 1041
1118 parse_args (argc, argv, 3); 1042 parse_args (argc, argv, 3);
1119 1043
1120#ifndef WIN32 /* ***win32: no BecomeDaemon in windows */
1121 if (settings.daemonmode) 1044 if (settings.daemonmode)
1122 logfile = BecomeDaemon (settings.logfilename[0] == '\0' ? "logfile" : settings.logfilename); 1045 logfile = BecomeDaemon (settings.logfilename[0] == '\0' ? "logfile" : settings.logfilename);
1123#endif
1124 1046
1125 init_beforeplay (); 1047 init_beforeplay ();
1126 init_ericserver (); 1048 init_ericserver ();
1127 metaserver_init ();
1128 init_done = 1; 1049 init_done = 1;
1129} 1050}
1130 1051
1131void 1052void
1132usage (void) 1053usage (void)
1307 printf ("Editor:\t\t%s\n", X_EDITOR); 1228 printf ("Editor:\t\t%s\n", X_EDITOR);
1308#endif 1229#endif
1309 1230
1310 printf ("Max_time:\t%d\n", MAX_TIME); 1231 printf ("Max_time:\t%d\n", MAX_TIME);
1311 1232
1312#ifdef WIN32 /* ***win32 compile_info(): remove execl... */
1313 printf ("Logfilename:\t%s\n", settings.logfilename);
1314 exit (0);
1315#else
1316 execl ("/bin/uname", "uname", "-a", NULL); 1233 execl ("/bin/uname", "uname", "-a", NULL);
1317 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));
1318 exit (-1); 1235 exit (-1);
1319#endif
1320} 1236}
1321 1237
1322/* Signal handlers: */ 1238/* Signal handlers: */
1323 1239
1324void 1240void
1325rec_sigsegv (int i) 1241rec_sigsegv (int i)
1326{ 1242{
1327 LOG (llevError, "\nSIGSEGV received.\n"); 1243 LOG (llevError, "SIGSEGV received.\n");
1328 fatal_signal (1, 1); 1244 fatal_signal (1, 1);
1329} 1245}
1330 1246
1331void 1247void
1332rec_sigint (int i) 1248rec_sigint (int i)
1333{ 1249{
1334 LOG (llevInfo, "\nSIGINT received.\n"); 1250 LOG (llevInfo, "SIGINT received.\n");
1335 fatal_signal (0, 1); 1251 fatal_signal (0, 1);
1336} 1252}
1337 1253
1338void 1254void
1339rec_sighup (int i) 1255rec_sighup (int i)
1340{ 1256{
1341 LOG (llevInfo, "\nSIGHUP received\n"); 1257 LOG (llevInfo, "SIGHUP received\n");
1258
1342 if (init_done) 1259 if (init_done)
1343 {
1344 emergency_save (0);
1345 cleanup (); 1260 cleanup ();
1346 } 1261
1347 exit (0); 1262 exit (0);
1348} 1263}
1349 1264
1350void 1265void
1351rec_sigquit (int i) 1266rec_sigquit (int i)
1352{ 1267{
1353 LOG (llevInfo, "\nSIGQUIT received\n"); 1268 LOG (llevInfo, "SIGQUIT received\n");
1354 fatal_signal (1, 1); 1269 fatal_signal (1, 1);
1355} 1270}
1356 1271
1357void 1272void
1358rec_sigbus (int i) 1273rec_sigbus (int i)
1359{ 1274{
1360#ifdef SIGBUS 1275#ifdef SIGBUS
1361 LOG (llevError, "\nSIGBUS received\n"); 1276 LOG (llevError, "SIGBUS received\n");
1362 fatal_signal (1, 1); 1277 fatal_signal (1, 1);
1363#endif 1278#endif
1364} 1279}
1365 1280
1366void 1281void
1367rec_sigterm (int i) 1282rec_sigterm (int i)
1368{ 1283{
1369 LOG (llevInfo, "\nSIGTERM received\n"); 1284 LOG (llevInfo, "SIGTERM received\n");
1370 fatal_signal (0, 1); 1285 fatal_signal (0, 1);
1371} 1286}
1372 1287
1373void 1288void
1374fatal_signal (int make_core, int close_sockets) 1289fatal_signal (int make_core, int close_sockets)
1375{ 1290{
1376 if (init_done) 1291 cleanup (make_core);
1377 {
1378 emergency_save (0);
1379 clean_tmp_files ();
1380 }
1381 if (make_core)
1382 abort ();
1383 exit (0);
1384} 1292}
1385 1293
1386void 1294void
1387init_signals (void) 1295init_signals (void)
1388{ 1296{
1389#ifndef WIN32 /* init_signals() remove signals */
1390 signal (SIGHUP, rec_sighup); 1297 signal (SIGHUP, rec_sighup);
1391 signal (SIGINT, rec_sigint); 1298 signal (SIGINT, rec_sigint);
1392 signal (SIGQUIT, rec_sigquit); 1299 signal (SIGQUIT, rec_sigquit);
1393 signal (SIGSEGV, rec_sigsegv); 1300 signal (SIGSEGV, rec_sigsegv);
1394 signal (SIGPIPE, SIG_IGN); 1301 signal (SIGPIPE, SIG_IGN);
1395# ifdef SIGBUS 1302#ifdef SIGBUS
1396 signal (SIGBUS, rec_sigbus); 1303 signal (SIGBUS, rec_sigbus);
1397# endif 1304#endif
1398 signal (SIGTERM, rec_sigterm); 1305 signal (SIGTERM, rec_sigterm);
1399#endif
1400} 1306}
1401 1307
1402/* init_races() - reads the races file in the lib/ directory, then 1308/* init_races() - reads the races file in the lib/ directory, then
1403 * overwrites old 'race' entries. This routine allow us to quickly 1309 * overwrites old 'race' entries. This routine allow us to quickly
1404 * re-configure the 'alignment' of monsters, objects. Useful for 1310 * re-configure the 'alignment' of monsters, objects. Useful for

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines