Skip to content

Commit

Permalink
More functions to guilds
Browse files Browse the repository at this point in the history
  • Loading branch information
jprzimba committed Jan 6, 2025
1 parent e6a0c1a commit 147a410
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/io/ioguild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,61 @@ uint32_t IOGuild::getGuildIdByName(const std::string &name) {
return result->getNumber<uint32_t>("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<uint32_t>("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";
Expand All @@ -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;
}
5 changes: 5 additions & 0 deletions src/io/ioguild.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@ class IOGuild {
static std::shared_ptr<Guild> loadGuild(uint32_t guildId);
static void saveGuild(const std::shared_ptr<Guild> &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);
};

0 comments on commit 147a410

Please sign in to comment.