diff options
author | Shauren <shauren.trinity@gmail.com> | 2024-08-29 20:32:45 +0200 |
---|---|---|
committer | Ovahlord <dreadkiller@gmx.de> | 2024-08-30 17:35:13 +0200 |
commit | 7627085c1b906a380f1680a14bb0e51b184e1cf4 (patch) | |
tree | b291462671b51d5d29f255c09e7fb83e6e7c2976 /src/server/shared/Realm/ClientBuildInfo.cpp | |
parent | 6f50030654e3b26b270b5128d4dc72564f0d8029 (diff) |
Core/Client Builds: Move build info out of RealmList class
(cherry picked from commit 82031dc720ac485c32158871aec86764c2505581)
Diffstat (limited to 'src/server/shared/Realm/ClientBuildInfo.cpp')
-rw-r--r-- | src/server/shared/Realm/ClientBuildInfo.cpp | 77 |
1 files changed, 75 insertions, 2 deletions
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; +} +} |