1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
|
|
4 | * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
8 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
12 | * option) any later version. |
12 | * |
13 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * GNU General Public License for more details. |
17 | * |
18 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
21 | * <http://www.gnu.org/licenses/>. |
21 | * |
22 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
24 | */ |
24 | |
25 | |
25 | #include <global.h> |
26 | #include <global.h> |
26 | #include <material.h> |
27 | #include <material.h> |
… | |
… | |
31 | * information, having it here probably makes more sense. |
32 | * information, having it here probably makes more sense. |
32 | */ |
33 | */ |
33 | void |
34 | void |
34 | load_settings () |
35 | load_settings () |
35 | { |
36 | { |
36 | char fname [1024]; |
37 | object_thawer thawer (settings.confdir, "settings"); |
37 | sprintf (fname, "%s/settings", settings.confdir); |
|
|
38 | object_thawer thawer (fname); |
|
|
39 | |
38 | |
40 | if (!thawer) |
39 | if (!thawer) |
41 | { |
40 | { |
42 | LOG (llevError, "Error: No settings file found\n"); |
41 | LOG (llevError, "Error: No settings file found\n"); |
43 | exit (1); |
42 | exit (1); |
… | |
… | |
333 | init_environ (); |
332 | init_environ (); |
334 | cfperl_init (); |
333 | cfperl_init (); |
335 | init_done = 1; |
334 | init_done = 1; |
336 | } |
335 | } |
337 | |
336 | |
338 | void |
|
|
339 | usage () |
|
|
340 | { |
|
|
341 | fprintf (stderr, "Usage: deliantra-server [-h] [-<flags>]...\n"); |
|
|
342 | } |
|
|
343 | |
|
|
344 | void |
|
|
345 | help () |
|
|
346 | { |
|
|
347 | |
|
|
348 | /* The information in usage is redundant with what is given below, so why call it? */ |
|
|
349 | |
|
|
350 | /* usage();*/ |
|
|
351 | printf ("Flags:\n"); |
|
|
352 | printf (" -csport <port> Specifies the port to use for the new client/server code.\n"); |
|
|
353 | printf (" -d Turns on some debugging.\n"); |
|
|
354 | printf (" +d Turns off debugging (useful if server compiled with debugging\n"); |
|
|
355 | printf (" as default).\n"); |
|
|
356 | printf (" -detach The server will go in the background, closing all\n"); |
|
|
357 | printf (" connections to the tty.\n"); |
|
|
358 | printf (" -h Display this information.\n"); |
|
|
359 | printf (" -log <file> Specifies which file to send output to.\n"); |
|
|
360 | printf (" Only has meaning if -detach is specified.\n"); |
|
|
361 | printf (" -mon Turns on monster debugging.\n"); |
|
|
362 | printf (" -o Prints out info on what was defined at compile time.\n"); |
|
|
363 | printf (" -s Display the high-score list.\n"); |
|
|
364 | printf (" -score <name or class> Displays all high scores with matching name/class.\n"); |
|
|
365 | printf (" -v Print version and contributors.\n"); |
|
|
366 | printf (" -data Sets the lib dir (archetypes, treasures, etc.)\n"); |
|
|
367 | printf (" -local Read/write local data (hiscore, unique items, etc.)\n"); |
|
|
368 | printf (" -maps Sets the directory for maps.\n"); |
|
|
369 | printf (" -arch Sets the archetype file to use.\n"); |
|
|
370 | printf (" -regions Sets the regions file to use.\n"); |
|
|
371 | printf (" -playerdir Sets the directory for the player files.\n"); |
|
|
372 | printf (" -templatedir Sets the directory for template generate maps.\n"); |
|
|
373 | printf (" -treasures Sets the treasures file to use.\n"); |
|
|
374 | printf (" -uniquedir Sets the unique items/maps directory.\n"); |
|
|
375 | printf (" -tmpdir Sets the directory for temporary files (mostly maps.)\n"); |
|
|
376 | printf (" -m Lists out suggested experience for all monsters.\n"); |
|
|
377 | printf (" -m2 Dumps out abilities.\n"); |
|
|
378 | printf (" -m3 Dumps out artifact information.\n"); |
|
|
379 | printf (" -m4 Dumps out spell information.\n"); |
|
|
380 | printf (" -m5 Dumps out skill information.\n"); |
|
|
381 | printf (" -m6 Dumps out race information.\n"); |
|
|
382 | printf (" -m7 Dumps out alchemy information.\n"); |
|
|
383 | printf (" -m8 Dumps out gods information.\n"); |
|
|
384 | printf (" -m9 Dumps out more alchemy information (formula checking).\n"); |
|
|
385 | printf (" -mt <name> Dumps out list of treasures for a monster.\n"); |
|
|
386 | exit (0); |
|
|
387 | } |
|
|
388 | |
|
|
389 | /* Signal handlers: */ |
337 | /* Signal handlers: */ |
390 | |
338 | |
391 | static void |
339 | static void |
392 | rec_sigabrt (int i) |
340 | rec_sigabrt (int i) |
393 | { |
341 | { |
… | |
… | |
396 | LOG (llevError, "SIGABRT received.\n"); |
344 | LOG (llevError, "SIGABRT received.\n"); |
397 | cleanup ("SIGABRT received", 1); |
345 | cleanup ("SIGABRT received", 1); |
398 | } |
346 | } |
399 | |
347 | |
400 | static void |
348 | static void |
|
|
349 | rec_sigquit (int i) |
|
|
350 | { |
|
|
351 | signal (SIGQUIT, SIG_IGN); |
|
|
352 | |
|
|
353 | LOG (llevInfo, "SIGQUIT received\n"); |
|
|
354 | cleanup ("SIGQUIT received", 1); |
|
|
355 | } |
|
|
356 | |
|
|
357 | static void |
401 | rec_sigsegv (int i) |
358 | rec_sigsegv (int i) |
402 | { |
359 | { |
403 | signal (SIGSEGV, SIG_DFL); |
360 | signal (SIGSEGV, SIG_DFL); |
404 | |
361 | |
405 | LOG (llevError, "SIGSEGV received.\n"); |
362 | LOG (llevError, "SIGSEGV received.\n"); |
406 | cleanup ("SIGSEGV received", 1); |
363 | cleanup ("SIGSEGV received", 1); |
407 | } |
364 | } |
408 | |
365 | |
409 | static void |
366 | static void |
410 | rec_sigquit (int i) |
|
|
411 | { |
|
|
412 | signal (SIGQUIT, SIG_IGN); |
|
|
413 | |
|
|
414 | LOG (llevInfo, "SIGQUIT received\n"); |
|
|
415 | cleanup ("SIGQUIT received", 1); |
|
|
416 | } |
|
|
417 | |
|
|
418 | static void |
|
|
419 | rec_sigbus (int i) |
367 | rec_sigbus (int i) |
420 | { |
368 | { |
421 | signal (SIGBUS, SIG_DFL); |
369 | signal (SIGBUS, SIG_DFL); |
422 | |
370 | |
423 | LOG (llevError, "SIGBUS received\n"); |
371 | LOG (llevError, "SIGBUS received\n"); |
424 | cleanup ("SIGBUS received", 1); |
372 | cleanup ("SIGBUS received", 1); |
|
|
373 | } |
|
|
374 | |
|
|
375 | static void |
|
|
376 | rec_sigfpe (int i) |
|
|
377 | { |
|
|
378 | signal (SIGFPE, SIG_DFL); |
|
|
379 | |
|
|
380 | LOG (llevError, "SIGFPE received.\n"); |
|
|
381 | cleanup ("SIGFPE received", 1); |
425 | } |
382 | } |
426 | |
383 | |
427 | void |
384 | void |
428 | reset_signals () |
385 | reset_signals () |
429 | { |
386 | { |
430 | signal (SIGABRT, SIG_DFL); |
387 | signal (SIGABRT, SIG_DFL); |
431 | signal (SIGQUIT, SIG_DFL); |
388 | signal (SIGQUIT, SIG_DFL); |
432 | signal (SIGSEGV, SIG_DFL); |
389 | signal (SIGSEGV, SIG_DFL); |
|
|
390 | #ifdef SIGBUS |
433 | signal (SIGBUS , SIG_DFL); |
391 | signal (SIGBUS , SIG_DFL); |
|
|
392 | #endif |
|
|
393 | signal (SIGFPE , SIG_DFL); |
434 | signal (SIGINT , SIG_DFL); |
394 | signal (SIGINT , SIG_DFL); |
435 | signal (SIGTERM, SIG_DFL); |
395 | signal (SIGTERM, SIG_DFL); |
436 | } |
396 | } |
437 | |
397 | |
438 | void |
398 | void |
… | |
… | |
454 | sa.sa_flags = SA_RESTART; |
414 | sa.sa_flags = SA_RESTART; |
455 | |
415 | |
456 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
416 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
457 | sa.sa_handler = rec_sigabrt; sigaction (SIGABRT, &sa, 0); |
417 | sa.sa_handler = rec_sigabrt; sigaction (SIGABRT, &sa, 0); |
458 | sa.sa_handler = rec_sigquit; sigaction (SIGQUIT, &sa, 0); |
418 | sa.sa_handler = rec_sigquit; sigaction (SIGQUIT, &sa, 0); |
|
|
419 | #ifdef SIGBUS |
459 | sa.sa_handler = rec_sigbus; sigaction (SIGBUS, &sa, 0); |
420 | sa.sa_handler = rec_sigbus; sigaction (SIGBUS, &sa, 0); |
|
|
421 | #endif |
|
|
422 | sa.sa_handler = rec_sigfpe; sigaction (SIGFPE, &sa, 0); |
460 | |
423 | |
461 | sa.sa_flags |= SA_ONSTACK; |
424 | sa.sa_flags |= SA_ONSTACK; |
462 | sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0); |
425 | sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0); |
463 | } |
426 | } |
464 | |
427 | |