diff options
Diffstat (limited to 'src/map/mapreg_sql.c')
-rw-r--r-- | src/map/mapreg_sql.c | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/src/map/mapreg_sql.c b/src/map/mapreg_sql.c index 82ce39d64..741505e17 100644 --- a/src/map/mapreg_sql.c +++ b/src/map/mapreg_sql.c @@ -2,8 +2,8 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team - * Copyright (C) Athena Dev Teams + * Copyright (C) 2012-2020 Hercules Dev Team + * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,6 +25,7 @@ #include "map/map.h" // map-"mysql_handle #include "map/script.h" #include "common/cbasetypes.h" +#include "common/conf.h" #include "common/db.h" #include "common/ers.h" #include "common/memmgr.h" @@ -37,7 +38,7 @@ #include <stdlib.h> #include <string.h> -struct mapreg_interface mapreg_s; +static struct mapreg_interface mapreg_s; struct mapreg_interface *mapreg; #define MAPREG_AUTOSAVE_INTERVAL (300*1000) @@ -48,7 +49,8 @@ struct mapreg_interface *mapreg; * @param uid variable's unique identifier. * @return variable's integer value */ -int mapreg_readreg(int64 uid) { +static int mapreg_readreg(int64 uid) +{ struct mapreg_save *m = i64db_get(mapreg->regs.vars, uid); return m?m->u.i:0; } @@ -59,7 +61,8 @@ int mapreg_readreg(int64 uid) { * @param uid variable's unique identifier * @return variable's string value */ -char* mapreg_readregstr(int64 uid) { +static char *mapreg_readregstr(int64 uid) +{ struct mapreg_save *m = i64db_get(mapreg->regs.vars, uid); return m?m->u.str:NULL; } @@ -71,7 +74,8 @@ char* mapreg_readregstr(int64 uid) { * @param val new value * @retval true value was successfully set */ -bool mapreg_setreg(int64 uid, int val) { +static bool mapreg_setreg(int64 uid, int val) +{ struct mapreg_save *m; int num = script_getvarid(uid); unsigned int i = script_getvaridx(uid); @@ -128,7 +132,8 @@ bool mapreg_setreg(int64 uid, int val) { * @param str new value * @retval true value was successfully set */ -bool mapreg_setregstr(int64 uid, const char* str) { +static bool mapreg_setregstr(int64 uid, const char *str) +{ struct mapreg_save *m; int num = script_getvarid(uid); unsigned int i = script_getvaridx(uid); @@ -187,7 +192,8 @@ bool mapreg_setregstr(int64 uid, const char* str) { /** * Loads permanent variables from database. */ -void script_load_mapreg(void) { +static void script_load_mapreg(void) +{ /* 0 1 2 +-------------------------+ @@ -210,12 +216,12 @@ void script_load_mapreg(void) { mapreg->skip_insert = true; - SQL->StmtBindColumn(stmt, 0, SQLDT_STRING, &varname[0], sizeof(varname), &length, NULL); - SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &index, 0, NULL, NULL); - SQL->StmtBindColumn(stmt, 2, SQLDT_STRING, &value[0], sizeof(value), NULL, NULL); + 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_str(varname); + int s = script->add_variable(varname); int i = index; @@ -240,7 +246,7 @@ void script_load_mapreg(void) { /** * Saves permanent variables to database. */ -void script_save_mapreg(void) +static void script_save_mapreg(void) { if (mapreg->dirty) { struct DBIterator *iter = db_iterator(mapreg->regs.vars); @@ -273,7 +279,8 @@ void script_save_mapreg(void) * * @see timer->do_timer */ -int script_autosave_mapreg(int tid, int64 tick, int id, intptr_t data) { +static int script_autosave_mapreg(int tid, int64 tick, int id, intptr_t data) +{ mapreg->save(); return 0; } @@ -283,7 +290,7 @@ int script_autosave_mapreg(int tid, int64 tick, int id, intptr_t data) { * * @see DBApply */ -int mapreg_destroyreg(union DBKey key, struct DBData *data, va_list ap) +static int mapreg_destroyreg(union DBKey key, struct DBData *data, va_list ap) { struct mapreg_save *m = NULL; @@ -307,7 +314,8 @@ int mapreg_destroyreg(union DBKey key, struct DBData *data, va_list ap) * This has the effect of clearing the temporary variables, and * reloading the permanent ones. */ -void mapreg_reload(void) { +static void mapreg_reload(void) +{ mapreg->save(); mapreg->regs.vars->clear(mapreg->regs.vars, mapreg->destroyreg); @@ -323,7 +331,8 @@ void mapreg_reload(void) { /** * Finalizer. */ -void mapreg_final(void) { +static void mapreg_final(void) +{ mapreg->save(); mapreg->regs.vars->destroy(mapreg->regs.vars, mapreg->destroyreg); @@ -337,7 +346,8 @@ void mapreg_final(void) { /** * Initializer. */ -void mapreg_init(void) { +static void mapreg_init(void) +{ mapreg->regs.vars = i64db_alloc(DB_OPT_BASE); mapreg->ers = ers_new(sizeof(struct mapreg_save), "mapreg_sql.c::mapreg_ers", ERS_OPT_CLEAN); @@ -349,13 +359,19 @@ void mapreg_init(void) { /** * 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. */ -bool mapreg_config_read(const char* w1, const char* w2) { - nullpo_retr(false, w1); - nullpo_retr(false, w2); - if(!strcmpi(w1, "mapreg_db")) - safestrncpy(mapreg->table, w2, sizeof(mapreg->table)); - else +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; @@ -364,7 +380,8 @@ bool mapreg_config_read(const char* w1, const char* w2) { /** * Interface defaults initializer. */ -void mapreg_defaults(void) { +void mapreg_defaults(void) +{ mapreg = &mapreg_s; /* */ |