diff options
author | Kenpachi Developer <Kenpachi.Developer@gmx.de> | 2020-05-10 23:29:47 +0200 |
---|---|---|
committer | Kenpachi Developer <Kenpachi.Developer@gmx.de> | 2020-05-12 03:45:25 +0200 |
commit | e14e4c77614afa2cacab9b5042554702da4b04fa (patch) | |
tree | b660880f41e2bcb2bf92923d691e2ec7ef5a8100 /src/map | |
parent | 41b883d4c27b21567eb2558b84ce80c43765b979 (diff) | |
download | hercules-e14e4c77614afa2cacab9b5042554702da4b04fa.tar.gz hercules-e14e4c77614afa2cacab9b5042554702da4b04fa.tar.bz2 hercules-e14e4c77614afa2cacab9b5042554702da4b04fa.tar.xz hercules-e14e4c77614afa2cacab9b5042554702da4b04fa.zip |
Read name of new map_reg_*_db tables from configuration file
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/map.c | 4 | ||||
-rw-r--r-- | src/map/mapreg.h | 3 | ||||
-rw-r--r-- | src/map/mapreg_sql.c | 39 |
3 files changed, 46 insertions, 0 deletions
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 @@ -329,6 +329,42 @@ static void mapreg_reload(void) } /** + * 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. */ static void mapreg_final(void) @@ -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; } |