summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-08-02 01:35:41 +0200
committerHaru <haru@dotalux.com>2016-08-19 21:32:28 +0200
commit4e5b040d9db0e4dee576149c53fba070372b51c2 (patch)
treef3424b4a576ea5d44a1e1f29361d028e805d52c5 /src
parent67a84ce174851ed866b99737eec6bd0adfca6617 (diff)
downloadhercules-4e5b040d9db0e4dee576149c53fba070372b51c2.tar.gz
hercules-4e5b040d9db0e4dee576149c53fba070372b51c2.tar.bz2
hercules-4e5b040d9db0e4dee576149c53fba070372b51c2.tar.xz
hercules-4e5b040d9db0e4dee576149c53fba070372b51c2.zip
Added option to make plugin-defined battle config entries optional
When a setting optional, no warning is issued on the console when said setting is not found in the config Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src')
-rw-r--r--src/common/HPM.c5
-rw-r--r--src/common/HPM.h1
-rw-r--r--src/common/HPMi.h16
-rw-r--r--src/plugins/sample.c5
4 files changed, 15 insertions, 12 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 17dc4408e..a134a4822 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -407,7 +407,7 @@ 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 (*parse_func) (const char *key, const char *val), int (*return_func) (const char *key))
+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), bool required)
{
struct HPConfListenStorage *conf;
int i;
@@ -442,6 +442,7 @@ bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *na
safestrncpy(conf->key, name, HPM_ADDCONF_LENGTH);
conf->parse_func = parse_func;
conf->return_func = return_func;
+ conf->required = required;
return true;
}
@@ -879,7 +880,7 @@ bool hplugins_parse_battle_conf(const struct config_t *config, const char *filen
const struct HPConfListenStorage *entry = &VECTOR_INDEX(HPM->config_listeners[HPCT_BATTLE], i);
const char *config_name = entry->key;
if ((setting = libconfig->lookup(config, config_name)) == NULL) {
- if (!imported) {
+ if (!imported && entry->required) {
ShowWarning("Missing configuration '%s' in file %s!\n", config_name, filename);
retval = false;
}
diff --git a/src/common/HPM.h b/src/common/HPM.h
index 104522090..43f610a6a 100644
--- a/src/common/HPM.h
+++ b/src/common/HPM.h
@@ -123,6 +123,7 @@ struct HPConfListenStorage {
char key[HPM_ADDCONF_LENGTH];
void (*parse_func) (const char *key, const char *val);
int (*return_func) (const char *key);
+ bool required;
};
/* Hercules Plugin Manager Interface */
diff --git a/src/common/HPMi.h b/src/common/HPMi.h
index e16eb1d75..19b9b20a5 100644
--- a/src/common/HPMi.h
+++ b/src/common/HPMi.h
@@ -188,19 +188,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,returnfunc) HPMi->addConf(HPMi->pid,HPCT_BATTLE,bcname,funcname,returnfunc)
+#define addBattleConf(bcname, funcname, returnfunc, required) HPMi->addConf(HPMi->pid, HPCT_BATTLE, bcname, funcname, returnfunc, required)
/* HPMi->addLogin */
-#define addLoginConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_LOGIN,bcname,funcname,NULL)
+#define addLoginConf(bcname, funcname) HPMi->addConf(HPMi->pid, HPCT_LOGIN, bcname, funcname, NULL, false)
/* HPMi->addChar */
-#define addCharConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_CHAR,bcname,funcname,NULL)
+#define addCharConf(bcname, funcname) HPMi->addConf(HPMi->pid, HPCT_CHAR, bcname, funcname, NULL, false)
/* HPMi->addCharInter */
-#define addCharInterConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_CHAR_INTER,bcname,funcname,NULL)
+#define addCharInterConf(bcname, funcname) HPMi->addConf(HPMi->pid, HPCT_CHAR_INTER, bcname, funcname, NULL, false)
/* HPMi->addMapInter */
-#define addMapInterConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_MAP_INTER,bcname,funcname,NULL)
+#define addMapInterConf(bcname, funcname) HPMi->addConf(HPMi->pid, HPCT_MAP_INTER, bcname, funcname, NULL, false)
/* HPMi->addLog */
-#define addLogConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_LOG,bcname,funcname,NULL)
+#define addLogConf(bcname, funcname) HPMi->addConf(HPMi->pid, HPCT_LOG, bcname, funcname, NULL, false)
/* HPMi->addScript */
-#define addScriptConf(bcname,funcname) HPMi->addConf(HPMi->pid,HPCT_SCRIPT,bcname,funcname,NULL)
+#define addScriptConf(bcname, funcname) HPMi->addConf(HPMi->pid, HPCT_SCRIPT, bcname, funcname, NULL, false)
/* HPMi->addPCGPermission */
#define addGroupPermission(pcgname,maskptr) HPMi->addPCGPermission(HPMi->pid,pcgname,&maskptr)
@@ -223,7 +223,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 (*parse_func) (const char *key, const char *val), int (*return_func) (const char *key));
+ 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), bool required);
/* pc group permission */
void (*addPCGPermission) (unsigned int pluginID, char *name, unsigned int *mask);
diff --git a/src/plugins/sample.c b/src/plugins/sample.c
index b1ff4b39f..b37f7c4f7 100644
--- a/src/plugins/sample.c
+++ b/src/plugins/sample.c
@@ -213,11 +213,12 @@ HPExport void plugin_init (void) {
}
}
/* triggered when server starts loading, before any server-specific data is set */
-HPExport void server_preinit (void) {
+HPExport void server_preinit(void)
+{
/* makes map server listen to mysetting:value in any "battleconf" file (including imported or custom ones) */
/* value is not limited to numbers, its passed to our plugins handler (parse_my_setting) as const char *,
* however for battle config to be returned to our script engine we need it to be number (int) so keep use it as int only */
- addBattleConf("my_setting",parse_my_setting,return_my_setting);
+ addBattleConf("my_setting", parse_my_setting, return_my_setting, false);
}
/* run when server is ready (online) */
HPExport void server_online (void) {