forked from github/server
allow reading the configuration from a different directory (-c dir).
This commit is contained in:
parent
af73c6dcdf
commit
51207167c8
|
@ -31,51 +31,51 @@
|
||||||
void game_done(void)
|
void game_done(void)
|
||||||
{
|
{
|
||||||
#ifdef CLEANUP_CODE
|
#ifdef CLEANUP_CODE
|
||||||
/* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur
|
/* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur
|
||||||
* zum Debugging interessant, wenn man Leak Detection hat, und nach
|
* zum Debugging interessant, wenn man Leak Detection hat, und nach
|
||||||
* nicht freigegebenem Speicher sucht, der nicht bis zum Ende benötigt
|
* nicht freigegebenem Speicher sucht, der nicht bis zum Ende benötigt
|
||||||
* wird (temporäre Hilsstrukturen) */
|
* wird (temporäre Hilsstrukturen) */
|
||||||
|
|
||||||
free_game();
|
free_game();
|
||||||
|
|
||||||
creport_cleanup();
|
creport_cleanup();
|
||||||
#ifdef REPORT_FORMAT_NR
|
#ifdef REPORT_FORMAT_NR
|
||||||
report_cleanup();
|
report_cleanup();
|
||||||
#endif
|
#endif
|
||||||
calendar_cleanup();
|
calendar_cleanup();
|
||||||
#endif
|
#endif
|
||||||
kernel_done();
|
kernel_done();
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_init(void)
|
void game_init(void)
|
||||||
{
|
{
|
||||||
kernel_init();
|
kernel_init();
|
||||||
register_triggers();
|
register_triggers();
|
||||||
register_xmas();
|
register_xmas();
|
||||||
|
|
||||||
register_nr();
|
register_nr();
|
||||||
register_cr();
|
register_cr();
|
||||||
|
|
||||||
register_names();
|
register_names();
|
||||||
register_resources();
|
register_resources();
|
||||||
register_buildings();
|
register_buildings();
|
||||||
register_itemfunctions();
|
register_itemfunctions();
|
||||||
#if DUNGEON_MODULE
|
#if DUNGEON_MODULE
|
||||||
register_dungeon();
|
register_dungeon();
|
||||||
#endif
|
#endif
|
||||||
#if MUSEUM_MODULE
|
#if MUSEUM_MODULE
|
||||||
register_museum();
|
register_museum();
|
||||||
#endif
|
#endif
|
||||||
#if ARENA_MODULE
|
#if ARENA_MODULE
|
||||||
register_arena();
|
register_arena();
|
||||||
#endif
|
#endif
|
||||||
register_wormholes();
|
register_wormholes();
|
||||||
|
|
||||||
register_itemtypes();
|
register_itemtypes();
|
||||||
#ifdef USE_LIBXML2
|
#ifdef USE_LIBXML2
|
||||||
register_xmlreader();
|
register_xmlreader();
|
||||||
#endif
|
#endif
|
||||||
register_attributes();
|
register_attributes();
|
||||||
register_gmcmd();
|
register_gmcmd();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
7208
src/laws.c
7208
src/laws.c
File diff suppressed because it is too large
Load Diff
352
src/main.c
352
src/main.c
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||||
Katja Zedel <katze@felidae.kn-bremen.de
|
Katja Zedel <katze@felidae.kn-bremen.de
|
||||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -41,136 +41,146 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
#include <iniparser.h>
|
#include <iniparser.h>
|
||||||
|
|
||||||
static const char *logfile= "eressea.log";
|
extern const char *confpath;
|
||||||
|
static const char *logfile = "eressea.log";
|
||||||
static const char *luafile = 0;
|
static const char *luafile = 0;
|
||||||
static const char *inifile = "eressea.ini";
|
static const char *inifile = "eressea.ini";
|
||||||
static int memdebug = 0;
|
static int memdebug = 0;
|
||||||
|
|
||||||
static void parse_config(const char *filename)
|
static void parse_config(const char *filename)
|
||||||
{
|
{
|
||||||
dictionary *d = iniparser_new(filename);
|
dictionary *d = iniparser_new(filename);
|
||||||
if (d) {
|
if (d) {
|
||||||
load_inifile(d);
|
load_inifile(d);
|
||||||
log_debug("reading from configuration file %s\n", filename);
|
log_debug("reading from configuration file %s\n", filename);
|
||||||
|
|
||||||
memdebug = iniparser_getint(d, "eressea:memcheck", memdebug);
|
memdebug = iniparser_getint(d, "eressea:memcheck", memdebug);
|
||||||
#ifdef USE_CURSES
|
#ifdef USE_CURSES
|
||||||
/* only one value in the [editor] section */
|
/* only one value in the [editor] section */
|
||||||
force_color = iniparser_getint(d, "editor:color", force_color);
|
force_color = iniparser_getint(d, "editor:color", force_color);
|
||||||
#endif
|
#endif
|
||||||
/* excerpt from [config] (the rest is used in bindings.c) */
|
/* excerpt from [config] (the rest is used in bindings.c) */
|
||||||
game_name = iniparser_getstring(d, "config:game", game_name);
|
game_name = iniparser_getstring(d, "config:game", game_name);
|
||||||
} else {
|
}
|
||||||
log_warning("could not open configuration file %s\n", filename);
|
else {
|
||||||
}
|
log_error("could not open configuration file %s\n", filename);
|
||||||
global.inifile = d;
|
}
|
||||||
|
global.inifile = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usage(const char *prog, const char *arg)
|
static int usage(const char *prog, const char *arg)
|
||||||
{
|
{
|
||||||
if (arg) {
|
if (arg) {
|
||||||
fprintf(stderr, "unknown argument: %s\n\n", arg);
|
fprintf(stderr, "unknown argument: %s\n\n", arg);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Usage: %s [options]\n"
|
fprintf(stderr, "Usage: %s [options]\n"
|
||||||
"-t <turn> : read this datafile, not the most current one\n"
|
"-t <turn> : read this datafile, not the most current one\n"
|
||||||
"-f <script.lua> : execute a lua script\n"
|
"-f <script.lua> : execute a lua script\n"
|
||||||
"-q : be quite (same as -v 0)\n"
|
"-q : be quite (same as -v 0)\n"
|
||||||
"-v <level> : verbosity level\n"
|
"-v <level> : verbosity level\n"
|
||||||
"-C : run in interactive mode\n"
|
"-C : run in interactive mode\n"
|
||||||
"--color : force curses to use colors even when not detected\n", prog);
|
"--color : force curses to use colors even when not detected\n", prog);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_arg(int argc, char **argv, size_t len, int index, const char **result, const char *def) {
|
static int get_arg(int argc, char **argv, size_t len, int index, const char **result, const char *def) {
|
||||||
if (argv[index][len]) {
|
if (argv[index][len]) {
|
||||||
*result = argv[index]+len;
|
*result = argv[index] + len;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
if (index + 1 < argc) {
|
||||||
|
*result = argv[index + 1];
|
||||||
|
return index + 1;
|
||||||
|
}
|
||||||
|
*result = def;
|
||||||
return index;
|
return index;
|
||||||
}
|
|
||||||
if (index+1 < argc) {
|
|
||||||
*result = argv[index+1];
|
|
||||||
return index+1;
|
|
||||||
}
|
|
||||||
*result = def;
|
|
||||||
return index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_args(int argc, char **argv, int *exitcode)
|
static int parse_args(int argc, char **argv, int *exitcode)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 1; i != argc; ++i) {
|
for (i = 1; i != argc; ++i) {
|
||||||
if (argv[i][0] != '-') {
|
if (argv[i][0] != '-') {
|
||||||
luafile = argv[i];
|
luafile = argv[i];
|
||||||
} else if (argv[i][1] == '-') { /* long format */
|
}
|
||||||
if (strcmp(argv[i] + 2, "version") == 0) {
|
else if (argv[i][1] == '-') { /* long format */
|
||||||
printf("\n%s PBEM host\n"
|
if (strcmp(argv[i] + 2, "version") == 0) {
|
||||||
"Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n"
|
printf("\n%s PBEM host\n"
|
||||||
"Compilation: " __DATE__ " at " __TIME__ "\nVersion: %d.%d.%d\n\n",
|
"Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n"
|
||||||
global.gamename, VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD);
|
"Compilation: " __DATE__ " at " __TIME__ "\nVersion: %d.%d.%d\n\n",
|
||||||
|
global.gamename, VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD);
|
||||||
#ifdef USE_CURSES
|
#ifdef USE_CURSES
|
||||||
} else if (strcmp(argv[i] + 2, "color") == 0) {
|
}
|
||||||
/* force the editor to have colors */
|
else if (strcmp(argv[i] + 2, "color") == 0) {
|
||||||
force_color = 1;
|
/* force the editor to have colors */
|
||||||
|
force_color = 1;
|
||||||
#endif
|
#endif
|
||||||
} else if (strcmp(argv[i] + 2, "help") == 0) {
|
}
|
||||||
return usage(argv[0], NULL);
|
else if (strcmp(argv[i] + 2, "help") == 0) {
|
||||||
} else {
|
return usage(argv[0], NULL);
|
||||||
return usage(argv[0], argv[i]);
|
}
|
||||||
}
|
else {
|
||||||
} else {
|
return usage(argv[0], argv[i]);
|
||||||
const char *arg;
|
}
|
||||||
switch (argv[i][1]) {
|
}
|
||||||
case 'f':
|
else {
|
||||||
i = get_arg(argc, argv, 2, i, &luafile, 0);
|
const char *arg;
|
||||||
break;
|
switch (argv[i][1]) {
|
||||||
case 'l':
|
case 'c':
|
||||||
i = get_arg(argc, argv, 2, i, &logfile, 0);
|
i = get_arg(argc, argv, 2, i, &confpath, 0);
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 'f':
|
||||||
i = get_arg(argc, argv, 2, i, &arg, 0);
|
i = get_arg(argc, argv, 2, i, &luafile, 0);
|
||||||
turn = atoi(arg);
|
break;
|
||||||
break;
|
case 'l':
|
||||||
case 'q':
|
i = get_arg(argc, argv, 2, i, &logfile, 0);
|
||||||
verbosity = 0;
|
break;
|
||||||
break;
|
case 't':
|
||||||
case 'r':
|
i = get_arg(argc, argv, 2, i, &arg, 0);
|
||||||
i = get_arg(argc, argv, 2, i, &arg, 0);
|
turn = atoi(arg);
|
||||||
turn = atoi(arg);
|
break;
|
||||||
break;
|
case 'q':
|
||||||
case 'v':
|
verbosity = 0;
|
||||||
i = get_arg(argc, argv, 2, i, &arg, 0);
|
break;
|
||||||
verbosity = arg ? atoi(arg) : 0xff;
|
case 'r':
|
||||||
break;
|
i = get_arg(argc, argv, 2, i, &arg, 0);
|
||||||
case 'h':
|
turn = atoi(arg);
|
||||||
usage(argv[0], NULL);
|
break;
|
||||||
return 1;
|
case 'v':
|
||||||
default:
|
i = get_arg(argc, argv, 2, i, &arg, 0);
|
||||||
*exitcode = -1;
|
verbosity = arg ? atoi(arg) : 0xff;
|
||||||
usage(argv[0], argv[i]);
|
break;
|
||||||
return 1;
|
case 'h':
|
||||||
}
|
usage(argv[0], NULL);
|
||||||
|
return 1;
|
||||||
|
default:
|
||||||
|
*exitcode = -1;
|
||||||
|
usage(argv[0], argv[i]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
switch (verbosity) {
|
|
||||||
case 0:
|
|
||||||
log_stderr = 0;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
log_stderr = LOG_CPERROR;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
log_stderr = LOG_CPERROR|LOG_CPWARNING;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
log_stderr = LOG_CPERROR|LOG_CPWARNING|LOG_CPDEBUG;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
log_stderr = LOG_CPERROR|LOG_CPWARNING|LOG_CPDEBUG|LOG_CPINFO;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
switch (verbosity) {
|
||||||
|
case 0:
|
||||||
|
log_stderr = 0;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
log_stderr = LOG_CPERROR;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
log_stderr = LOG_CPERROR | LOG_CPWARNING;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
log_stderr = LOG_CPERROR | LOG_CPWARNING | LOG_CPDEBUG;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log_stderr = LOG_CPERROR | LOG_CPWARNING | LOG_CPDEBUG | LOG_CPINFO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_SIGACTION) && defined(HAVE_EXECINFO)
|
#if defined(HAVE_SIGACTION) && defined(HAVE_EXECINFO)
|
||||||
|
@ -179,30 +189,30 @@ static int parse_args(int argc, char **argv, int *exitcode)
|
||||||
|
|
||||||
static void report_segfault(int signo, siginfo_t * sinf, void *arg)
|
static void report_segfault(int signo, siginfo_t * sinf, void *arg)
|
||||||
{
|
{
|
||||||
void *btrace[50];
|
void *btrace[50];
|
||||||
size_t size;
|
size_t size;
|
||||||
int fd = fileno(stderr);
|
int fd = fileno(stderr);
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
fputs("\n\nProgram received SIGSEGV, backtrace follows.\n", stderr);
|
fputs("\n\nProgram received SIGSEGV, backtrace follows.\n", stderr);
|
||||||
size = backtrace(btrace, 50);
|
size = backtrace(btrace, 50);
|
||||||
backtrace_symbols_fd(btrace, size, fd);
|
backtrace_symbols_fd(btrace, size, fd);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int setup_signal_handler(void)
|
static int setup_signal_handler(void)
|
||||||
{
|
{
|
||||||
struct sigaction act;
|
struct sigaction act;
|
||||||
|
|
||||||
act.sa_flags = SA_ONESHOT | SA_SIGINFO;
|
act.sa_flags = SA_ONESHOT | SA_SIGINFO;
|
||||||
act.sa_sigaction = report_segfault;
|
act.sa_sigaction = report_segfault;
|
||||||
sigfillset(&act.sa_mask);
|
sigfillset(&act.sa_mask);
|
||||||
return sigaction(SIGSEGV, &act, NULL);
|
return sigaction(SIGSEGV, &act, NULL);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static int setup_signal_handler(void)
|
static int setup_signal_handler(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -212,72 +222,82 @@ static int setup_signal_handler(void)
|
||||||
void init_crtdbg(void)
|
void init_crtdbg(void)
|
||||||
{
|
{
|
||||||
#if (defined(_MSC_VER))
|
#if (defined(_MSC_VER))
|
||||||
int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
||||||
if (memdebug == 1) {
|
if (memdebug == 1) {
|
||||||
flags |= _CRTDBG_CHECK_ALWAYS_DF; /* expensive */
|
flags |= _CRTDBG_CHECK_ALWAYS_DF; /* expensive */
|
||||||
} else if (memdebug == 2) {
|
} else if (memdebug == 2) {
|
||||||
flags = (flags & 0x0000FFFF) | _CRTDBG_CHECK_EVERY_16_DF;
|
flags = (flags & 0x0000FFFF) | _CRTDBG_CHECK_EVERY_16_DF;
|
||||||
} else if (memdebug == 3) {
|
} else if (memdebug == 3) {
|
||||||
flags = (flags & 0x0000FFFF) | _CRTDBG_CHECK_EVERY_128_DF;
|
flags = (flags & 0x0000FFFF) | _CRTDBG_CHECK_EVERY_128_DF;
|
||||||
} else if (memdebug == 4) {
|
} else if (memdebug == 4) {
|
||||||
flags = (flags & 0x0000FFFF) | _CRTDBG_CHECK_EVERY_1024_DF;
|
flags = (flags & 0x0000FFFF) | _CRTDBG_CHECK_EVERY_1024_DF;
|
||||||
}
|
}
|
||||||
_CrtSetDbgFlag(flags);
|
_CrtSetDbgFlag(flags);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void locale_init(void)
|
void locale_init(void)
|
||||||
{
|
{
|
||||||
setlocale(LC_CTYPE, "");
|
setlocale(LC_CTYPE, "");
|
||||||
setlocale(LC_NUMERIC, "C");
|
setlocale(LC_NUMERIC, "C");
|
||||||
if (towlower(0xC4) != 0xE4) { /* Ä => ä */
|
if (towlower(0xC4) != 0xE4) { /* Ä => ä */
|
||||||
log_error("Umlaut conversion is not working properly. Wrong locale? LANG=%s\n",
|
log_error("Umlaut conversion is not working properly. Wrong locale? LANG=%s\n",
|
||||||
getenv("LANG"));
|
getenv("LANG"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void bind_monsters(struct lua_State *L);
|
extern void bind_monsters(struct lua_State *L);
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int err, result = 0;
|
char inipath[MAX_PATH];
|
||||||
lua_State *L;
|
int err = 0;
|
||||||
setup_signal_handler();
|
lua_State *L;
|
||||||
parse_config(inifile);
|
setup_signal_handler();
|
||||||
log_open(logfile);
|
|
||||||
|
|
||||||
err = parse_args(argc, argv, &result);
|
/* parse args once to read config file location */
|
||||||
if (err) {
|
if (parse_args(argc, argv, &err) != 0) {
|
||||||
return result;
|
return err;
|
||||||
}
|
}
|
||||||
|
/* ini file sets defaults for arguments*/
|
||||||
|
if (confpath) {
|
||||||
|
_snprintf(inipath, sizeof(inipath), "%s/%s", confpath, inifile);
|
||||||
|
parse_config(inipath);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
parse_config(inifile);
|
||||||
|
}
|
||||||
|
/* parse arguments again, to override ini file */
|
||||||
|
parse_args(argc, argv, &err);
|
||||||
|
|
||||||
locale_init();
|
log_open(logfile);
|
||||||
|
locale_init();
|
||||||
|
|
||||||
#ifdef CRTDBG
|
#ifdef CRTDBG
|
||||||
init_crtdbg();
|
init_crtdbg();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
L = lua_init();
|
L = lua_init();
|
||||||
game_init();
|
game_init();
|
||||||
register_races();
|
register_races();
|
||||||
register_borders();
|
register_borders();
|
||||||
register_spells();
|
register_spells();
|
||||||
bind_monsters(L);
|
bind_monsters(L);
|
||||||
err = eressea_run(L, luafile);
|
err = eressea_run(L, luafile);
|
||||||
if (err) {
|
if (err) {
|
||||||
log_error("server execution failed with code %d\n", err);
|
log_error("server execution failed with code %d\n", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
#ifdef MSPACES
|
#ifdef MSPACES
|
||||||
malloc_stats();
|
malloc_stats();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
game_done();
|
game_done();
|
||||||
lua_done(L);
|
lua_done(L);
|
||||||
log_close();
|
log_close();
|
||||||
if (global.inifile) {
|
if (global.inifile) {
|
||||||
iniparser_free(global.inifile);
|
iniparser_free(global.inifile);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue