diff options
-rw-r--r-- | src/server/game/Achievements/CriteriaHandler.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Entities/Player/Player.cpp | 4 | ||||
-rw-r--r-- | src/server/game/Server/WorldSocket.cpp | 2 | ||||
-rw-r--r-- | src/server/shared/Realm/ClientBuildInfo.cpp | 77 | ||||
-rw-r--r-- | src/server/shared/Realm/ClientBuildInfo.h | 4 | ||||
-rw-r--r-- | src/server/shared/Realm/RealmList.cpp | 67 | ||||
-rw-r--r-- | src/server/shared/Realm/RealmList.h | 4 |
7 files changed, 85 insertions, 75 deletions
diff --git a/src/server/game/Achievements/CriteriaHandler.cpp b/src/server/game/Achievements/CriteriaHandler.cpp index 97d43ac2140..72b1c2419d3 100644 --- a/src/server/game/Achievements/CriteriaHandler.cpp +++ b/src/server/game/Achievements/CriteriaHandler.cpp @@ -1884,7 +1884,7 @@ bool CriteriaHandler::ModifierSatisfied(ModifierTreeEntry const* modifier, uint6 std::shared_ptr<Realm const> currentRealm = sRealmList->GetCurrentRealm(); if (!currentRealm) return false; - if (reqValue < sRealmList->GetMinorMajorBugfixVersionForBuild(currentRealm->Build)) + if (reqValue < ClientBuild::GetMinorMajorBugfixVersionForBuild(currentRealm->Build)) return false; break; } diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index b6b7ea4b836..072f53f7d97 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -19077,7 +19077,7 @@ void Player::SaveToDB(LoginDatabaseTransaction loginTransaction, CharacterDataba stmt->setUInt8(index++, m_activePlayerData->MultiActionBars); if (std::shared_ptr<Realm const> currentRealm = sRealmList->GetCurrentRealm()) - stmt->setUInt32(index++, sRealmList->GetMinorMajorBugfixVersionForBuild(currentRealm->Build)); + stmt->setUInt32(index++, ClientBuild::GetMinorMajorBugfixVersionForBuild(currentRealm->Build)); else stmt->setUInt32(index++, 0); } @@ -19223,7 +19223,7 @@ void Player::SaveToDB(LoginDatabaseTransaction loginTransaction, CharacterDataba stmt->setUInt8(index++, m_activePlayerData->RestInfo[REST_TYPE_HONOR].StateID); stmt->setFloat(index++, finiteAlways(_restMgr->GetRestBonus(REST_TYPE_HONOR))); if (std::shared_ptr<Realm const> currentRealm = sRealmList->GetCurrentRealm()) - stmt->setUInt32(index++, sRealmList->GetMinorMajorBugfixVersionForBuild(currentRealm->Build)); + stmt->setUInt32(index++, ClientBuild::GetMinorMajorBugfixVersionForBuild(currentRealm->Build)); else stmt->setUInt32(index++, 0); diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index 1fde981ad53..2bdde59e956 100644 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -706,7 +706,7 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<WorldPackets::Auth:: AccountInfo account(result->Fetch()); - ClientBuild::Info const* buildInfo = sRealmList->GetBuildInfo(account.Game.Build); + ClientBuild::Info const* buildInfo = ClientBuild::GetBuildInfo(account.Game.Build); if (!buildInfo) { SendAuthResponseError(ERROR_BAD_VERSION); diff --git a/src/server/shared/Realm/ClientBuildInfo.cpp b/src/server/shared/Realm/ClientBuildInfo.cpp index 55b1e0d0b25..c2ab1632282 100644 --- a/src/server/shared/Realm/ClientBuildInfo.cpp +++ b/src/server/shared/Realm/ClientBuildInfo.cpp @@ -16,10 +16,19 @@ */ #include "ClientBuildInfo.h" +#include "DatabaseEnv.h" +#include "Util.h" #include <algorithm> #include <cctype> -std::array<char, 5> ClientBuild::ToCharArray(uint32 value) +namespace +{ +std::vector<ClientBuild::Info> Builds; +} + +namespace ClientBuild +{ +std::array<char, 5> ToCharArray(uint32 value) { auto normalize = [](uint8 c) -> char { @@ -43,7 +52,7 @@ std::array<char, 5> ClientBuild::ToCharArray(uint32 value) return chars; } -bool ClientBuild::Platform::IsValid(std::string_view platform) +bool Platform::IsValid(std::string_view platform) { if (platform.length() > sizeof(uint32)) return false; @@ -70,3 +79,67 @@ bool ClientBuild::Platform::IsValid(std::string_view platform) return false; } + +void LoadBuildInfo() +{ + Builds.clear(); + + // 0 1 2 3 4 5 6 + if (QueryResult result = LoginDatabase.Query("SELECT majorVersion, minorVersion, bugfixVersion, hotfixVersion, build, win64AuthSeed, mac64AuthSeed, macArmAuthSeed FROM build_info ORDER BY build ASC")) + { + do + { + using namespace ClientBuild; + + Field* fields = result->Fetch(); + Info& build = Builds.emplace_back(); + build.MajorVersion = fields[0].GetUInt32(); + build.MinorVersion = fields[1].GetUInt32(); + build.BugfixVersion = fields[2].GetUInt32(); + std::string hotfixVersion = fields[3].GetString(); + if (hotfixVersion.length() < build.HotfixVersion.size()) + std::ranges::copy(hotfixVersion, build.HotfixVersion.begin()); + else + build.HotfixVersion = { }; + + build.Build = fields[4].GetUInt32(); + std::string win64AuthSeedHexStr = fields[5].GetString(); + if (win64AuthSeedHexStr.length() == AuthKey::Size * 2) + { + AuthKey& buildKey = build.AuthKeys.emplace_back(); + buildKey.Variant = { .Platform = PlatformType::Windows, .Arch = Arch::x64, .Type = Type::Retail }; + HexStrToByteArray(win64AuthSeedHexStr, buildKey.Key); + } + + std::string mac64AuthSeedHexStr = fields[6].GetString(); + if (mac64AuthSeedHexStr.length() == AuthKey::Size * 2) + { + AuthKey& buildKey = build.AuthKeys.emplace_back(); + buildKey.Variant = { .Platform = PlatformType::macOS, .Arch = Arch::x64, .Type = Type::Retail }; + HexStrToByteArray(mac64AuthSeedHexStr, buildKey.Key); + } + + std::string macArmAuthSeedHexStr = fields[7].GetString(); + if (macArmAuthSeedHexStr.length() == AuthKey::Size * 2) + { + AuthKey& buildKey = build.AuthKeys.emplace_back(); + buildKey.Variant = { .Platform = PlatformType::macOS, .Arch = Arch::Arm64, .Type = Type::Retail }; + HexStrToByteArray(macArmAuthSeedHexStr, buildKey.Key); + } + + } while (result->NextRow()); + } +} + +Info const* GetBuildInfo(uint32 build) +{ + auto buildInfo = std::ranges::find(Builds, build, &Info::Build); + return buildInfo != Builds.end() ? &*buildInfo : nullptr; +} + +uint32 GetMinorMajorBugfixVersionForBuild(uint32 build) +{ + auto buildInfo = std::ranges::lower_bound(Builds, build, {}, &Info::Build); + return buildInfo != Builds.end() ? (buildInfo->MajorVersion * 10000 + buildInfo->MinorVersion * 100 + buildInfo->BugfixVersion) : 0; +} +} diff --git a/src/server/shared/Realm/ClientBuildInfo.h b/src/server/shared/Realm/ClientBuildInfo.h index e52b585b5b0..9d99c28b744 100644 --- a/src/server/shared/Realm/ClientBuildInfo.h +++ b/src/server/shared/Realm/ClientBuildInfo.h @@ -105,6 +105,10 @@ struct Info std::array<char, 4> HotfixVersion; std::vector<AuthKey> AuthKeys; }; + +TC_SHARED_API void LoadBuildInfo(); +TC_SHARED_API Info const* GetBuildInfo(uint32 build); +TC_SHARED_API uint32 GetMinorMajorBugfixVersionForBuild(uint32 build); } #endif // TRINITYCORE_CLIENT_BUILD_INFO_H diff --git a/src/server/shared/Realm/RealmList.cpp b/src/server/shared/Realm/RealmList.cpp index 095640f949b..fcee58c47d0 100644 --- a/src/server/shared/Realm/RealmList.cpp +++ b/src/server/shared/Realm/RealmList.cpp @@ -69,7 +69,7 @@ void RealmList::Initialize(Trinity::Asio::IoContext& ioContext, uint32 updateInt _updateTimer = std::make_unique<Trinity::Asio::DeadlineTimer>(ioContext); _resolver = std::make_unique<Trinity::Asio::Resolver>(ioContext); - LoadBuildInfo(); + ClientBuild::LoadBuildInfo(); // Get the content of the realmlist table in the database UpdateRealms(); } @@ -79,57 +79,6 @@ void RealmList::Close() _updateTimer->cancel(); } -void RealmList::LoadBuildInfo() -{ - _builds.clear(); - - // 0 1 2 3 4 5 6 - if (QueryResult result = LoginDatabase.Query("SELECT majorVersion, minorVersion, bugfixVersion, hotfixVersion, build, win64AuthSeed, mac64AuthSeed, macArmAuthSeed FROM build_info ORDER BY build ASC")) - { - do - { - using namespace ClientBuild; - - Field* fields = result->Fetch(); - Info& build = _builds.emplace_back(); - build.MajorVersion = fields[0].GetUInt32(); - build.MinorVersion = fields[1].GetUInt32(); - build.BugfixVersion = fields[2].GetUInt32(); - std::string hotfixVersion = fields[3].GetString(); - if (hotfixVersion.length() < build.HotfixVersion.size()) - std::ranges::copy(hotfixVersion, build.HotfixVersion.begin()); - else - build.HotfixVersion = { }; - - build.Build = fields[4].GetUInt32(); - std::string win64AuthSeedHexStr = fields[5].GetString(); - if (win64AuthSeedHexStr.length() == AuthKey::Size * 2) - { - AuthKey& buildKey = build.AuthKeys.emplace_back(); - buildKey.Variant = { .Platform = PlatformType::Windows, .Arch = Arch::x64, .Type = Type::Retail }; - HexStrToByteArray(win64AuthSeedHexStr, buildKey.Key); - } - - std::string mac64AuthSeedHexStr = fields[6].GetString(); - if (mac64AuthSeedHexStr.length() == AuthKey::Size * 2) - { - AuthKey& buildKey = build.AuthKeys.emplace_back(); - buildKey.Variant = { .Platform = PlatformType::macOS, .Arch = Arch::x64, .Type = Type::Retail }; - HexStrToByteArray(mac64AuthSeedHexStr, buildKey.Key); - } - - std::string macArmAuthSeedHexStr = fields[7].GetString(); - if (macArmAuthSeedHexStr.length() == AuthKey::Size * 2) - { - AuthKey& buildKey = build.AuthKeys.emplace_back(); - buildKey.Variant = { .Platform = PlatformType::macOS, .Arch = Arch::Arm64, .Type = Type::Retail }; - HexStrToByteArray(macArmAuthSeedHexStr, buildKey.Key); - } - - } while (result->NextRow()); - } -} - void RealmList::UpdateRealm(Realm& realm, Battlenet::RealmHandle const& id, uint32 build, std::string const& name, boost::asio::ip::address&& address, boost::asio::ip::address&& localAddr, uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, @@ -269,18 +218,6 @@ std::shared_ptr<Realm const> RealmList::GetCurrentRealm() const return nullptr; } -ClientBuild::Info const* RealmList::GetBuildInfo(uint32 build) const -{ - auto buildInfo = std::ranges::find(_builds, build, &ClientBuild::Info::Build); - return buildInfo != _builds.end() ? &*buildInfo : nullptr; -} - -uint32 RealmList::GetMinorMajorBugfixVersionForBuild(uint32 build) const -{ - auto buildInfo = std::ranges::lower_bound(_builds, build, {}, &ClientBuild::Info::Build); - return buildInfo != _builds.end() ? (buildInfo->MajorVersion * 10000 + buildInfo->MinorVersion * 100 + buildInfo->BugfixVersion) : 0; -} - void RealmList::WriteSubRegions(bgs::protocol::game_utilities::v1::GetAllValuesForAttributeResponse* response) const { std::shared_lock<std::shared_mutex> lock(_realmsMutex); @@ -300,7 +237,7 @@ void RealmList::FillRealmEntry(Realm const& realm, uint32 clientBuild, AccountTy realmEntry->set_cfgcategoriesid(realm.Timezone); JSON::RealmList::ClientVersion* version = realmEntry->mutable_version(); - if (ClientBuild::Info const* buildInfo = GetBuildInfo(realm.Build)) + if (ClientBuild::Info const* buildInfo = ClientBuild::GetBuildInfo(realm.Build)) { version->set_versionmajor(buildInfo->MajorVersion); version->set_versionminor(buildInfo->MinorVersion); diff --git a/src/server/shared/Realm/RealmList.h b/src/server/shared/Realm/RealmList.h index ac408feada2..4ece6124a51 100644 --- a/src/server/shared/Realm/RealmList.h +++ b/src/server/shared/Realm/RealmList.h @@ -57,7 +57,6 @@ public: ~RealmList(); void Initialize(Trinity::Asio::IoContext& ioContext, uint32 updateInterval); - void LoadBuildInfo(); void Close(); std::shared_ptr<Realm const> GetRealm(Battlenet::RealmHandle const& id) const; @@ -65,8 +64,6 @@ public: void SetCurrentRealmId(Battlenet::RealmHandle const& id); std::shared_ptr<Realm const> GetCurrentRealm() const; - ClientBuild::Info const* GetBuildInfo(uint32 build) const; - uint32 GetMinorMajorBugfixVersionForBuild(uint32 build) const; void WriteSubRegions(bgs::protocol::game_utilities::v1::GetAllValuesForAttributeResponse* response) const; std::vector<uint8> GetRealmEntryJSON(Battlenet::RealmHandle const& id, uint32 build, AccountTypes accountSecurityLevel) const; std::vector<uint8> GetRealmList(uint32 build, AccountTypes accountSecurityLevel, std::string const& subRegion) const; @@ -83,7 +80,6 @@ private: uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, RealmPopulationState population); void FillRealmEntry(Realm const& realm, uint32 clientBuild, AccountTypes accountSecurityLevel, JSON::RealmList::RealmEntry* realmEntry) const; - std::vector<ClientBuild::Info> _builds; mutable std::shared_mutex _realmsMutex; RealmMap _realms; std::map<Battlenet::RealmHandle, std::string> _removedRealms; |