summaryrefslogtreecommitdiff
path: root/src/common/HPM.c
diff options
context:
space:
mode:
authorYour Name <hemagx2@gmail.com>2015-12-12 21:44:27 +0200
committerHaru <haru@dotalux.com>2015-12-13 03:55:41 +0100
commitf102c913b2aa093ef40c7846e25850ebb1106d71 (patch)
tree8965bde6164baa50121171c7291ea438e11d8503 /src/common/HPM.c
parentbb214d4651c9c9aa9599f50cb5de52059176a87f (diff)
downloadhercules-f102c913b2aa093ef40c7846e25850ebb1106d71.tar.gz
hercules-f102c913b2aa093ef40c7846e25850ebb1106d71.tar.bz2
hercules-f102c913b2aa093ef40c7846e25850ebb1106d71.tar.xz
hercules-f102c913b2aa093ef40c7846e25850ebb1106d71.zip
- Fixed #723 now it's possible to retrieve Battle Config Settings from plugins into scripts
- Fixed Possible Crash when null parse function pointer passed to HPMi->addConf - Now it's possible to use same parse function for all config entries - Now Battle Config entries must have a return function
Diffstat (limited to 'src/common/HPM.c')
-rw-r--r--src/common/HPM.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 7d9a0b104..e5c3c47ba 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -389,11 +389,21 @@ bool hpm_add_arg(unsigned int pluginID, char *name, bool has_param, CmdlineExecF
* @retval true if the listener was added successfully.
* @retval false in case of error.
*/
-bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *name, void (*func) (const char *val))
+bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *name, void (*parse_func) (const char *key, const char *val), int (*return_func) (const char *key))
{
struct HPConfListenStorage *conf;
int i;
+ if (parse_func == NULL) {
+ ShowError("HPM->addConf:%s: missing setter function for config '%s'\n",HPM->pid2name(pluginID),name);
+ return false;
+ }
+
+ if (type == HPCT_BATTLE && return_func == NULL) {
+ ShowError("HPM->addConf:%s: missing getter function for config '%s'\n",HPM->pid2name(pluginID),name);
+ return false;
+ }
+
if (type >= HPCT_MAX) {
ShowError("HPM->addConf:%s: unknown point '%u' specified for config '%s'\n",HPM->pid2name(pluginID),type,name);
return false;
@@ -412,7 +422,8 @@ bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *na
conf->pluginID = pluginID;
safestrncpy(conf->key, name, HPM_ADDCONF_LENGTH);
- conf->func = func;
+ conf->parse_func = parse_func;
+ conf->return_func = return_func;
return true;
}
@@ -798,7 +809,29 @@ bool hplugins_parse_conf(const char *w1, const char *w2, enum HPluginConfType po
if (i == VECTOR_LENGTH(HPM->config_listeners[point]))
return false;
- VECTOR_INDEX(HPM->config_listeners[point], i).func(w2);
+ VECTOR_INDEX(HPM->config_listeners[point], i).parse_func(w1, w2);
+ return true;
+}
+
+/**
+ * Get a battle configuration entry through the registered plugins.
+ *
+ * @param[in] w1 The configuration entry name.
+ * @param[out] value Where the config result will be saved
+ * @retval true in case of data found
+ * @retval false in case of no data found
+ */
+bool hplugins_get_battle_conf(const char *w1, int *value)
+{
+ int i;
+
+ nullpo_retr(false, value);
+
+ ARR_FIND(0, VECTOR_LENGTH(HPM->config_listeners[HPCT_BATTLE]), i, strcmpi(w1, VECTOR_INDEX(HPM->config_listeners[HPCT_BATTLE], i).key) == 0);
+ if (i == VECTOR_LENGTH(HPM->config_listeners[HPCT_BATTLE]))
+ return false;
+
+ *value = VECTOR_INDEX(HPM->config_listeners[HPCT_BATTLE], i).return_func(w1);
return true;
}
@@ -1020,6 +1053,7 @@ void hpm_defaults(void)
HPM->load_sub = NULL;
HPM->addhook_sub = NULL;
HPM->parseConf = hplugins_parse_conf;
+ HPM->getBattleConf = hplugins_get_battle_conf;
HPM->DataCheck = HPM_DataCheck;
HPM->datacheck_init = HPM_datacheck_init;
HPM->datacheck_final = HPM_datacheck_final;