aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-08-30 00:52:33 +0200
committerOvahlord <dreadkiller@gmx.de>2024-08-30 17:54:32 +0200
commit842e1b6c9b5030c05dab9149a4feb9904d440462 (patch)
treeedc4301ecface91f7381371d512582876724f6fe /src/server/shared
parent7627085c1b906a380f1680a14bb0e51b184e1cf4 (diff)
Core/Client Builds: Refactor build_info structure to support any client variants
(cherry picked from commit e94558d07892a98d78bec3633e0c82e1394b9d66) # Conflicts: # sql/base/auth_database.sql # sql/updates/auth/cata_classic/2024_08_30_00_auth.sql
Diffstat (limited to 'src/server/shared')
-rw-r--r--src/server/shared/Realm/ClientBuildInfo.cpp124
-rw-r--r--src/server/shared/Realm/ClientBuildInfo.h22
2 files changed, 113 insertions, 33 deletions
diff --git a/src/server/shared/Realm/ClientBuildInfo.cpp b/src/server/shared/Realm/ClientBuildInfo.cpp
index c2ab1632282..d3d73071802 100644
--- a/src/server/shared/Realm/ClientBuildInfo.cpp
+++ b/src/server/shared/Realm/ClientBuildInfo.cpp
@@ -17,6 +17,7 @@
#include "ClientBuildInfo.h"
#include "DatabaseEnv.h"
+#include "Log.h"
#include "Util.h"
#include <algorithm>
#include <cctype>
@@ -57,14 +58,7 @@ bool Platform::IsValid(std::string_view platform)
if (platform.length() > sizeof(uint32))
return false;
- uint32 platformInt = 0;
- for (uint8 c : platform)
- {
- platformInt <<= 8;
- platformInt |= c;
- }
-
- switch (platformInt)
+ switch (ToFourCC(platform))
{
case Win_x86:
case Win_x64:
@@ -80,17 +74,73 @@ bool Platform::IsValid(std::string_view platform)
return false;
}
+bool PlatformType::IsValid(std::string_view platformType)
+{
+ if (platformType.length() > sizeof(uint32))
+ return false;
+
+ switch (ToFourCC(platformType))
+ {
+ case Windows:
+ case macOS:
+ return true;
+ default:
+ break;
+ }
+
+ return false;
+}
+
+bool Arch::IsValid(std::string_view arch)
+{
+ if (arch.length() > sizeof(uint32))
+ return false;
+
+ switch (ToFourCC(arch))
+ {
+ case x86:
+ case x64:
+ case Arm32:
+ case Arm64:
+ case WA32:
+ return true;
+ default:
+ break;
+ }
+
+ return false;
+}
+
+bool Type::IsValid(std::string_view type)
+{
+ if (type.length() > sizeof(uint32))
+ return false;
+
+ switch (ToFourCC(type))
+ {
+ case Retail:
+ case RetailChina:
+ case Beta:
+ case BetaRelease:
+ case Ptr:
+ case PtrRelease:
+ return true;
+ default:
+ break;
+ }
+
+ 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"))
+ // 0 1 2 3 4
+ if (QueryResult result = LoginDatabase.Query("SELECT majorVersion, minorVersion, bugfixVersion, hotfixVersion, build 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();
@@ -103,30 +153,50 @@ void LoadBuildInfo()
build.HotfixVersion = { };
build.Build = fields[4].GetUInt32();
- std::string win64AuthSeedHexStr = fields[5].GetString();
- if (win64AuthSeedHexStr.length() == AuthKey::Size * 2)
+
+ } while (result->NextRow());
+ }
+
+ // 0 1 2 3 4
+ if (QueryResult result = LoginDatabase.Query("SELECT `build`, `platform`, `arch`, `type`, `key` FROM `build_auth_key`"))
+ {
+ do
+ {
+ Field* fields = result->Fetch();
+
+ uint32 build = fields[0].GetInt32();
+ auto buildInfo = std::ranges::find(Builds, build, &Info::Build);
+ if (buildInfo == Builds.end())
+ {
+ TC_LOG_ERROR("sql.sql", "ClientBuild::LoadBuildInfo: Unknown `build` {} in `build_auth_key` - missing from `build_info`, skipped.", build);
+ continue;
+ }
+
+ std::string_view platformType = fields[1].GetStringView();
+ if (!PlatformType::IsValid(platformType))
{
- AuthKey& buildKey = build.AuthKeys.emplace_back();
- buildKey.Variant = { .Platform = PlatformType::Windows, .Arch = Arch::x64, .Type = Type::Retail };
- HexStrToByteArray(win64AuthSeedHexStr, buildKey.Key);
+ TC_LOG_ERROR("sql.sql", "ClientBuild::LoadBuildInfo: Invalid platform {} for `build` {} in `build_auth_key`, skipped.", platformType, build);
+ continue;
}
- std::string mac64AuthSeedHexStr = fields[6].GetString();
- if (mac64AuthSeedHexStr.length() == AuthKey::Size * 2)
+ std::string_view arch = fields[2].GetStringView();
+ if (!Arch::IsValid(arch))
{
- AuthKey& buildKey = build.AuthKeys.emplace_back();
- buildKey.Variant = { .Platform = PlatformType::macOS, .Arch = Arch::x64, .Type = Type::Retail };
- HexStrToByteArray(mac64AuthSeedHexStr, buildKey.Key);
+ TC_LOG_ERROR("sql.sql", "ClientBuild::LoadBuildInfo: Invalid `arch` {} for `build` {} in `build_auth_key`, skipped.", arch, build);
+ continue;
}
- std::string macArmAuthSeedHexStr = fields[7].GetString();
- if (macArmAuthSeedHexStr.length() == AuthKey::Size * 2)
+ std::string_view type = fields[3].GetStringView();
+ if (!Type::IsValid(type))
{
- AuthKey& buildKey = build.AuthKeys.emplace_back();
- buildKey.Variant = { .Platform = PlatformType::macOS, .Arch = Arch::Arm64, .Type = Type::Retail };
- HexStrToByteArray(macArmAuthSeedHexStr, buildKey.Key);
+ TC_LOG_ERROR("sql.sql", "ClientBuild::LoadBuildInfo: Invalid `type` {} for `build` {} in `build_auth_key`, skipped.", type, build);
+ continue;
}
+ AuthKey& buildKey = buildInfo->AuthKeys.emplace_back();
+ buildKey.Variant = { .Platform = ToFourCC(platformType), .Arch = ToFourCC(arch), .Type = ToFourCC(type) };
+ buildKey.Key = fields[4].GetBinary<AuthKey::Size>();
+
} while (result->NextRow());
}
}
diff --git a/src/server/shared/Realm/ClientBuildInfo.h b/src/server/shared/Realm/ClientBuildInfo.h
index 9d99c28b744..56acd3af3de 100644
--- a/src/server/shared/Realm/ClientBuildInfo.h
+++ b/src/server/shared/Realm/ClientBuildInfo.h
@@ -25,21 +25,25 @@
namespace ClientBuild
{
-consteval uint32 operator""_fourcc(char const* chars, std::size_t length)
+inline constexpr uint32 ToFourCC(std::string_view text)
{
- if (length > sizeof(uint32))
- throw "Text can only be max 4 characters long";
-
uint32 uintValue = 0;
- for (uint8 c : std::string_view(chars, length))
+ for (uint8 c : text)
{
uintValue <<= 8;
uintValue |= c;
}
-
return uintValue;
}
+consteval uint32 operator""_fourcc(char const* chars, std::size_t length)
+{
+ if (length > sizeof(uint32))
+ throw "Text can only be max 4 characters long";
+
+ return ToFourCC({ chars, length });
+}
+
TC_SHARED_API std::array<char, 5> ToCharArray(uint32 value);
namespace Platform
@@ -58,6 +62,8 @@ namespace PlatformType
{
inline constexpr uint32 Windows = "Win"_fourcc;
inline constexpr uint32 macOS = "Mac"_fourcc;
+
+ TC_SHARED_API bool IsValid(std::string_view platformType);
}
namespace Arch
@@ -67,6 +73,8 @@ namespace Arch
inline constexpr uint32 Arm32 = "A32"_fourcc;
inline constexpr uint32 Arm64 = "A64"_fourcc;
inline constexpr uint32 WA32 = "WA32"_fourcc;
+
+ TC_SHARED_API bool IsValid(std::string_view arch);
}
namespace Type
@@ -77,6 +85,8 @@ namespace Type
inline constexpr uint32 BetaRelease = "WoWE"_fourcc;
inline constexpr uint32 Ptr = "WoWT"_fourcc;
inline constexpr uint32 PtrRelease = "WoWR"_fourcc;
+
+ TC_SHARED_API bool IsValid(std::string_view type);
}
struct VariantId