summaryrefslogtreecommitdiff
path: root/src/common
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
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')
-rw-r--r--src/common/HPM.c40
-rw-r--r--src/common/HPM.h4
-rw-r--r--src/common/HPMi.h16
3 files changed, 48 insertions, 12 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;
diff --git a/src/common/HPM.h b/src/common/HPM.h
index 5420e5300..bcf831d0e 100644
--- a/src/common/HPM.h
+++ b/src/common/HPM.h
@@ -101,7 +101,8 @@ struct HPMFileNameCache {
struct HPConfListenStorage {
unsigned int pluginID;
char key[HPM_ADDCONF_LENGTH];
- void (*func) (const char *val);
+ void (*parse_func) (const char *key, const char *val);
+ int (*return_func) (const char *key);
};
/* Hercules Plugin Manager Interface */
@@ -145,6 +146,7 @@ struct HPM_interface {
bool (*addhook_sub) (enum HPluginHookType type, const char *target, void *hook, unsigned int pID);
/* for custom config parsing */
bool (*parseConf) (const char *w1, const char *w2, enum HPluginConfType point);
+ bool (*getBattleConf) (const char* w1, int *value);
/* validates plugin data */
bool (*DataCheck) (struct s_HPMDataCheck *src, unsigned int size, int version, char *name);
void (*datacheck_init) (const struct s_HPMDataCheck *src, unsigned int length, int version);
diff --git a/src/common/HPMi.h b/src/common/HPMi.h
index 9a61dd256..5b62f80d9 100644
--- a/src/common/HPMi.h
+++ b/src/common/HPMi.h
@@ -183,19 +183,19 @@ enum HPluginConfType {
/* HPMi->addPacket */
#define addPacket(cmd,len,receive,point) HPMi->addPacket(cmd,len,receive,point,HPMi->pid)
/* HPMi->addBattleConf */
-#define addBattleConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_BATTLE,bcname,funcname)
+#define addBattleConf(bcname,funcname,returnfunc) HPMi->addConf(HPMi->pid,HPCT_BATTLE,bcname,funcname,returnfunc)
/* HPMi->addLogin */
-#define addLoginConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_LOGIN,bcname,funcname)
+#define addLoginConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_LOGIN,bcname,funcname,NULL)
/* HPMi->addChar */
-#define addCharConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_CHAR,bcname,funcname)
+#define addCharConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_CHAR,bcname,funcname,NULL)
/* HPMi->addCharInter */
-#define addCharInterConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_CHAR_INTER,bcname,funcname)
+#define addCharInterConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_CHAR_INTER,bcname,funcname,NULL)
/* HPMi->addMapInter */
-#define addMapInterConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_MAP_INTER,bcname,funcname)
+#define addMapInterConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_MAP_INTER,bcname,funcname,NULL)
/* HPMi->addLog */
-#define addLogConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_LOG,bcname,funcname)
+#define addLogConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_LOG,bcname,funcname,NULL)
/* HPMi->addScript */
-#define addScriptConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_SCRIPT,bcname,funcname)
+#define addScriptConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_SCRIPT,bcname,funcname,NULL)
/* HPMi->addPCGPermission */
#define addGroupPermission(pcgname,maskptr) HPMi->addPCGPermission(HPMi->pid,pcgname,&maskptr)
@@ -222,7 +222,7 @@ struct HPMi_interface {
/* program --arg/-a */
bool (*addArg) (unsigned int pluginID, char *name, bool has_param, CmdlineExecFunc func, const char *help);
/* battle-config recv param */
- bool (*addConf) (unsigned int pluginID, enum HPluginConfType type, char *name, void (*func) (const char *val));
+ bool (*addConf) (unsigned int pluginID, enum HPluginConfType type, char *name, void (*parse_func) (const char *key, const char *val), int (*return_func) (const char *key));
/* pc group permission */
void (*addPCGPermission) (unsigned int pluginID, char *name, unsigned int *mask);