summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-02-13 15:38:23 +0100
committerHaru <haru@dotalux.com>2016-08-19 21:32:26 +0200
commit6cdb1e5ec2daa295b388d6c3a920b6cffe4193ce (patch)
treee4d67ff2bb7e80b6cab693f9ec24dac47b3a27a4 /src/common
parentc0e59c874786cdf3bc5863090934b8e18ba0336d (diff)
downloadhercules-6cdb1e5ec2daa295b388d6c3a920b6cffe4193ce.tar.gz
hercules-6cdb1e5ec2daa295b388d6c3a920b6cffe4193ce.tar.bz2
hercules-6cdb1e5ec2daa295b388d6c3a920b6cffe4193ce.tar.xz
hercules-6cdb1e5ec2daa295b388d6c3a920b6cffe4193ce.zip
Ported battle.conf to libconfig
Ported to modern Hercules and cleaned up from Panikon's commits: 44fea0b3cdba6901599265220228ba4359b1f96d, 9cba05bc0811e638bbaaa6cff887d0b2c9872560 Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/HPM.c49
-rw-r--r--src/common/HPM.h5
2 files changed, 52 insertions, 2 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 8e0bbe992..17dc4408e 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2013-2015 Hercules Dev Team
+ * Copyright (C) 2013-2016 Hercules Dev Team
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -859,6 +859,52 @@ bool hplugins_get_battle_conf(const char *w1, int *value)
}
/**
+ * Parses battle config entries registered by plugins.
+ *
+ * @param config The configuration file to parse.
+ * @param filename Path to configuration file.
+ * @param imported Whether the current config is imported from another file.
+ * @retval false in case of error.
+ */
+bool hplugins_parse_battle_conf(const struct config_t *config, const char *filename, bool imported)
+{
+ const struct config_setting_t *setting = NULL;
+ int i, val, type;
+ char str[1024];
+ bool retval = true;
+
+ nullpo_retr(false, config);
+
+ for (i = 0; i < VECTOR_LENGTH(HPM->config_listeners[HPCT_BATTLE]); i++) {
+ 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) {
+ ShowWarning("Missing configuration '%s' in file %s!\n", config_name, filename);
+ retval = false;
+ }
+ continue;
+ }
+
+ switch ((type = config_setting_type(setting))) {
+ case CONFIG_TYPE_INT:
+ val = libconfig->setting_get_int(setting);
+ break;
+ case CONFIG_TYPE_BOOL:
+ val = libconfig->setting_get_bool(setting);
+ break;
+ default: // Unsupported type
+ ShowWarning("Setting %s has unsupported type %d, ignoring...\n", config_name, type);
+ retval = false;
+ continue;
+ }
+ sprintf(str, "%d", val); // FIXME: Remove this when support to int's as value is added
+ entry->parse_func(config_name, str);
+ }
+ return retval;
+}
+
+/**
* Helper to destroy an interface's hplugin_data store and release any owned memory.
*
* The pointer will be cleared.
@@ -1074,6 +1120,7 @@ void hpm_defaults(void)
HPM->parse_packets = hplugins_parse_packets;
HPM->load_sub = NULL;
HPM->parseConf = hplugins_parse_conf;
+ HPM->parse_battle_conf = hplugins_parse_battle_conf;
HPM->getBattleConf = hplugins_get_battle_conf;
HPM->DataCheck = HPM_DataCheck;
HPM->datacheck_init = HPM_datacheck_init;
diff --git a/src/common/HPM.h b/src/common/HPM.h
index 0b1275fde..104522090 100644
--- a/src/common/HPM.h
+++ b/src/common/HPM.h
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2013-2015 Hercules Dev Team
+ * Copyright (C) 2013-2016 Hercules Dev Team
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -65,7 +65,9 @@
#endif // WIN32
+/* Forward Declarations */
struct HPMHooking_core_interface;
+struct config_t;
struct hplugin {
DLL dll;
@@ -155,6 +157,7 @@ struct HPM_interface {
void *(*import_symbol) (char *name, unsigned int pID);
void (*share) (void *value, const char *name);
void (*config_read) (void);
+ bool (*parse_battle_conf) (const struct config_t *config, const char *filename, bool imported);
char *(*pid2name) (unsigned int pid);
unsigned char (*parse_packets) (int fd, int packet_id, enum HPluginPacketHookingPoints point);
void (*load_sub) (struct hplugin *plugin);