From e14e4c77614afa2cacab9b5042554702da4b04fa Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Sun, 10 May 2020 23:29:47 +0200 Subject: Read name of new map_reg_*_db tables from configuration file --- src/map/map.c | 4 ++++ src/map/mapreg.h | 3 +++ src/map/mapreg_sql.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) (limited to 'src') diff --git a/src/map/map.c b/src/map/map.c index f66f40dfc..d9be46bfb 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -4486,6 +4486,10 @@ static bool inter_config_read_database_names(const char *filename, const struct ShowError("inter_config_read: inter_configuration/database_names/registry was not found in %s!\n", filename); return false; } + + if (!mapreg->config_read_registry(filename, setting, imported)) + retval = false; + return retval; } diff --git a/src/map/mapreg.h b/src/map/mapreg.h index b3b89e1b2..bd0e13e21 100644 --- a/src/map/mapreg.h +++ b/src/map/mapreg.h @@ -48,6 +48,8 @@ struct mapreg_interface { struct eri *ers; //[Ind/Hercules] /* */ char table[32]; + char num_db[32]; //!< Name of SQL table which holds permanent global integer variables. + char str_db[32]; //!< Name of SQL table which holds permanent global string variables. /* */ bool dirty; ///< Whether there are modified regs to be saved /* */ @@ -63,6 +65,7 @@ struct mapreg_interface { int (*save_timer) (int tid, int64 tick, int id, intptr_t data); int (*destroyreg) (union DBKey key, struct DBData *data, va_list ap); void (*reload) (void); + bool (*config_read_registry) (const char *filename, const struct config_setting_t *config, bool imported); bool (*config_read) (const char *filename, const struct config_setting_t *config, bool imported); }; diff --git a/src/map/mapreg_sql.c b/src/map/mapreg_sql.c index 2963637da..a461763fa 100644 --- a/src/map/mapreg_sql.c +++ b/src/map/mapreg_sql.c @@ -328,6 +328,42 @@ static void mapreg_reload(void) mapreg->load(); } +/** + * Loads the mapreg database table names from configuration file. + * + * @param filename Path to configuration file. (Used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * @return True on success, otherwise false. + * + **/ +static bool mapreg_config_read_registry(const char *filename, const struct config_setting_t *config, bool imported) +{ + nullpo_retr(false, filename); + nullpo_retr(false, config); + + bool ret_val = true; + size_t sz = sizeof(mapreg->num_db); + int result = libconfig->setting_lookup_mutable_string(config, "map_reg_num_db", mapreg->num_db, sz); + + if (result != CONFIG_TRUE && !imported) { + ShowError("%s: inter_configuration/database_names/registry/map_reg_num_db was not found in %s!\n", + __func__, filename); + ret_val = false; + } + + sz = sizeof(mapreg->str_db); + result = libconfig->setting_lookup_mutable_string(config, "map_reg_str_db", mapreg->str_db, sz); + + if (result != CONFIG_TRUE && !imported) { + ShowError("%s: inter_configuration/database_names/registry/map_reg_str_db was not found in %s!\n", + __func__, filename); + ret_val = false; + } + + return ret_val; +} + /** * Finalizer. */ @@ -390,6 +426,8 @@ void mapreg_defaults(void) mapreg->skip_insert = false; safestrncpy(mapreg->table, "mapreg", sizeof(mapreg->table)); + safestrncpy(mapreg->num_db, "map_reg_num_db", sizeof(mapreg->num_db)); + safestrncpy(mapreg->str_db, "map_reg_str_db", sizeof(mapreg->str_db)); mapreg->dirty = false; /* */ @@ -409,6 +447,7 @@ void mapreg_defaults(void) mapreg->save_timer = script_autosave_mapreg; mapreg->destroyreg = mapreg_destroyreg; mapreg->reload = mapreg_reload; + mapreg->config_read_registry = mapreg_config_read_registry; mapreg->config_read = mapreg_config_read; } -- cgit v1.2.3-60-g2f50