From 6e2fc20fb8db092d99fad292707e15a500513a13 Mon Sep 17 00:00:00 2001 From: Hondacrx Date: Thu, 10 Oct 2024 09:44:41 -0400 Subject: [PATCH] Core/Client Builds: Refactor build_info structure to support any client variants Port From (https://github.com/TrinityCore/TrinityCore/commit/e94558d07892a98d78bec3633e0c82e1394b9d66) --- Source/Framework/Realm/ClientBuildInfo.cs | 145 +++++++++++++++------- Source/Framework/Util/Extensions.cs | 7 +- 2 files changed, 99 insertions(+), 53 deletions(-) diff --git a/Source/Framework/Realm/ClientBuildInfo.cs b/Source/Framework/Realm/ClientBuildInfo.cs index b94595314..5bd35cf8c 100644 --- a/Source/Framework/Realm/ClientBuildInfo.cs +++ b/Source/Framework/Realm/ClientBuildInfo.cs @@ -1,38 +1,12 @@ // Copyright (c) CypherCore All rights reserved. // Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information. +using Framework.Database; using System; using System.Collections.Generic; -using Framework.Database; -using System.Linq; namespace Framework.ClientBuild { - struct ClientBuildPlatformType - { - public static int Windows = "Win".fourcc(); - public static int macOS = "Mac".fourcc(); - } - - struct ClientBuildArch - { - public static int x86 = "x86".fourcc(); - public static int x64 = "x64".fourcc(); - public static int Arm32 = "A32".fourcc(); - public static int Arm64 = "A64".fourcc(); - public static int WA32 = "WA32".fourcc(); - } - - struct ClientBuildType - { - public static int Retail = "WoW".fourcc(); - public static int RetailChina = "WoWC".fourcc(); - public static int Beta = "WoWB".fourcc(); - public static int BetaRelease = "WoWE".fourcc(); - public static int Ptr = "WoWT".fourcc(); - public static int PtrRelease = "WoWR".fourcc(); - } - public class ClientBuildHelper { static List _builds = new(); @@ -41,8 +15,8 @@ namespace Framework.ClientBuild { _builds.Clear(); - // 0 1 2 3 4 5 6 7 - SQLResult result = DB.Login.Query("SELECT majorVersion, minorVersion, bugfixVersion, hotfixVersion, build, win64AuthSeed, mac64AuthSeed, macArmAuthSeed FROM build_info ORDER BY build ASC"); + // 0 1 2 3 4 + SQLResult result = DB.Login.Query("SELECT majorVersion, minorVersion, bugfixVersion, hotfixVersion, build FROM build_info ORDER BY build ASC"); if (!result.IsEmpty()) { do @@ -56,35 +30,52 @@ namespace Framework.ClientBuild build.HotfixVersion = hotfixVersion.ToCharArray(); build.Build = result.Read(4); + } + while (result.NextRow()); + } - string win64AuthSeedHexStr = result.Read(5); - if (win64AuthSeedHexStr.Length == ClientBuildAuthKey.Size * 2) + // 0 1 2 3 4 + result = DB.Login.Query("SELECT `build`, `platform`, `arch`, `type`, `key` FROM `build_auth_key`"); + if (!result.IsEmpty()) + { + do + { + uint build = result.Read(0); + var buildInfo = _builds.Find(p => p.Build == build); + if (buildInfo == null) { - ClientBuildAuthKey buildKey = new(); - buildKey.Variant = new() { Platform = ClientBuildPlatformType.Windows, Arch = ClientBuildArch.x64, Type = ClientBuildType.Retail }; - buildKey.Key = win64AuthSeedHexStr.ToByteArray(); - build.AuthKeys.Add(buildKey); + Log.outError(LogFilter.Sql, $"ClientBuildHealper.LoadBuildInfo: Unknown `build` {build} in `build_auth_key` - missing from `build_info`, skipped."); + continue; } - string mac64AuthSeedHexStr = result.Read(6); - if (mac64AuthSeedHexStr.Length == ClientBuildAuthKey.Size * 2) + string platformType = result.Read(1); + if (!IsPlatformTypeValid(platformType)) { - ClientBuildAuthKey buildKey = new(); - buildKey.Variant = new() { Platform = ClientBuildPlatformType.macOS, Arch = ClientBuildArch.x64, Type = ClientBuildType.Retail }; - buildKey.Key = mac64AuthSeedHexStr.ToByteArray(); - build.AuthKeys.Add(buildKey); + Log.outError(LogFilter.Sql, $"ClientBuild::LoadBuildInfo: Invalid platform {platformType} for `build` {build} in `build_auth_key`, skipped."); + continue; } - string macArmAuthSeedHexStr = result.Read(7); - if (macArmAuthSeedHexStr.Length == ClientBuildAuthKey.Size * 2) + string arch = result.Read(2); + if (!IsArcValid(arch)) { - ClientBuildAuthKey buildKey = new(); - buildKey.Variant = new() { Platform = ClientBuildPlatformType.macOS, Arch = ClientBuildArch.Arm64, Type = ClientBuildType.Retail }; - buildKey.Key = macArmAuthSeedHexStr.ToByteArray(); - build.AuthKeys.Add(buildKey); + Log.outError(LogFilter.Sql, $"ClientBuild::LoadBuildInfo: Invalid `arch` {arch} for `build` {build} in `build_auth_key`, skipped."); + continue; } - _builds.Add(build); + string type = result.Read(3); + if (!IsTypeValid(type)) + { + Log.outError(LogFilter.Sql, $"ClientBuild::LoadBuildInfo: Invalid `type` {type} for `build` {build} in `build_auth_key`, skipped."); + continue; + } + + ClientBuildAuthKey buildKey = new() + { + Variant = new() { Platform = platformType.ToFourCC(), Arch = arch.ToFourCC(), Type = type.ToFourCC() }, + Key = result.Read(4) + }; + + buildInfo.AuthKeys.Add(buildKey); } while (result.NextRow()); } @@ -118,6 +109,64 @@ namespace Framework.ClientBuild return false; } + + static bool IsPlatformTypeValid(string platformType) + { + if (platformType.Length > 4) + return false; + + switch (platformType) + { + case "Win": + case "Mac": + return true; + default: + break; + } + + return false; + } + + static bool IsArcValid(string arch) + { + if (arch.Length > 4) + return false; + + switch (arch) + { + case "x86": + case "x64": + case "A32": + case "A64": + case "WA32": + return true; + default: + break; + } + + return false; + } + + static bool IsTypeValid(string type) + { + if (type.Length > 4) + return false; + + switch (type) + { + case "WoW": + case "WoWC": + case "WoWB": + case "WoWE": + case "WoWT": + case "WoWR": + return true; + default: + break; + } + + return false; + } } public class ClientBuildVariantId diff --git a/Source/Framework/Util/Extensions.cs b/Source/Framework/Util/Extensions.cs index 9a922dd1a..74733f5b8 100644 --- a/Source/Framework/Util/Extensions.cs +++ b/Source/Framework/Util/Extensions.cs @@ -439,13 +439,10 @@ namespace System return hash; } - public static int fourcc(this string str) + public static int ToFourCC(this string text) { - //if (length > sizeof(uint)) - // throw "Text can only be max 4 characters long"; - int intValue = 0; - foreach (char c in str.ToCharArray()) + foreach (char c in text) { intValue <<= 8; intValue |= c;