aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-08-29 20:32:45 +0200
committerShauren <shauren.trinity@gmail.com>2024-08-29 20:32:45 +0200
commit82031dc720ac485c32158871aec86764c2505581 (patch)
tree7cf48ddae8a53dd0d36c130ce595f175e2e33946 /src/server/shared
parentd277be8718976764b6a2ed872c0e0b364c9a488b (diff)
Core/Client Builds: Move build info out of RealmList class
Diffstat (limited to 'src/server/shared')
-rw-r--r--src/server/shared/Realm/ClientBuildInfo.cpp77
-rw-r--r--src/server/shared/Realm/ClientBuildInfo.h4
-rw-r--r--src/server/shared/Realm/RealmList.cpp67
-rw-r--r--src/server/shared/Realm/RealmList.h4
4 files changed, 81 insertions, 71 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;
+}
+}
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;