diff --git a/src/io/ioguild.cpp b/src/io/ioguild.cpp index 4c58e23..8a22497 100644 --- a/src/io/ioguild.cpp +++ b/src/io/ioguild.cpp @@ -65,6 +65,61 @@ uint32_t IOGuild::getGuildIdByName(const std::string &name) { return result->getNumber("id"); } +std::string IOGuild::getGuildNameById(uint32_t id) { + Database &db = Database::getInstance(); + + std::ostringstream query; + query << "SELECT `name` FROM `guilds` WHERE `id` = " << id; + + DBResult_ptr result = db.storeQuery(query.str()); + if (!result) { + return ""; + } + + return result->getString("name"); +} + +uint32_t IOGuild::getRankIdByGuildIdAndLevel(uint32_t guildId, uint32_t guildLevel) { + Database &db = Database::getInstance(); + + std::ostringstream query; + query << "SELECT `id` FROM `guild_ranks` WHERE `level` = " << guildLevel + << " AND `guild_id` = " << guildId << " LIMIT 1;"; + + DBResult_ptr result = db.storeQuery(query.str()); + if (!result) { + return 0; + } + + return result->getNumber("id"); +} + +std::string IOGuild::getRankName(int16_t guildLevel, uint32_t guildId) { + Database &db = Database::getInstance(); + + std::ostringstream query; + query << "SELECT `name` FROM `guild_ranks` WHERE `guild_id` = " << guildId + << " AND `level` = " << guildLevel << " LIMIT 1;"; + + DBResult_ptr result = db.storeQuery(query.str()); + if (!result) { + return ""; + } + + return result->getString("name"); +} + +bool IOGuild::rankNameExists(const std::string& rankName, uint32_t guildId) { + Database &db = Database::getInstance(); + + std::ostringstream query; + query << "SELECT `name` FROM `guild_ranks` WHERE `guild_id` = " << guildId + << " AND `name` = " << "'" << db.escapeString(rankName) << "'" << " LIMIT 1;"; + + DBResult_ptr result = db.storeQuery(query.str()); + return result != nullptr; +} + void IOGuild::getWarList(uint32_t guildId, GuildWarVector &guildWarVector) { std::ostringstream query; query << "SELECT `guild1`, `guild2` FROM `guild_wars` WHERE (`guild1` = " << guildId << " OR `guild2` = " << guildId << ") AND `status` = 1"; @@ -83,3 +138,14 @@ void IOGuild::getWarList(uint32_t guildId, GuildWarVector &guildWarVector) { } } while (result->next()); } + +bool IOGuild::guildExists(uint32_t guildId) { + Database &db = Database::getInstance(); + std::ostringstream query; + query << "SELECT `id` FROM `guilds` WHERE `id` = " << guildId << " LIMIT 1;"; + if (DBResult_ptr result = db.storeQuery(query.str())) { + return true; + } + + return false; +} diff --git a/src/io/ioguild.hpp b/src/io/ioguild.hpp index 20a3eed..b1d2578 100644 --- a/src/io/ioguild.hpp +++ b/src/io/ioguild.hpp @@ -25,5 +25,10 @@ class IOGuild { static std::shared_ptr loadGuild(uint32_t guildId); static void saveGuild(const std::shared_ptr &guild); static uint32_t getGuildIdByName(const std::string &name); + static std::string getGuildNameById(uint32_t id); + static uint32_t getRankIdByGuildIdAndLevel(uint32_t guildId, uint32_t guildLevel); + static std::string getRankName(int16_t guildLevel, uint32_t guildId); + static bool rankNameExists(const std::string& rankName, uint32_t guildId); static void getWarList(uint32_t guildId, GuildWarVector &guildWarVector); + static bool guildExists(uint32_t guildId); };