forked from github/server
config file reading based on game name and install location.
This commit is contained in:
parent
ebe078df61
commit
afd41286b5
11 changed files with 77 additions and 79 deletions
|
@ -6,11 +6,13 @@ lomem = 0
|
|||
debug = 0
|
||||
memcheck = 0
|
||||
locales = de,en
|
||||
;game_id = 0
|
||||
|
||||
[config]
|
||||
source_dir = ../git
|
||||
[lua]
|
||||
install = ../git
|
||||
paths = ../git/lunit:../git/scripts
|
||||
maxnmrs = 20
|
||||
rules = eressea ; use -r to override
|
||||
rules = e2 ; can use -r to override
|
||||
|
||||
[editor]
|
||||
color = 1
|
||||
|
|
15
doc/LICENSE
Normal file
15
doc/LICENSE
Normal file
|
@ -0,0 +1,15 @@
|
|||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
16
eressea.ini
16
eressea.ini
|
@ -1,16 +0,0 @@
|
|||
[eressea]
|
||||
base = .
|
||||
report = reports
|
||||
verbose = 0
|
||||
lomem = 0
|
||||
debug = 0
|
||||
memcheck = 0
|
||||
locales = de,en
|
||||
|
||||
[config]
|
||||
paths = lunit
|
||||
install = .
|
||||
maxnmrs = 10
|
||||
|
||||
[editor]
|
||||
color = 1
|
|
@ -181,13 +181,29 @@ function run_turn(rules)
|
|||
return result
|
||||
end
|
||||
|
||||
path = 'scripts'
|
||||
if config.source_dir ~= nil then
|
||||
path = config.source_dir .. '/' .. path
|
||||
local confdir = 'conf/'
|
||||
|
||||
if config.rules then
|
||||
confdir = confdir .. config.rules .. '/'
|
||||
end
|
||||
if config.install then
|
||||
confdir = config.install .. '/' .. confdir
|
||||
end
|
||||
read_xml(confdir .. 'config.xml', confdir .. 'catalog.xml')
|
||||
|
||||
local path = 'scripts'
|
||||
if config.install then
|
||||
path = config.install .. '/' .. path
|
||||
end
|
||||
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
|
||||
|
||||
rules = require('eressea.' .. config.rules)
|
||||
read_xml()
|
||||
require 'eressea'
|
||||
local rules = {}
|
||||
if config.rules then
|
||||
rules = require('eressea.' .. config.rules)
|
||||
eressea.log.info('loaded ' .. table.getn(rules) .. ' modules for ' .. config.rules)
|
||||
else
|
||||
eressea.log.warning('no rule modules loaded, specify a game in eressea.ini or with -r')
|
||||
end
|
||||
|
||||
run_turn(rules)
|
||||
|
|
|
@ -1116,7 +1116,7 @@ int tolua_bindings_open(lua_State * L)
|
|||
tolua_module(L, TOLUA_CAST "config", 1);
|
||||
tolua_beginmodule(L, TOLUA_CAST "config");
|
||||
{
|
||||
parse_inifile(L, global.inifile, "config");
|
||||
parse_inifile(L, global.inifile, "lua");
|
||||
tolua_variable(L, TOLUA_CAST "locales", &config_get_locales, 0);
|
||||
tolua_function(L, TOLUA_CAST "get_resource", &config_get_resource);
|
||||
tolua_variable(L, TOLUA_CAST "buildings", &config_get_buildings, 0);
|
||||
|
@ -1222,12 +1222,6 @@ int eressea_run(lua_State *L, const char *luafile)
|
|||
global.vm_state = L;
|
||||
/* run the main script */
|
||||
if (luafile) {
|
||||
const char * install = iniparser_getstring(global.inifile, "eressea:install", 0);
|
||||
char path[MAX_PATH];
|
||||
if (install) {
|
||||
_snprintf(path, sizeof(path), "%s/%s", install, luafile);
|
||||
luafile = path;
|
||||
}
|
||||
log_debug("executing script %s\n", luafile);
|
||||
|
||||
lua_getglobal(L, "debug");
|
||||
|
|
|
@ -2922,7 +2922,7 @@ const char * game_name(void) {
|
|||
}
|
||||
|
||||
int game_id(void) {
|
||||
return get_param_int(global.parameters, "game.id", global.game_id);
|
||||
return get_param_int(global.parameters, "game.id", 0);
|
||||
}
|
||||
|
||||
void load_inifile(dictionary * d)
|
||||
|
@ -2960,9 +2960,6 @@ void load_inifile(dictionary * d)
|
|||
str = iniparser_getstring(d, "eressea:locales", "de,en");
|
||||
make_locales(str);
|
||||
|
||||
/* excerpt from [config] (the rest is used in bindings.c) */
|
||||
global.game_id = iniparser_getint(d, "config:game_id", 0);
|
||||
|
||||
if (global.inifile) iniparser_free(global.inifile);
|
||||
global.inifile = d;
|
||||
}
|
||||
|
|
|
@ -372,7 +372,6 @@ extern "C" {
|
|||
void *vm_state;
|
||||
float producexpchance;
|
||||
int cookie;
|
||||
int game_id;
|
||||
int data_version; /* TODO: eliminate in favor of gamedata.version */
|
||||
struct _dictionary_ *inifile;
|
||||
|
||||
|
|
33
src/laws.c
33
src/laws.c
|
@ -4796,41 +4796,14 @@ void update_subscriptions(void)
|
|||
fclose(F);
|
||||
}
|
||||
|
||||
const char *confpath = 0;
|
||||
|
||||
int init_data(const char *filename, const char *catalog)
|
||||
{
|
||||
const char * install = iniparser_getstring(global.inifile, "eressea:install", 0);
|
||||
char filepath[MAX_PATH], catpath[MAX_PATH];
|
||||
int l;
|
||||
|
||||
if (install || confpath) {
|
||||
if (install && confpath) {
|
||||
_snprintf(filepath, sizeof(filepath), "%s/%s/", install, confpath);
|
||||
_snprintf(catpath, sizeof(catpath), "%s/%s/", install, confpath);
|
||||
}
|
||||
else if (confpath) {
|
||||
_snprintf(filepath, sizeof(filepath), "%s/", confpath);
|
||||
_snprintf(catpath, sizeof(catpath), "%s/", confpath);
|
||||
}
|
||||
else if (install) {
|
||||
_snprintf(filepath, sizeof(filepath), "%s/", install);
|
||||
_snprintf(catpath, sizeof(catpath), "%s/", install);
|
||||
}
|
||||
if (filename) {
|
||||
strncat(filepath, filename, sizeof(filepath));
|
||||
filename = filepath;
|
||||
}
|
||||
if (catalog) {
|
||||
strncat(catpath, catalog, sizeof(catpath));
|
||||
catalog = catpath;
|
||||
}
|
||||
}
|
||||
l = read_xml(filename, catalog);
|
||||
init_locales();
|
||||
if (l)
|
||||
if (l) {
|
||||
return l;
|
||||
|
||||
}
|
||||
init_locales();
|
||||
if (turn < 0) {
|
||||
turn = first_turn;
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ $#include <util/log.h>
|
|||
|
||||
module eressea {
|
||||
module log {
|
||||
void log_error @ error(const char *message);
|
||||
void log_error_n @ error(const char *message);
|
||||
void log_debug @ debug(const char *message);
|
||||
void log_warning @ warning(const char *message);
|
||||
void log_info @ info(const char *message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ static int tolua_log_eressea_log_error00(lua_State* tolua_S)
|
|||
{
|
||||
const char* message = ((const char*) tolua_tostring(tolua_S,1,0));
|
||||
{
|
||||
log_error(message);
|
||||
log_error_n(message);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -103,6 +103,32 @@ static int tolua_log_eressea_log_debug00(lua_State* tolua_S)
|
|||
#endif
|
||||
}
|
||||
|
||||
/* function: log_info */
|
||||
static int tolua_log_eressea_log_info00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isstring(tolua_S, 1, 0, &tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S, 2, &tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
const char* message = ((const char*)tolua_tostring(tolua_S, 1, 0));
|
||||
{
|
||||
log_info(message);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror :
|
||||
tolua_error(tolua_S, "#ferror in function 'info'.", &tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Open lib function */
|
||||
LUALIB_API int luaopen_log (lua_State* tolua_S)
|
||||
{
|
||||
|
@ -116,7 +142,8 @@ LUALIB_API int luaopen_log (lua_State* tolua_S)
|
|||
tolua_beginmodule(tolua_S,"log");
|
||||
tolua_function(tolua_S,"error",tolua_log_eressea_log_error00);
|
||||
tolua_function(tolua_S,"warning",tolua_log_eressea_log_warning00);
|
||||
tolua_function(tolua_S,"debug",tolua_log_eressea_log_debug00);
|
||||
tolua_function(tolua_S, "debug",tolua_log_eressea_log_debug00);
|
||||
tolua_function(tolua_S, "info",tolua_log_eressea_log_info00);
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_endmodule(tolua_S);
|
||||
|
|
|
@ -41,7 +41,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <wctype.h>
|
||||
#include <iniparser.h>
|
||||
|
||||
extern const char *confpath;
|
||||
static const char *logfile = "eressea.log";
|
||||
static const char *luafile = 0;
|
||||
static const char *inifile = "eressea.ini";
|
||||
|
@ -125,9 +124,6 @@ static int parse_args(int argc, char **argv, int *exitcode)
|
|||
i = get_arg(argc, argv, 2, i, &arg, 0);
|
||||
set_param(&global.parameters, "config.rules", arg);
|
||||
break;
|
||||
case 'c':
|
||||
i = get_arg(argc, argv, 2, i, &confpath, 0);
|
||||
break;
|
||||
case 'f':
|
||||
i = get_arg(argc, argv, 2, i, &luafile, 0);
|
||||
break;
|
||||
|
@ -245,7 +241,6 @@ extern void bind_monsters(struct lua_State *L);
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char inipath[MAX_PATH];
|
||||
int err = 0;
|
||||
lua_State *L;
|
||||
setup_signal_handler();
|
||||
|
@ -256,10 +251,6 @@ int main(int argc, char **argv)
|
|||
}
|
||||
/* ini file sets defaults for arguments*/
|
||||
parse_config(inifile);
|
||||
if (!global.inifile && confpath) {
|
||||
_snprintf(inipath, sizeof(inipath), "%s/%s", confpath, inifile);
|
||||
parse_config(inipath);
|
||||
}
|
||||
if (!global.inifile) {
|
||||
log_error("could not open ini configuration %s\n", inifile);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue