From d958a36388644a9e58b63da0458f836d198833c8 Mon Sep 17 00:00:00 2001 From: gumi Date: Sat, 2 May 2020 09:26:33 -0400 Subject: add a config flag to allow local functions to be public by default --- conf/map/script.conf | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'conf') diff --git a/conf/map/script.conf b/conf/map/script.conf index fc4f26965..cda25d546 100644 --- a/conf/map/script.conf +++ b/conf/map/script.conf @@ -59,6 +59,11 @@ script_configuration: { // Defaults to INT_MAX. //input_max_value: 2147483647 input_max_value: 10000000 + + // Specifies whether functions not explicitly marked with a "private" or + // "public" keyword should be treated as "private" by default. + // Default: true + functions_private_by_default: true } import: "conf/import/script.conf" -- cgit v1.2.3-60-g2f50 From b12f1ff8be37346ec70ab50447c8f03bd9a990e1 Mon Sep 17 00:00:00 2001 From: gumi Date: Sat, 2 May 2020 09:35:01 -0400 Subject: add a config flag to allow to local functions to be event handlers --- conf/map/script.conf | 5 +++++ src/map/npc.c | 4 +++- src/map/script.c | 2 ++ src/map/script.h | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) (limited to 'conf') diff --git a/conf/map/script.conf b/conf/map/script.conf index cda25d546..4eb84edf4 100644 --- a/conf/map/script.conf +++ b/conf/map/script.conf @@ -64,6 +64,11 @@ script_configuration: { // "public" keyword should be treated as "private" by default. // Default: true functions_private_by_default: true + + // Specifies whether public functions can be invoked as NPC events. This + // allows, for example, to use a `public function OnDeath { ... }` instead + // of a `OnDeath:` label for mob death events. + functions_as_events: false } import: "conf/import/script.conf" diff --git a/src/map/npc.c b/src/map/npc.c index 570305ba1..2f03623e4 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -390,7 +390,9 @@ static int npc_event_export(struct npc_data *nd, int i) lname = nd->u.scr.label_list[i].name; pos = nd->u.scr.label_list[i].pos; - if ((nd->u.scr.label_list[i].flags & LABEL_IS_EXTERN) != 0 && (nd->u.scr.label_list[i].flags & LABEL_IS_USERFUNC) == 0) { + if ((nd->u.scr.label_list[i].flags & LABEL_IS_EXTERN) != 0 + && ((nd->u.scr.label_list[i].flags & LABEL_IS_USERFUNC) == 0 + || script->config.functions_as_events)) { struct event_data *ev; struct linkdb_node **label_linkdb = NULL; char buf[EVENT_NAME_LENGTH]; diff --git a/src/map/script.c b/src/map/script.c index 6f21f2a82..bf9348645 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -4973,6 +4973,7 @@ static bool script_config_read(const char *filename, bool imported) libconfig->setting_lookup_bool_real(setting, "warn_func_mismatch_paramnum", &script->config.warn_func_mismatch_paramnum); libconfig->setting_lookup_bool_real(setting, "warn_func_mismatch_argtypes", &script->config.warn_func_mismatch_argtypes); libconfig->setting_lookup_bool_real(setting, "functions_private_by_default", &script->config.functions_private_by_default); + libconfig->setting_lookup_bool_real(setting, "functions_as_events", &script->config.functions_as_events); libconfig->setting_lookup_int(setting, "check_cmdcount", &script->config.check_cmdcount); libconfig->setting_lookup_int(setting, "check_gotocount", &script->config.check_gotocount); libconfig->setting_lookup_int(setting, "input_min_value", &script->config.input_min_value); @@ -28576,6 +28577,7 @@ void script_defaults(void) script->config.ontouch2_name = "OnTouch"; //ontouch2_name (run whenever a char walks into the OnTouch area) script->config.onuntouch_name = "OnUnTouch"; //onuntouch_name (run whenever a char walks from the OnTouch area) script->config.functions_private_by_default = true; + script->config.functions_as_events = false; // for ENABLE_CASE_CHECK script->calc_hash_ci = calc_hash_ci; diff --git a/src/map/script.h b/src/map/script.h index 0a6a21f1b..5a031e9f5 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -585,6 +585,7 @@ struct Script_Config { bool warn_func_mismatch_argtypes; bool warn_func_mismatch_paramnum; bool functions_private_by_default; + bool functions_as_events; int check_cmdcount; int check_gotocount; int input_min_value; -- cgit v1.2.3-60-g2f50 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 --- conf/common/inter-server.conf | 3 ++- src/map/map.c | 4 ++++ src/map/mapreg.h | 3 +++ src/map/mapreg_sql.c | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) (limited to 'conf') diff --git a/conf/common/inter-server.conf b/conf/common/inter-server.conf index 7696774d6..1bcf34e23 100644 --- a/conf/common/inter-server.conf +++ b/conf/common/inter-server.conf @@ -76,9 +76,10 @@ inter_configuration: { acc_reg_str_db: "acc_reg_str_db" char_reg_str_db: "char_reg_str_db" char_reg_num_db: "char_reg_num_db" - global_acc_reg_num_db: "global_acc_reg_num_db" global_acc_reg_str_db: "global_acc_reg_str_db" + map_reg_num_db: "map_reg_num_db" + map_reg_str_db: "map_reg_str_db" } pc: { hotkey_db: "hotkey" 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 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 --- conf/common/inter-server.conf | 1 - src/map/map.c | 11 +-- src/map/mapreg.h | 2 - src/map/mapreg_sql.c | 101 +-------------------- src/plugins/HPMHooking/HPMHooking.Defs.inc | 2 - .../HPMHooking/HPMHooking_map.HPMHooksCore.inc | 4 - .../HPMHooking/HPMHooking_map.HookingPoints.inc | 1 - src/plugins/HPMHooking/HPMHooking_map.Hooks.inc | 27 ------ 8 files changed, 5 insertions(+), 144 deletions(-) (limited to 'conf') diff --git a/conf/common/inter-server.conf b/conf/common/inter-server.conf index 1bcf34e23..9960c46d6 100644 --- a/conf/common/inter-server.conf +++ b/conf/common/inter-server.conf @@ -114,7 +114,6 @@ inter_configuration: { position_db: "guild_position" storage_db: "guild_storage" } - mapreg_db: "mapreg" autotrade_merchants_db: "autotrade_merchants" autotrade_data_db: "autotrade_data" npc_market_data_db: "npc_market_data" 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; - } diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc index ef71f1967..c8dd6fed3 100644 --- a/src/plugins/HPMHooking/HPMHooking.Defs.inc +++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc @@ -5246,8 +5246,6 @@ typedef int (*HPMHOOK_pre_mapreg_destroyreg) (union DBKey *key, struct DBData ** typedef int (*HPMHOOK_post_mapreg_destroyreg) (int retVal___, union DBKey key, struct DBData *data, va_list ap); typedef void (*HPMHOOK_pre_mapreg_reload) (void); typedef void (*HPMHOOK_post_mapreg_reload) (void); -typedef bool (*HPMHOOK_pre_mapreg_config_read) (const char **filename, const struct config_setting_t **config, bool *imported); -typedef bool (*HPMHOOK_post_mapreg_config_read) (bool retVal___, const char *filename, const struct config_setting_t *config, bool imported); #endif // MAP_MAPREG_H #ifdef COMMON_MD5CALC_H /* md5 */ typedef void (*HPMHOOK_pre_md5_string) (const char **string, char **output); diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc index e8cb41240..c458ef539 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc @@ -3850,8 +3850,6 @@ struct { struct HPMHookPoint *HP_mapreg_destroyreg_post; struct HPMHookPoint *HP_mapreg_reload_pre; struct HPMHookPoint *HP_mapreg_reload_post; - struct HPMHookPoint *HP_mapreg_config_read_pre; - struct HPMHookPoint *HP_mapreg_config_read_post; struct HPMHookPoint *HP_md5_string_pre; struct HPMHookPoint *HP_md5_string_post; struct HPMHookPoint *HP_md5_binary_pre; @@ -10751,8 +10749,6 @@ struct { int HP_mapreg_destroyreg_post; int HP_mapreg_reload_pre; int HP_mapreg_reload_post; - int HP_mapreg_config_read_pre; - int HP_mapreg_config_read_post; int HP_md5_string_pre; int HP_md5_string_post; int HP_md5_binary_pre; diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc index 6b89841ad..bdfcbf931 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc @@ -1971,7 +1971,6 @@ struct HookingPointData HookingPoints[] = { { HP_POP(mapreg->save_timer, HP_mapreg_save_timer) }, { HP_POP(mapreg->destroyreg, HP_mapreg_destroyreg) }, { HP_POP(mapreg->reload, HP_mapreg_reload) }, - { HP_POP(mapreg->config_read, HP_mapreg_config_read) }, /* md5_interface */ { HP_POP(md5->string, HP_md5_string) }, { HP_POP(md5->binary, HP_md5_binary) }, diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc index 02d55228e..b25ca934b 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc @@ -50916,33 +50916,6 @@ void HP_mapreg_reload(void) { } return; } -bool HP_mapreg_config_read(const char *filename, const struct config_setting_t *config, bool imported) { - int hIndex = 0; - bool retVal___ = false; - if (HPMHooks.count.HP_mapreg_config_read_pre > 0) { - bool (*preHookFunc) (const char **filename, const struct config_setting_t **config, bool *imported); - *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_mapreg_config_read_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_mapreg_config_read_pre[hIndex].func; - retVal___ = preHookFunc(&filename, &config, &imported); - } - if (*HPMforce_return) { - *HPMforce_return = false; - return retVal___; - } - } - { - retVal___ = HPMHooks.source.mapreg.config_read(filename, config, imported); - } - if (HPMHooks.count.HP_mapreg_config_read_post > 0) { - bool (*postHookFunc) (bool retVal___, const char *filename, const struct config_setting_t *config, bool imported); - for (hIndex = 0; hIndex < HPMHooks.count.HP_mapreg_config_read_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_mapreg_config_read_post[hIndex].func; - retVal___ = postHookFunc(retVal___, filename, config, imported); - } - } - return retVal___; -} /* md5_interface */ void HP_md5_string(const char *string, char *output) { int hIndex = 0; -- cgit v1.2.3-60-g2f50 From a271110b6c53cf268747ab74d1471452909c5272 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Sun, 10 May 2020 03:02:56 +0200 Subject: Extend item_enabled_npc battle flag with option for usable items --- conf/map/battle/items.conf | 12 ++++++++---- src/map/battle.c | 2 +- src/map/clif.c | 4 ++-- src/map/pc.c | 3 ++- src/map/pc.h | 7 +++++++ src/map/script.c | 5 +++++ 6 files changed, 25 insertions(+), 8 deletions(-) (limited to 'conf') diff --git a/conf/map/battle/items.conf b/conf/map/battle/items.conf index 4788d7b30..ef383e19b 100644 --- a/conf/map/battle/items.conf +++ b/conf/map/battle/items.conf @@ -100,10 +100,14 @@ autospell_stacking: false // Default: true (official) item_restricted_consumption_type: true -// Enable all NPC to allow changing of equipments while interacting? (Note 1) -// Script commands 'enable_items/disable_items' will not be override. (see doc/script_commands.txt) -// Default: true (official) -item_enabled_npc: true +// Which item actions are allowed while interacting with NPC? (Note 3) +// Script commands 'enable_items/disable_items' will not be overridden. (See doc/script_commands.txt.) +// 0x0 (ITEMENABLEDNPC_NONE) - Don't allow any item actions. +// 0x1 (ITEMENABLEDNPC_EQUIP) - Allow changing equipment. +// 0x2 (ITEMENABLEDNPC_CONSUME) - Allow consuming usable items. +// Official RE: 0x1 (Default value.) +// Official Pre-RE: 0x3 +item_enabled_npc: 0x1 // Unequip the equipments that has disabled by map_zone_db.conf ? // 0 : disabled equipments and cards are nullify (official) diff --git a/src/map/battle.c b/src/map/battle.c index c8cd71b94..cf51f4fc5 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -7378,7 +7378,7 @@ static const struct battle_data { { "item_restricted_consumption_type", &battle_config.item_restricted_consumption_type,1, 0, 1, }, { "unequip_restricted_equipment", &battle_config.unequip_restricted_equipment, 0, 0, 3, }, { "max_walk_path", &battle_config.max_walk_path, 17, 1, MAX_WALKPATH, }, - { "item_enabled_npc", &battle_config.item_enabled_npc, 1, 0, 1, }, + { "item_enabled_npc", &battle_config.item_enabled_npc, 1, 0, INT_MAX, }, { "gm_ignore_warpable_area", &battle_config.gm_ignore_warpable_area, 0, 2, 100, }, { "packet_obfuscation", &battle_config.packet_obfuscation, 1, 0, 3, }, { "client_accept_chatdori", &battle_config.client_accept_chatdori, 0, 0, INT_MAX, }, diff --git a/src/map/clif.c b/src/map/clif.c index 7be5c6978..5a090301d 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -12038,7 +12038,7 @@ static void clif_parse_EquipItem(int fd, struct map_session_data *sd) return; //Out of bounds check. if( sd->npc_id ) { - if ( !sd->npc_item_flag ) + if ((sd->npc_item_flag & ITEMENABLEDNPC_EQUIP) == 0) return; } else if (sd->state.storage_flag != STORAGE_FLAG_CLOSED || sd->sc.opt1) ; //You can equip/unequip stuff while storage is open/under status changes @@ -12083,7 +12083,7 @@ static void clif_parse_UnequipItem(int fd, struct map_session_data *sd) } if( sd->npc_id ) { - if ( !sd->npc_item_flag ) + if ((sd->npc_item_flag & ITEMENABLEDNPC_EQUIP) == 0) return; } else if (sd->state.storage_flag != STORAGE_FLAG_CLOSED || sd->sc.opt1) ; //You can equip/unequip stuff while storage is open/under status changes diff --git a/src/map/pc.c b/src/map/pc.c index 5faadf76a..c6f8ef4f9 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -5162,7 +5162,8 @@ static int pc_useitem(struct map_session_data *sd, int n) nullpo_ret(sd); Assert_ret(n >= 0 && n < sd->status.inventorySize); - if (sd->npc_id || sd->state.workinprogress & 1) { + if ((sd->npc_id != 0 && (sd->npc_item_flag & ITEMENABLEDNPC_CONSUME) == 0) + || (sd->state.workinprogress & 1) != 0) { #if PACKETVER >= 20110308 clif->msgtable(sd, MSG_BUSY); #else diff --git a/src/map/pc.h b/src/map/pc.h index e560df549..01fd855b7 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -103,6 +103,13 @@ enum pc_checkitem_types { PCCHECKITEM_GSTORAGE = 0x8 }; +/** Bit flags for allowed item actions while interacting with NPC. **/ +enum item_enabled_npc_flags { + ITEMENABLEDNPC_NONE = 0x0, //!< Don't allow any item actions while interacting with NPC. + ITEMENABLEDNPC_EQUIP = 0x1, //!< Allow changing equipment while interacting with NPC. + ITEMENABLEDNPC_CONSUME = 0x2, //!< Allow consuming usable items while interacting with NPC. +}; + struct weapon_data { int atkmods[3]; BEGIN_ZEROED_BLOCK; // all the variables within this block get zero'ed in each call of status_calc_pc diff --git a/src/map/script.c b/src/map/script.c index 45c954dc0..46b7ef8f5 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -27864,6 +27864,11 @@ static void script_hardcoded_constants(void) script->set_constant("PCBLOCK_COMMANDS", PCBLOCK_COMMANDS, false, false); script->set_constant("PCBLOCK_NPC", PCBLOCK_NPC, false, false); + script->constdb_comment("NPC item action constants"); + script->set_constant("ITEMENABLEDNPC_NONE", ITEMENABLEDNPC_NONE, false, false); + script->set_constant("ITEMENABLEDNPC_EQUIP", ITEMENABLEDNPC_EQUIP, false, false); + script->set_constant("ITEMENABLEDNPC_CONSUME", ITEMENABLEDNPC_CONSUME, false, false); + script->constdb_comment("private airship responds"); script->set_constant("P_AIRSHIP_NONE", P_AIRSHIP_NONE, false, false); script->set_constant("P_AIRSHIP_RETRY", P_AIRSHIP_RETRY, false, false); -- cgit v1.2.3-60-g2f50 From 9a64eca5235da46655ca64ba5916c6fd4d90208a Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Sun, 10 May 2020 03:05:29 +0200 Subject: Add skill_enabled_npc battle flag and implement usage --- conf/map/battle/skill.conf | 8 ++++++++ src/map/battle.c | 1 + src/map/battle.h | 2 ++ src/map/clif.c | 18 ++++++++++++------ src/map/pc.h | 1 + src/map/script.c | 5 +++++ src/map/skill.h | 7 +++++++ 7 files changed, 36 insertions(+), 6 deletions(-) (limited to 'conf') diff --git a/conf/map/battle/skill.conf b/conf/map/battle/skill.conf index a40b52124..fe9ca638a 100644 --- a/conf/map/battle/skill.conf +++ b/conf/map/battle/skill.conf @@ -347,3 +347,11 @@ stormgust_knockback: true // 0 : (official) Magic Rod's animation occurs every time it is used. // 1 : Magic Rod's animation would not occur unless a spell was absorbed. (old behavior) magicrod_type: 0 + +// Which skills are allowed to use while interacting with NPC? +// 0 (SKILLENABLEDNPC_NONE) - Don't allow using skills. +// 1 (SKILLENABLEDNPC_SELF) - Allow using non-damaging self skills. +// 2 (SKILLENABLEDNPC_ALL) - Allow using all skills. +// Official RE: 0 (Default value.) +// Official Pre-RE: 1 +skill_enabled_npc: 0 diff --git a/src/map/battle.c b/src/map/battle.c index cf51f4fc5..d99daca14 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -7425,6 +7425,7 @@ static const struct battle_data { { "min_item_sell_price", &battle_config.min_item_sell_price, 0, 0, INT_MAX, }, { "display_fake_hp_when_dead", &battle_config.display_fake_hp_when_dead, 1, 0, 1, }, { "magicrod_type", &battle_config.magicrod_type, 0, 0, 1, }, + { "skill_enabled_npc", &battle_config.skill_enabled_npc, 0, 0, INT_MAX, }, { "features/enable_achievement_system", &battle_config.feature_enable_achievement, 1, 0, 1, }, { "ping_timer_inverval", &battle_config.ping_timer_interval, 30, 0, 99999999, }, { "ping_time", &battle_config.ping_time, 20, 0, 99999999, }, diff --git a/src/map/battle.h b/src/map/battle.h index bb907d5b9..55ee32445 100644 --- a/src/map/battle.h +++ b/src/map/battle.h @@ -580,6 +580,8 @@ struct Battle_Config { int magicrod_type; + int skill_enabled_npc; + int feature_enable_achievement; int ping_timer_interval; diff --git a/src/map/clif.c b/src/map/clif.c index 5a090301d..4f0859a4c 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -12832,7 +12832,11 @@ static void clif_useSkillToIdReal(int fd, struct map_session_data *sd, int skill // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex] pc->update_idle_time(sd, BCIDLE_USESKILLTOID); - if (sd->npc_id || sd->state.workinprogress & 1) { + bool allow_self_skill = ((tmp & INF_SELF_SKILL) != 0 && (skill->get_nk(skill_id) & NK_NO_DAMAGE) != 0); + allow_self_skill = (allow_self_skill && battle_config.skill_enabled_npc == SKILLENABLEDNPC_SELF); + + if ((sd->npc_id != 0 && !allow_self_skill && battle_config.skill_enabled_npc != SKILLENABLEDNPC_ALL) + || (sd->state.workinprogress & 1) != 0) { #if PACKETVER >= 20110308 clif->msgtable(sd, MSG_BUSY); #else @@ -12841,7 +12845,7 @@ static void clif_useSkillToIdReal(int fd, struct map_session_data *sd, int skill return; } - if (pc_cant_act(sd) + if (pc_cant_act_except_npc(sd) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) && (sd->state.storage_flag != STORAGE_FLAG_CLOSED && !(tmp&INF_SELF_SKILL)) // SELF skills can be used with the storage open, issue: 8027 @@ -12976,7 +12980,8 @@ static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uin return; } - if (sd->state.workinprogress & 1) { + if ((sd->npc_id != 0 && battle_config.skill_enabled_npc != SKILLENABLEDNPC_ALL) + || (sd->state.workinprogress & 1) != 0) { #if PACKETVER >= 20110308 clif->msgtable(sd, MSG_BUSY); #else @@ -13046,7 +13051,7 @@ static void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd) __attr /// There are various variants of this packet, some of them have padding between fields. static void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd) { - if (pc_cant_act(sd)) + if (pc_cant_act_except_npc(sd)) return; if (pc_issit(sd)) return; @@ -13067,7 +13072,7 @@ static void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd /// There are various variants of this packet, some of them have padding between fields. static void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd) { - if (pc_cant_act(sd)) + if (pc_cant_act_except_npc(sd)) return; if (pc_issit(sd)) return; @@ -13096,7 +13101,8 @@ static void clif_parse_UseSkillMap(int fd, struct map_session_data *sd) return; // It is possible to use teleport with the storage window open issue:8027 - if (pc_cant_act(sd) && (sd->state.storage_flag == STORAGE_FLAG_CLOSED && skill_id != AL_TELEPORT)) { + if ((pc_cant_act_except_npc(sd) && sd->state.storage_flag == STORAGE_FLAG_CLOSED && skill_id != AL_TELEPORT) + || (sd->npc_id != 0 && battle_config.skill_enabled_npc != SKILLENABLEDNPC_ALL)) { clif_menuskill_clear(sd); return; } diff --git a/src/map/pc.h b/src/map/pc.h index 01fd855b7..f9526c248 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -686,6 +686,7 @@ END_ZEROED_BLOCK; #define pc_istrading(sd) ( (sd)->npc_id || (sd)->state.vending || (sd)->state.buyingstore || (sd)->state.trading ) #define pc_cant_act(sd) ( (sd)->npc_id || (sd)->state.vending || (sd)->state.buyingstore || (sd)->chat_id != 0 || ((sd)->sc.opt1 && (sd)->sc.opt1 != OPT1_BURNING) || (sd)->state.trading || (sd)->state.storage_flag || (sd)->state.prevend || (sd)->state.refine_ui == 1 || (sd)->state.lapine_ui == 1) #define pc_cant_act_except_lapine(sd) ((sd)->npc_id || (sd)->state.vending || (sd)->state.buyingstore || (sd)->chat_id != 0 || ((sd)->sc.opt1 && (sd)->sc.opt1 != OPT1_BURNING) || (sd)->state.trading || (sd)->state.storage_flag || (sd)->state.prevend || (sd)->state.refine_ui == 1) +#define pc_cant_act_except_npc(sd) ( (sd)->state.vending != 0 || (sd)->state.buyingstore != 0 || (sd)->chat_id != 0 || ((sd)->sc.opt1 != 0 && (sd)->sc.opt1 != OPT1_BURNING) || (sd)->state.trading != 0 || (sd)->state.storage_flag != 0 || (sd)->state.prevend != 0 || (sd)->state.refine_ui == 1 || (sd)->state.lapine_ui == 1) /* equals pc_cant_act except it doesn't check for chat rooms */ #define pc_cant_act2(sd) ( (sd)->npc_id || (sd)->state.buyingstore || ((sd)->sc.opt1 && (sd)->sc.opt1 != OPT1_BURNING) || (sd)->state.trading || (sd)->state.storage_flag || (sd)->state.prevend || (sd)->state.refine_ui == 1 || (sd)->state.lapine_ui == 1) diff --git a/src/map/script.c b/src/map/script.c index bda461d5d..7ba9fd276 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -27918,6 +27918,11 @@ static void script_hardcoded_constants(void) script->set_constant("ITEMENABLEDNPC_EQUIP", ITEMENABLEDNPC_EQUIP, false, false); script->set_constant("ITEMENABLEDNPC_CONSUME", ITEMENABLEDNPC_CONSUME, false, false); + script->constdb_comment("NPC allowed skill use constants"); + script->set_constant("SKILLENABLEDNPC_NONE", SKILLENABLEDNPC_NONE, false, false); + script->set_constant("SKILLENABLEDNPC_SELF", SKILLENABLEDNPC_SELF, false, false); + script->set_constant("SKILLENABLEDNPC_ALL", SKILLENABLEDNPC_ALL, false, false); + script->constdb_comment("private airship responds"); script->set_constant("P_AIRSHIP_NONE", P_AIRSHIP_NONE, false, false); script->set_constant("P_AIRSHIP_RETRY", P_AIRSHIP_RETRY, false, false); diff --git a/src/map/skill.h b/src/map/skill.h index 4dbbaf147..e8360c91f 100644 --- a/src/map/skill.h +++ b/src/map/skill.h @@ -1733,6 +1733,13 @@ enum autocast_type { AUTOCAST_ITEM, // Used for itemskill() script command. }; +/** Constants for allowed skill use while interacting with NPC. **/ +enum skill_enabled_npc_flags { + SKILLENABLEDNPC_NONE = 0, //!< Don't allow using any skills while interacting with NPC. + SKILLENABLEDNPC_SELF = 1, //!< Allow using non-damaging self skills while interacting with NPC. + SKILLENABLEDNPC_ALL = 2, //!< Allow using all skills while interacting with NPC. +}; + /** * Structures **/ -- cgit v1.2.3-60-g2f50 From ba9bbcb3384e80865ce2786368a19239d0f66604 Mon Sep 17 00:00:00 2001 From: Jedzkie Date: Sat, 30 May 2020 12:16:57 +0800 Subject: Player always faces north when warped. --- conf/map/battle/player.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'conf') diff --git a/conf/map/battle/player.conf b/conf/map/battle/player.conf index b691f7343..c25159717 100644 --- a/conf/map/battle/player.conf +++ b/conf/map/battle/player.conf @@ -225,4 +225,4 @@ shadow_refine_atk: true // Keep player facing direction after warping? // Default: false (on official servers players always faces north) -player_warp_keep_direction: true +player_warp_keep_direction: false -- cgit v1.2.3-60-g2f50