From d80274aa9483c6d2d0e1a70b85f654a7d0eddb04 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Mon, 11 May 2020 01:33:39 +0200 Subject: Remove old mapreg table related code and config --- src/map/map.c | 11 +----- src/map/mapreg.h | 2 - src/map/mapreg_sql.c | 101 ++------------------------------------------------- 3 files changed, 5 insertions(+), 109 deletions(-) (limited to 'src/map') diff --git a/src/map/map.c b/src/map/map.c index d9be46bfb..63d05c1c0 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -4459,7 +4459,6 @@ static bool inter_config_read_connection(const char *filename, const struct conf static bool inter_config_read_database_names(const char *filename, const struct config_t *config, bool imported) { const struct config_setting_t *setting = NULL; - bool retval = true; nullpo_retr(false, filename); nullpo_retr(false, config); @@ -4477,20 +4476,14 @@ static bool inter_config_read_database_names(const char *filename, const struct libconfig->setting_lookup_mutable_string(setting, "npc_barter_data_db", map->npc_barter_data_db, sizeof(map->npc_barter_data_db)); libconfig->setting_lookup_mutable_string(setting, "npc_expanded_barter_data_db", map->npc_expanded_barter_data_db, sizeof(map->npc_expanded_barter_data_db)); - if (!mapreg->config_read(filename, setting, imported)) - retval = false; - if ((setting = libconfig->lookup(config, "inter_configuration/database_names/registry")) == NULL) { if (imported) - return retval; + return true; 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; + return mapreg->config_read_registry(filename, setting, imported); } /*======================================= diff --git a/src/map/mapreg.h b/src/map/mapreg.h index 772a6cb61..f97cd997d 100644 --- a/src/map/mapreg.h +++ b/src/map/mapreg.h @@ -47,7 +47,6 @@ 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. /* */ @@ -70,7 +69,6 @@ struct mapreg_interface { 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); }; #ifdef HERCULES_CORE diff --git a/src/map/mapreg_sql.c b/src/map/mapreg_sql.c index 376e582f9..cf509f027 100644 --- a/src/map/mapreg_sql.c +++ b/src/map/mapreg_sql.c @@ -101,11 +101,6 @@ static bool mapreg_setreg(int64 uid, int val) m->is_string = false; if (name[1] != '@' && !mapreg->skip_insert) {// write new variable to database - char tmp_str[(SCRIPT_VARNAME_LENGTH+1)*2+1]; - SQL->EscapeStringLen(map->mysql_handle, tmp_str, name, strnlen(name, SCRIPT_VARNAME_LENGTH+1)); - if( SQL_ERROR == SQL->Query(map->mysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%u','%d')", mapreg->table, tmp_str, i, val) ) - Sql_ShowDebug(map->mysql_handle); - struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); if (stmt == NULL) { @@ -136,9 +131,6 @@ static bool mapreg_setreg(int64 uid, int val) i64db_remove(mapreg->regs.vars, uid); if( name[1] != '@' ) {// Remove from database because it is unused. - if( SQL_ERROR == SQL->Query(map->mysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%u'", mapreg->table, name, i) ) - Sql_ShowDebug(map->mysql_handle); - struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); if (stmt == NULL) { @@ -182,9 +174,6 @@ static bool mapreg_setregstr(int64 uid, const char *str) if( i ) script->array_update(&mapreg->regs, uid, true); if(name[1] != '@') { - if (SQL_ERROR == SQL->Query(map->mysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%u'", mapreg->table, name, i)) - Sql_ShowDebug(map->mysql_handle); - struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); if (stmt == NULL) { @@ -230,13 +219,6 @@ static bool mapreg_setregstr(int64 uid, const char *str) m->is_string = true; if(name[1] != '@' && !mapreg->skip_insert) { //put returned null, so we must insert. - char tmp_str[(SCRIPT_VARNAME_LENGTH+1)*2+1]; - char tmp_str2[SCRIPT_STRING_VAR_LENGTH * 2 + 1]; - SQL->EscapeStringLen(map->mysql_handle, tmp_str, name, strnlen(name, SCRIPT_VARNAME_LENGTH+1)); - SQL->EscapeStringLen(map->mysql_handle, tmp_str2, str, strnlen(str, SCRIPT_STRING_VAR_LENGTH)); - if( SQL_ERROR == SQL->Query(map->mysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%u','%s')", mapreg->table, tmp_str, i, tmp_str2) ) - Sql_ShowDebug(map->mysql_handle); - struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); if (stmt == NULL) { @@ -371,55 +353,8 @@ static void mapreg_load_str_db(void) */ static void script_load_mapreg(void) { - /* - 0 1 2 - +-------------------------+ - | varname | index | value | - +-------------------------+ - */ - struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); - char varname[SCRIPT_VARNAME_LENGTH+1]; - int index; - char value[SCRIPT_STRING_VAR_LENGTH + 1]; - uint32 length; - - if ( SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `varname`, `index`, `value` FROM `%s`", mapreg->table) - || SQL_ERROR == SQL->StmtExecute(stmt) - ) { - SqlStmt_ShowDebug(stmt); - SQL->StmtFree(stmt); - return; - } - - mapreg->skip_insert = true; - - SQL->StmtBindColumn(stmt, 0, SQLDT_STRING, &varname, sizeof varname, &length, NULL); - SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &index, sizeof index, NULL, NULL); - SQL->StmtBindColumn(stmt, 2, SQLDT_STRING, &value, sizeof value, NULL, NULL); - - while ( SQL_SUCCESS == SQL->StmtNextRow(stmt) ) { - int s = script->add_variable(varname); - int i = index; - - - if( i64db_exists(mapreg->regs.vars, reference_uid(s, i)) ) { - ShowWarning("load_mapreg: duplicate! '%s' => '%s' skipping...\n",varname,value); - continue; - } - if( varname[length-1] == '$' ) { - mapreg->setregstr(reference_uid(s, i),value); - } else { - mapreg->setreg(reference_uid(s, i),atoi(value)); - } - } - - SQL->StmtFree(stmt); - - mapreg->skip_insert = false; - mapreg->load_num_db(); mapreg->load_str_db(); - mapreg->dirty = false; } @@ -508,19 +443,12 @@ static void script_save_mapreg(void) int i = script_getvaridx(m->uid); const char* name = script->get_str(num); nullpo_retv(name); - if (!m->is_string) { - if( SQL_ERROR == SQL->Query(map->mysql_handle, "UPDATE `%s` SET `value`='%d' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg->table, m->u.i, name, i) ) - Sql_ShowDebug(map->mysql_handle); + if (!m->is_string) mapreg->save_num_db(name, i, m->u.i); - } else { - char tmp_str2[SCRIPT_STRING_VAR_LENGTH * 2 + 1]; - SQL->EscapeStringLen(map->mysql_handle, tmp_str2, m->u.str, safestrnlen(m->u.str, SCRIPT_STRING_VAR_LENGTH)); - if( SQL_ERROR == SQL->Query(map->mysql_handle, "UPDATE `%s` SET `value`='%s' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg->table, tmp_str2, name, i) ) - Sql_ShowDebug(map->mysql_handle); - + else mapreg->save_str_db(name, i, m->u.str); - } + m->save = false; } } @@ -648,26 +576,6 @@ static void mapreg_init(void) timer->add_interval(timer->gettick() + MAPREG_AUTOSAVE_INTERVAL, mapreg->save_timer, 0, 0, MAPREG_AUTOSAVE_INTERVAL); } -/** - * Loads the mapreg 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. - * - * @retval false in case of error. - */ -static bool mapreg_config_read(const char *filename, const struct config_setting_t *config, bool imported) -{ - nullpo_retr(false, filename); - nullpo_retr(false, config); - - if (libconfig->setting_lookup_mutable_string(config, "mapreg_db", mapreg->table, sizeof(mapreg->table)) != CONFIG_TRUE) - return false; - - return true; -} - /** * Interface defaults initializer. */ @@ -680,7 +588,6 @@ void mapreg_defaults(void) mapreg->ers = NULL; 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; @@ -707,6 +614,4 @@ void mapreg_defaults(void) 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-70-g09d2