diff --git a/src/creatures/players/cyclopedia/player_badge.cpp b/src/creatures/players/cyclopedia/player_badge.cpp index c19e2443db1..b509ef041e3 100644 --- a/src/creatures/players/cyclopedia/player_badge.cpp +++ b/src/creatures/players/cyclopedia/player_badge.cpp @@ -13,6 +13,8 @@ #include "game/game.hpp" #include "kv/kv.hpp" +#include "enums/account_errors.hpp" + PlayerBadge::PlayerBadge(Player &player) : m_player(player) { } @@ -113,8 +115,38 @@ bool PlayerBadge::loyalty(uint8_t amount) { return m_player.getLoyaltyPoints() >= amount; } +std::vector> PlayerBadge::getPlayersInfoByAccount(std::shared_ptr acc) const { + auto [accountPlayers, error] = acc->getAccountPlayers(); + if (error != enumToValue(AccountErrors_t::Ok) || accountPlayers.empty()) { + return {}; + } + + std::string namesList; + for (const auto &[name, _] : accountPlayers) { + if (!namesList.empty()) { + namesList += ", "; + } + namesList += fmt::format("'{}'", name); + } + + auto query = fmt::format("SELECT name, level, vocation FROM players WHERE name IN ({})", namesList); + std::vector> players; + DBResult_ptr result = g_database().storeQuery(query); + if (result) { + do { + auto player = std::make_shared(nullptr); + player->setName(result->getString("name")); + player->setLevel(result->getNumber("level")); + player->setVocation(result->getNumber("vocation")); + players.push_back(player); + } while (result->next()); + } + + return players; +} + bool PlayerBadge::accountAllLevel(uint8_t amount) { - auto players = g_game().getPlayersByAccount(m_player.getAccount(), true); + auto players = getPlayersInfoByAccount(m_player.getAccount()); uint16_t total = std::accumulate(players.begin(), players.end(), 0, [](uint16_t sum, const std::shared_ptr &player) { return sum + player->getLevel(); }); @@ -126,7 +158,7 @@ bool PlayerBadge::accountAllVocations(uint8_t amount) { auto paladin = false; auto druid = false; auto sorcerer = false; - for (const auto &player : g_game().getPlayersByAccount(m_player.getAccount(), true)) { + for (const auto &player : getPlayersInfoByAccount(m_player.getAccount())) { if (player->getLevel() >= amount) { auto vocationEnum = player->getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { diff --git a/src/creatures/players/cyclopedia/player_badge.hpp b/src/creatures/players/cyclopedia/player_badge.hpp index 7bf28c0c302..25eaea0666f 100644 --- a/src/creatures/players/cyclopedia/player_badge.hpp +++ b/src/creatures/players/cyclopedia/player_badge.hpp @@ -13,6 +13,7 @@ class Player; class KV; +class Account; struct Badge { uint8_t m_id = 0; @@ -52,6 +53,7 @@ class PlayerBadge { // Badge Calculate Functions bool accountAge(uint8_t amount); bool loyalty(uint8_t amount); + std::vector> getPlayersInfoByAccount(std::shared_ptr acc) const; bool accountAllLevel(uint8_t amount); bool accountAllVocations(uint8_t amount); [[nodiscard]] bool tournamentParticipation(uint8_t skill); diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index ff844c97b3b..cd69cec99a0 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -606,6 +606,9 @@ class Player final : public Creature, public Cylinder, public Bankable { uint32_t getLevel() const { return level; } + void setLevel(uint32_t newLevel) { + level = newLevel; + } uint8_t getLevelPercent() const { return levelPercent; } diff --git a/src/database/database.cpp b/src/database/database.cpp index 9ac892ef2be..4f038605e05 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -42,6 +42,10 @@ bool Database::connect(const std::string* host, const std::string* user, const s bool reconnect = true; mysql_options(handle, MYSQL_OPT_RECONNECT, &reconnect); + // Remove ssl verification + bool ssl_enabled = false; + mysql_options(handle, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &ssl_enabled); + // connects to database if (!mysql_real_connect(handle, host->c_str(), user->c_str(), password->c_str(), database->c_str(), port, sock->c_str(), 0)) { g_logger().error("MySQL Error Message: {}", mysql_error(handle));