From e657ef0ee76b5f4f15ee041f6863aee58a24cc35 Mon Sep 17 00:00:00 2001 From: Asheraf Date: Fri, 19 Jul 2019 11:52:56 +0100 Subject: Convert guild castle database to use libconfig --- db/castle_db.conf | 269 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ db/castle_db.txt | 74 --------------- src/map/guild.c | 81 +++++++++++++--- src/map/guild.h | 3 +- 4 files changed, 337 insertions(+), 90 deletions(-) create mode 100644 db/castle_db.conf delete mode 100644 db/castle_db.txt diff --git a/db/castle_db.conf b/db/castle_db.conf new file mode 100644 index 000000000..907754954 --- /dev/null +++ b/db/castle_db.conf @@ -0,0 +1,269 @@ +//================= Hercules Database ===================================== +//= _ _ _ +//= | | | | | | +//= | |_| | ___ _ __ ___ _ _| | ___ ___ +//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __| +//= | | | | __/ | | (__| |_| | | __/\__ \ +//= \_| |_/\___|_| \___|\__,_|_|\___||___/ +//================= License =============================================== +//= This file is part of Hercules. +//= http://herc.ws - http://github.com/HerculesWS/Hercules +//= +//= Copyright (C) 2019 Hercules Dev Team +//= Copyright (C) 2019 Asheraf +//= +//= Hercules is free software: you can redistribute it and/or modify +//= it under the terms of the GNU General Public License as published by +//= the Free Software Foundation, either version 3 of the License, or +//= (at your option) any later version. +//= +//= This program is distributed in the hope that it will be useful, +//= but WITHOUT ANY WARRANTY; without even the implied warranty of +//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//= GNU General Public License for more details. +//= +//= You should have received a copy of the GNU General Public License +//= along with this program. If not, see . +//========================================================================= +//= Castle Database +//========================================================================= + +castle_db: ( +/************************************************************************** + ************* Entry structure ******************************************** + ************************************************************************** +{ + // ================ Mandatory fields ============================== + CastleID: (int) Unique ID of the castle. Must remain unique across all map-servers. + MapName: (string) Map name to be considered as the castle map. + CastleName: (string) Name of the castle (used by scripts and guardian name tags) + OnGuildBreakEventName: (string) NPC unique name to invoke ::OnGuildBreak on, when a occupied + castle is abandoned during guild break. +}, +**************************************************************************/ +//================ +// Al De Baran +//================ +{ + CastleID: 0 + MapName: "aldeg_cas01" + CastleName: "Neuschwanstein" // kRO : Noisyubantian + OnGuildBreakEventName: "Agit#aldeg_cas01" +}, +{ + CastleID: 1 + MapName: "aldeg_cas02" + CastleName: "Hohenschwangau" // kRO : Hohensyubangawoo + OnGuildBreakEventName: "Agit#aldeg_cas02" +}, +{ + CastleID: 2 + MapName: "aldeg_cas03" + CastleName: "Nuernberg" // kRO : Nyirenverk + OnGuildBreakEventName: "Agit#aldeg_cas03" +}, +{ + CastleID: 3 + MapName: "aldeg_cas04" + CastleName: "Wuerzburg" // kRO : Byirtsburi + OnGuildBreakEventName: "Agit#aldeg_cas04" +}, +{ + CastleID: 4 + MapName: "aldeg_cas05" + CastleName: "Rothenburg" // kRO : Rotenburk + OnGuildBreakEventName: "Agit#aldeg_cas05" +}, +//================ +// Geffen +//================ +{ + CastleID: 5 + MapName: "gefg_cas01" + CastleName: "Repherion" // kRO : Reprion + OnGuildBreakEventName: "Agit#gefg_cas01" +}, +{ + CastleID: 6 + MapName: "gefg_cas02" + CastleName: "Eeyolbriggar" // kRO : Yolbriger + OnGuildBreakEventName: "Agit#gefg_cas02" +}, +{ + CastleID: 7 + MapName: "gefg_cas03" + CastleName: "Yesnelph" // kRO : Isinlife + OnGuildBreakEventName: "Agit#gefg_cas03" +}, +{ + CastleID: 8 + MapName: "gefg_cas04" + CastleName: "Bergel" // kRO : Berigel + OnGuildBreakEventName: "Agit#gefg_cas04" +}, +{ + CastleID: 9 + MapName: "gefg_cas05" + CastleName: "Mersetzdeitz" // kRO : Melsedetsu + OnGuildBreakEventName: "Agit#gefg_cas05" +}, +//================ +// Payon +//================ +{ + CastleID: 10 + MapName: "payg_cas01" + CastleName: "Bright Arbor" // kRO : Mingting + OnGuildBreakEventName: "Agit#payg_cas01" +}, +{ + CastleID: 11 + MapName: "payg_cas02" + CastleName: "Scarlet Palace" // kRO : Tiantan + OnGuildBreakEventName: "Agit#payg_cas02" +}, +{ + CastleID: 12 + MapName: "payg_cas03" + CastleName: "Holy Shadow" // kRO : Fuying + OnGuildBreakEventName: "Agit#payg_cas03" +}, +{ + CastleID: 13 + MapName: "payg_cas04" + CastleName: "Sacred Altar" // kRO : Honglou + OnGuildBreakEventName: "Agit#payg_cas04" +}, +{ + CastleID: 14 + MapName: "payg_cas05" + CastleName: "Bamboo Grove Hill" // kRO : Zhulinxian + OnGuildBreakEventName: "Agit#payg_cas05" +}, +//================ +// Prontera +//================ +{ + CastleID: 15 + MapName: "prtg_cas01" + CastleName: "Kriemhild" // kRO : Creamhilt + OnGuildBreakEventName: "Agit#prtg_cas01" +}, +{ + CastleID: 16 + MapName: "prtg_cas02" + CastleName: "Swanhild" // kRO : Sbanhealt + OnGuildBreakEventName: "Agit#prtg_cas02" +}, +{ + CastleID: 17 + MapName: "prtg_cas03" + CastleName: "Fadhgridh" // kRO : Lazrigees + OnGuildBreakEventName: "Agit#prtg_cas03" +}, +{ + CastleID: 18 + MapName: "prtg_cas04" + CastleName: "Skoegul" // kRO : Squagul + OnGuildBreakEventName: "Agit#prtg_cas04" +}, +{ + CastleID: 19 + MapName: "prtg_cas05" + CastleName: "Gondul" // kRO : Guindull + OnGuildBreakEventName: "Agit#prtg_cas05" +}, +//================ +// Novice Guilds +//================ +{ + CastleID: 20 + MapName: "nguild_alde" + CastleName: "Earth" + OnGuildBreakEventName: "Agit_N01" +}, +{ + CastleID: 21 + MapName: "nguild_gef" + CastleName: "Air" + OnGuildBreakEventName: "Agit_N02" +}, +{ + CastleID: 22 + MapName: "nguild_pay" + CastleName: "Water" + OnGuildBreakEventName: "Agit_N03" +}, +{ + CastleID: 23 + MapName: "nguild_prt" + CastleName: "Fire" + OnGuildBreakEventName: "Agit_N04" +}, +//================ +// Yuno +//================ +{ + CastleID: 24 + MapName: "schg_cas01" + CastleName: "Himinn" // kRO : Himinn + OnGuildBreakEventName: "Manager#schg_cas01" +}, +{ + CastleID: 25 + MapName: "schg_cas02" + CastleName: "Andlangr" // kRO : Andlangr + OnGuildBreakEventName: "Manager#schg_cas02" +}, +{ + CastleID: 26 + MapName: "schg_cas03" + CastleName: "Viblainn" // kRO : Viblainn + OnGuildBreakEventName: "Manager#schg_cas03" +}, +{ + CastleID: 27 + MapName: "schg_cas04" + CastleName: "Hljod" // kRO : Hljod + OnGuildBreakEventName: "Manager#schg_cas04" +}, +{ + CastleID: 28 + MapName: "schg_cas05" + CastleName: "Skidbladnir" // kRO : Skidbladnir + OnGuildBreakEventName: "Manager#schg_cas05" +}, +//================ +// Rachel +//================ +{ + CastleID: 29 + MapName: "arug_cas01" + CastleName: "Mardol" // kRO : Mardol + OnGuildBreakEventName: "Manager#arug_cas01" +}, +{ + CastleID: 30 + MapName: "arug_cas02" + CastleName: "Cyr" // kRO : Cyr + OnGuildBreakEventName: "Manager#arug_cas02" +}, +{ + CastleID: 31 + MapName: "arug_cas03" + CastleName: "Horn" // kRO : Horn + OnGuildBreakEventName: "Manager#arug_cas03" +}, +{ + CastleID: 32 + MapName: "arug_cas04" + CastleName: "Gefn" // kRO : Gefn + OnGuildBreakEventName: "Manager#arug_cas04" +}, +{ + CastleID: 33 + MapName: "arug_cas05" + CastleName: "Bandis" // kRO : Bandis + OnGuildBreakEventName: "Manager#arug_cas05" +}, +) diff --git a/db/castle_db.txt b/db/castle_db.txt deleted file mode 100644 index 12e222eb6..000000000 --- a/db/castle_db.txt +++ /dev/null @@ -1,74 +0,0 @@ -// Guild Castles Database -// -// Structure of Database: -// CastleID,MapName,CastleName,OnGuildBreakEventName,Flag -// -// 01. CastleID Unique ID of the castle. Must remain unique across all map-servers. -// 02. MapName Map name to be considered as the castle map. -// 03. CastleName Name of the castle (used by scripts and guardian name tags). -// 04. OnGuildBreakEventName NPC unique name to invoke ::OnGuildBreak on, when a occupied -// castle is abandoned during guild break. -// 05. Flag Switch flag (reserved as of athena-dev mod0796~0801, not used by server). - - -//================ -// Al De Baran -//================ -0,aldeg_cas01,Neuschwanstein,Agit#aldeg_cas01,1 // kRO : Noisyubantian -1,aldeg_cas02,Hohenschwangau,Agit#aldeg_cas02,1 // kRO : Hohensyubangawoo -2,aldeg_cas03,Nuernberg,Agit#aldeg_cas03,1 // kRO : Nyirenverk -3,aldeg_cas04,Wuerzburg,Agit#aldeg_cas04,1 // kRO : Byirtsburi -4,aldeg_cas05,Rothenburg,Agit#aldeg_cas05,1 // kRO : Rotenburk - -//================ -// Geffen -//================ -5,gefg_cas01,Repherion,Agit#gefg_cas01,1 // kRO : Reprion -6,gefg_cas02,Eeyolbriggar,Agit#gefg_cas02,1 // kRO : Yolbriger -7,gefg_cas03,Yesnelph,Agit#gefg_cas03,1 // kRO : Isinlife -8,gefg_cas04,Bergel,Agit#gefg_cas04,1 // kRO : Berigel -9,gefg_cas05,Mersetzdeitz,Agit#gefg_cas05,1 // kRO : Melsedetsu - -//================ -// Payon -//================ -10,payg_cas01,Bright Arbor,Agit#payg_cas01,1 // kRO : Mingting -11,payg_cas02,Scarlet Palace,Agit#payg_cas02,1 // kRO : Tiantan -12,payg_cas03,Holy Shadow,Agit#payg_cas03,1 // kRO : Fuying -13,payg_cas04,Sacred Altar,Agit#payg_cas04,1 // kRO : Honglou -14,payg_cas05,Bamboo Grove Hill,Agit#payg_cas05,1 // kRO : Zhulinxian - -//================ -// Prontera -//================ -15,prtg_cas01,Kriemhild,Agit#prtg_cas01,1 // kRO : Creamhilt -16,prtg_cas02,Swanhild,Agit#prtg_cas02,1 // kRO : Sbanhealt -17,prtg_cas03,Fadhgridh,Agit#prtg_cas03,1 // kRO : Lazrigees -18,prtg_cas04,Skoegul,Agit#prtg_cas04,1 // kRO : Squagul -19,prtg_cas05,Gondul,Agit#prtg_cas05,1 // kRO : Guindull - -//================ -// Novice Guilds -//================ -20,nguild_alde,Earth,Agit_N01,2 -21,nguild_gef,Air,Agit_N02,2 -22,nguild_pay,Water,Agit_N03,2 -23,nguild_prt,Fire,Agit_N04,2 - -//================ -// Yuno -//================ -24,schg_cas01,Himinn,Manager#schg_cas01,1 // kRO : Himinn -25,schg_cas02,Andlangr,Manager#schg_cas02,1 // kRO : Andlangr -26,schg_cas03,Viblainn,Manager#schg_cas03,1 // kRO : Viblainn -27,schg_cas04,Hljod,Manager#schg_cas04,1 // kRO : Hljod -28,schg_cas05,Skidbladnir,Manager#schg_cas05,1 // kRO : Skidbladnir - -//================ -// Rachel -//================ -29,arug_cas01,Mardol,Manager#arug_cas01,1 // kRO : Mardol -30,arug_cas02,Cyr,Manager#arug_cas02,1 // kRO : Cyr -31,arug_cas03,Horn,Manager#arug_cas03,1 // kRO : Horn -32,arug_cas04,Gefn,Manager#arug_cas04,1 // kRO : Gefn -33,arug_cas05,Bandis,Manager#arug_cas05,1 // kRO : Bandis 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) -{// ,,,[,] - 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); -- cgit v1.2.3-60-g2f50