summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2019-07-28 22:37:07 +0200
committerGitHub <noreply@github.com>2019-07-28 22:37:07 +0200
commit893a01ab14ad56579a4c280ac7a302e4e6d7c755 (patch)
treeb4e40b659924f9f0a08a9ab63be79307ddbab699 /src
parentcd04fd96954ccb9fbbe33d05ad1eb3e2f7ce98c5 (diff)
parentc67015a13bd6ed0e3be7fcbb0db525fa482c9bda (diff)
downloadhercules-893a01ab14ad56579a4c280ac7a302e4e6d7c755.tar.gz
hercules-893a01ab14ad56579a4c280ac7a302e4e6d7c755.tar.bz2
hercules-893a01ab14ad56579a4c280ac7a302e4e6d7c755.tar.xz
hercules-893a01ab14ad56579a4c280ac7a302e4e6d7c755.zip
Merge pull request #2506 from Asheraf/castledb_update
Convert guild castle database to use libconfig
Diffstat (limited to 'src')
-rw-r--r--src/map/guild.c81
-rw-r--r--src/map/guild.h3
-rw-r--r--src/plugins/HPMHooking/HPMHooking.Defs.inc6
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc12
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc3
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.Hooks.inc51
6 files changed, 121 insertions, 35 deletions
diff --git a/src/map/guild.c b/src/map/guild.c
index ae76b22a3..aadb55c78 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -38,6 +38,7 @@
#include "map/storage.h"
#include "common/HPM.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/ers.h"
#include "common/memmgr.h"
#include "common/mapindex.h"
@@ -147,26 +148,76 @@ static int guild_check_skill_require(struct guild *g, int id)
return 1;
}
-static bool guild_read_castledb(char *str[], int columns, int current)
-{// <castle id>,<map name>,<castle name>,<castle event>[,<reserved/unused switch flag>]
- struct guild_castle *gc;
- int index;
+static bool guild_read_castledb_libconfig(void)
+{
+ struct config_t castle_conf;
+ struct config_setting_t *castle_db = NULL, *it = NULL;
+ const char *config_filename = "db/castle_db.conf"; // FIXME hardcoded name
+ int i = 0;
+
+ if (libconfig->load_file(&castle_conf, config_filename) == 0)
+ return false;
- nullpo_retr(false, str);
- index = mapindex->name2id(str[1]);
- if (map->mapindex2mapid(index) < 0) // Map not found or on another map-server
+ if ((castle_db = libconfig->setting_get_member(castle_conf.root, "castle_db")) == NULL) {
+ libconfig->destroy(&castle_conf);
+ ShowError("guild_read_castledb_libconfig: can't read %s\n", config_filename);
return false;
+ }
+
+ while ((it = libconfig->setting_get_elem(castle_db, i++)) != NULL) {
+ guild->read_castledb_libconfig_sub(it, i - 1, config_filename);
+ }
+ libconfig->destroy(&castle_conf);
+ ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", i, config_filename);
+ return true;
+}
+
+static bool guild_read_castledb_libconfig_sub(struct config_setting_t *it, int idx, const char *source)
+{
+ nullpo_ret(it);
+ nullpo_ret(source);
+
+ struct guild_castle *gc = NULL;
+ const char *name = NULL;
+ int i32 = 0;
CREATE(gc, struct guild_castle, 1);
- gc->castle_id = atoi(str[0]);
+
+ if (libconfig->setting_lookup_int(it, "CastleID", &i32) == CONFIG_FALSE) {
+ aFree(gc);
+ ShowWarning("guild_read_castledb_libconfig_sub: Invalid or missing CastleID (%d) in \"%s\", entry #%d, skipping.\n", i32, source, idx);
+ return false;
+ }
+ gc->castle_id = i32;
+
+ if (libconfig->setting_lookup_string(it, "MapName", &name) == CONFIG_FALSE) {
+ aFree(gc);
+ ShowWarning("guild_read_castledb_libconfig_sub: Invalid or missing MapName in \"%s\", entry #%d, skipping.\n", source, idx);
+ return false;
+ }
+ int index = mapindex->name2id(name);
+ if (map->mapindex2mapid(index) < 0) {
+ aFree(gc);
+ ShowWarning("guild_read_castledb_libconfig_sub: Invalid MapName (%s) in \"%s\", entry #%d, skipping.\n", name, source, idx);
+ return false;
+ }
gc->mapindex = index;
- safestrncpy(gc->castle_name, str[2], sizeof(gc->castle_name));
- safestrncpy(gc->castle_event, str[3], sizeof(gc->castle_event));
- idb_put(guild->castle_db,gc->castle_id,gc);
+ if (libconfig->setting_lookup_string(it, "CastleName", &name) == CONFIG_FALSE) {
+ aFree(gc);
+ ShowWarning("guild_read_castledb_libconfig_sub: Invalid CastleName in \"%s\", entry #%d, skipping.\n", source, idx);
+ return false;
+ }
+ safestrncpy(gc->castle_name, name, sizeof(gc->castle_name));
- //intif->guild_castle_info(gc->castle_id);
+ if (libconfig->setting_lookup_string(it, "OnGuildBreakEventName", &name) == CONFIG_FALSE){
+ aFree(gc);
+ ShowWarning("guild_read_castledb_libconfig_sub: Invalid OnGuildBreakEventName in \"%s\", entry #%d, skipping.\n", source, idx);
+ return false;
+ }
+ safestrncpy(gc->castle_event, name, sizeof(gc->castle_event));
+ idb_put(guild->castle_db, gc->castle_id, gc);
return true;
}
@@ -2321,8 +2372,7 @@ static void do_init_guild(bool minimal)
guild->infoevent_db = idb_alloc(DB_OPT_BASE);
guild->expcache_ers = ers_new(sizeof(struct guild_expcache),"guild.c::expcache_ers",ERS_OPT_NONE);
- sv->readdb(map->db_path, "castle_db.txt", ',', 4, 5, -1, guild->read_castledb);
-
+ guild->read_castledb_libconfig();
sv->readdb(map->db_path, "guild_skill_tree.txt", ',', 2+MAX_GUILD_SKILL_REQUIRE*2, 2+MAX_GUILD_SKILL_REQUIRE*2, -1, guild->read_guildskill_tree_db); //guild skill tree [Komurka]
timer->add_func_list(guild->payexp_timer,"guild_payexp_timer");
@@ -2457,7 +2507,8 @@ void guild_defaults(void)
guild->payexp_timer = guild_payexp_timer;
guild->sd_check = guild_sd_check;
guild->read_guildskill_tree_db = guild_read_guildskill_tree_db;
- guild->read_castledb = guild_read_castledb;
+ guild->read_castledb_libconfig = guild_read_castledb_libconfig;
+ guild->read_castledb_libconfig_sub = guild_read_castledb_libconfig_sub;
guild->payexp_timer_sub = guild_payexp_timer_sub;
guild->send_xy_timer_sub = guild_send_xy_timer_sub;
guild->send_xy_timer = guild_send_xy_timer;
diff --git a/src/map/guild.h b/src/map/guild.h
index 396cbda86..40209b988 100644
--- a/src/map/guild.h
+++ b/src/map/guild.h
@@ -165,7 +165,8 @@ struct guild_interface {
int (*payexp_timer) (int tid, int64 tick, int id, intptr_t data);
struct map_session_data *(*sd_check) (int guild_id, int account_id, int char_id);
bool (*read_guildskill_tree_db) (char* split[], int columns, int current);
- bool (*read_castledb) (char* str[], int columns, int current);
+ bool (*read_castledb_libconfig) (void);
+ bool (*read_castledb_libconfig_sub) (struct config_setting_t *it, int idx, const char *source);
int (*payexp_timer_sub) (union DBKey key, struct DBData *data, va_list ap);
int (*send_xy_timer_sub) (union DBKey key, struct DBData *data, va_list ap);
int (*send_xy_timer) (int tid, int64 tick, int id, intptr_t data);
diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc
index 2f3642a18..24958711e 100644
--- a/src/plugins/HPMHooking/HPMHooking.Defs.inc
+++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc
@@ -3054,8 +3054,10 @@ typedef struct map_session_data* (*HPMHOOK_pre_guild_sd_check) (int *guild_id, i
typedef struct map_session_data* (*HPMHOOK_post_guild_sd_check) (struct map_session_data* retVal___, int guild_id, int account_id, int char_id);
typedef bool (*HPMHOOK_pre_guild_read_guildskill_tree_db) (char **split[], int *columns, int *current);
typedef bool (*HPMHOOK_post_guild_read_guildskill_tree_db) (bool retVal___, char *split[], int columns, int current);
-typedef bool (*HPMHOOK_pre_guild_read_castledb) (char **str[], int *columns, int *current);
-typedef bool (*HPMHOOK_post_guild_read_castledb) (bool retVal___, char *str[], int columns, int current);
+typedef bool (*HPMHOOK_pre_guild_read_castledb_libconfig) (void);
+typedef bool (*HPMHOOK_post_guild_read_castledb_libconfig) (bool retVal___);
+typedef bool (*HPMHOOK_pre_guild_read_castledb_libconfig_sub) (struct config_setting_t **it, int *idx, const char **source);
+typedef bool (*HPMHOOK_post_guild_read_castledb_libconfig_sub) (bool retVal___, struct config_setting_t *it, int idx, const char *source);
typedef int (*HPMHOOK_pre_guild_payexp_timer_sub) (union DBKey *key, struct DBData **data, va_list ap);
typedef int (*HPMHOOK_post_guild_payexp_timer_sub) (int retVal___, union DBKey key, struct DBData *data, va_list ap);
typedef int (*HPMHOOK_pre_guild_send_xy_timer_sub) (union DBKey *key, struct DBData **data, va_list ap);
diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
index fa5bb7cc2..ad49bacb4 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
@@ -2618,8 +2618,10 @@ struct {
struct HPMHookPoint *HP_guild_sd_check_post;
struct HPMHookPoint *HP_guild_read_guildskill_tree_db_pre;
struct HPMHookPoint *HP_guild_read_guildskill_tree_db_post;
- struct HPMHookPoint *HP_guild_read_castledb_pre;
- struct HPMHookPoint *HP_guild_read_castledb_post;
+ struct HPMHookPoint *HP_guild_read_castledb_libconfig_pre;
+ struct HPMHookPoint *HP_guild_read_castledb_libconfig_post;
+ struct HPMHookPoint *HP_guild_read_castledb_libconfig_sub_pre;
+ struct HPMHookPoint *HP_guild_read_castledb_libconfig_sub_post;
struct HPMHookPoint *HP_guild_payexp_timer_sub_pre;
struct HPMHookPoint *HP_guild_payexp_timer_sub_post;
struct HPMHookPoint *HP_guild_send_xy_timer_sub_pre;
@@ -9411,8 +9413,10 @@ struct {
int HP_guild_sd_check_post;
int HP_guild_read_guildskill_tree_db_pre;
int HP_guild_read_guildskill_tree_db_post;
- int HP_guild_read_castledb_pre;
- int HP_guild_read_castledb_post;
+ int HP_guild_read_castledb_libconfig_pre;
+ int HP_guild_read_castledb_libconfig_post;
+ int HP_guild_read_castledb_libconfig_sub_pre;
+ int HP_guild_read_castledb_libconfig_sub_post;
int HP_guild_payexp_timer_sub_pre;
int HP_guild_payexp_timer_sub_post;
int HP_guild_send_xy_timer_sub_pre;
diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
index 07bbbb4d8..474bcfb14 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
@@ -1342,7 +1342,8 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(guild->payexp_timer, HP_guild_payexp_timer) },
{ HP_POP(guild->sd_check, HP_guild_sd_check) },
{ HP_POP(guild->read_guildskill_tree_db, HP_guild_read_guildskill_tree_db) },
- { HP_POP(guild->read_castledb, HP_guild_read_castledb) },
+ { HP_POP(guild->read_castledb_libconfig, HP_guild_read_castledb_libconfig) },
+ { HP_POP(guild->read_castledb_libconfig_sub, HP_guild_read_castledb_libconfig_sub) },
{ HP_POP(guild->payexp_timer_sub, HP_guild_payexp_timer_sub) },
{ HP_POP(guild->send_xy_timer_sub, HP_guild_send_xy_timer_sub) },
{ HP_POP(guild->send_xy_timer, HP_guild_send_xy_timer) },
diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
index 30bc8b8ca..8817c34cc 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
@@ -34251,15 +34251,15 @@ bool HP_guild_read_guildskill_tree_db(char *split[], int columns, int current) {
}
return retVal___;
}
-bool HP_guild_read_castledb(char *str[], int columns, int current) {
+bool HP_guild_read_castledb_libconfig(void) {
int hIndex = 0;
bool retVal___ = false;
- if (HPMHooks.count.HP_guild_read_castledb_pre > 0) {
- bool (*preHookFunc) (char **str[], int *columns, int *current);
+ if (HPMHooks.count.HP_guild_read_castledb_libconfig_pre > 0) {
+ bool (*preHookFunc) (void);
*HPMforce_return = false;
- for (hIndex = 0; hIndex < HPMHooks.count.HP_guild_read_castledb_pre; hIndex++) {
- preHookFunc = HPMHooks.list.HP_guild_read_castledb_pre[hIndex].func;
- retVal___ = preHookFunc(&str, &columns, &current);
+ for (hIndex = 0; hIndex < HPMHooks.count.HP_guild_read_castledb_libconfig_pre; hIndex++) {
+ preHookFunc = HPMHooks.list.HP_guild_read_castledb_libconfig_pre[hIndex].func;
+ retVal___ = preHookFunc();
}
if (*HPMforce_return) {
*HPMforce_return = false;
@@ -34267,13 +34267,40 @@ bool HP_guild_read_castledb(char *str[], int columns, int current) {
}
}
{
- retVal___ = HPMHooks.source.guild.read_castledb(str, columns, current);
+ retVal___ = HPMHooks.source.guild.read_castledb_libconfig();
}
- if (HPMHooks.count.HP_guild_read_castledb_post > 0) {
- bool (*postHookFunc) (bool retVal___, char *str[], int columns, int current);
- for (hIndex = 0; hIndex < HPMHooks.count.HP_guild_read_castledb_post; hIndex++) {
- postHookFunc = HPMHooks.list.HP_guild_read_castledb_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, str, columns, current);
+ if (HPMHooks.count.HP_guild_read_castledb_libconfig_post > 0) {
+ bool (*postHookFunc) (bool retVal___);
+ for (hIndex = 0; hIndex < HPMHooks.count.HP_guild_read_castledb_libconfig_post; hIndex++) {
+ postHookFunc = HPMHooks.list.HP_guild_read_castledb_libconfig_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___);
+ }
+ }
+ return retVal___;
+}
+bool HP_guild_read_castledb_libconfig_sub(struct config_setting_t *it, int idx, const char *source) {
+ int hIndex = 0;
+ bool retVal___ = false;
+ if (HPMHooks.count.HP_guild_read_castledb_libconfig_sub_pre > 0) {
+ bool (*preHookFunc) (struct config_setting_t **it, int *idx, const char **source);
+ *HPMforce_return = false;
+ for (hIndex = 0; hIndex < HPMHooks.count.HP_guild_read_castledb_libconfig_sub_pre; hIndex++) {
+ preHookFunc = HPMHooks.list.HP_guild_read_castledb_libconfig_sub_pre[hIndex].func;
+ retVal___ = preHookFunc(&it, &idx, &source);
+ }
+ if (*HPMforce_return) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.guild.read_castledb_libconfig_sub(it, idx, source);
+ }
+ if (HPMHooks.count.HP_guild_read_castledb_libconfig_sub_post > 0) {
+ bool (*postHookFunc) (bool retVal___, struct config_setting_t *it, int idx, const char *source);
+ for (hIndex = 0; hIndex < HPMHooks.count.HP_guild_read_castledb_libconfig_sub_post; hIndex++) {
+ postHookFunc = HPMHooks.list.HP_guild_read_castledb_libconfig_sub_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, it, idx, source);
}
}
return retVal___;