From 758bb4252efc30447dbe391e5818a940efc42b46 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 30 Mar 2021 16:17:34 +0300 Subject: [PATCH 38/38] Make it possible to use custom database.lua See osdn #41880 Signed-off-by: Marko Lindqvist --- doc/README.fcdb | 6 ++++++ server/fcdb.c | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc/README.fcdb b/doc/README.fcdb index 595e356f7f..6ce1663039 100644 --- a/doc/README.fcdb +++ b/doc/README.fcdb @@ -158,6 +158,12 @@ The script lives in data/database.lua in the source tree, and is installed to 'sysconfdir'; depending on the options given to 'configure' at build time, this may be a location like /usr/local/etc/freeciv/database.lua. +To use custom database.lua, give name of the file with its full path +in the conf file entry "lua" in [fcdb] section, e.g.: + + [fcdb] + lua="/etc/freeciv/local_database.lua" + The supplied version supports basic authentication against a SQLite or MySQL database; it supports configuration as shown in the following example (for MySQL; SQLite does not need all of these options). diff --git a/server/fcdb.c b/server/fcdb.c index 0befbf3a6e..0e6621fbe3 100644 --- a/server/fcdb.c +++ b/server/fcdb.c @@ -74,6 +74,8 @@ struct fcdb_option { struct fcdb_option_hash *fcdb_config = NULL; +char *fcdb_script = NULL; + static bool fcdb_set_option(const char *key, const char *value, enum fcdb_option_source source); static bool fcdb_load_config(const char *filename); @@ -132,13 +134,21 @@ static bool fcdb_load_config(const char *filename) pentry) { if (entry_type_get(pentry) == ENTRY_STR) { const char *value; + const char *name; #ifndef FREECIV_NDEBUG bool entry_str_get_success = #endif /* FREECIV_NDEBUG */ entry_str_get(pentry, &value); fc_assert(entry_str_get_success); - fcdb_set_option(entry_name(pentry), value, AOS_FILE); + + name = entry_name(pentry); + if (!strcasecmp("lua", name)) { + free(fcdb_script); + fcdb_script = fc_strdup(value); + } else { + fcdb_set_option(name, value, AOS_FILE); + } } else { log_error("Value for '%s' in '%s' is not of string type, ignoring", entry_name(pentry), filename); @@ -168,7 +178,7 @@ bool fcdb_init(const char *conf_file) log_debug("No fcdb config file."); } - return script_fcdb_init(NULL); + return script_fcdb_init(fcdb_script); } /************************************************************************//** -- 2.30.2