From 2b8c5ad42dc886a7246b18af99c4966e9f1aba0e Mon Sep 17 00:00:00 2001 From: Shauren Date: Thu, 29 Aug 2024 15:08:47 +0200 Subject: Core/Auth: Refactor client auth key storage to support more future client variants and preserve more information about client version (cherry picked from commit 8e1595265925e0840d07e943b8c9ff1e906d4719) --- src/server/shared/Realm/ClientBuildInfo.cpp | 72 +++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/server/shared/Realm/ClientBuildInfo.cpp (limited to 'src/server/shared/Realm/ClientBuildInfo.cpp') diff --git a/src/server/shared/Realm/ClientBuildInfo.cpp b/src/server/shared/Realm/ClientBuildInfo.cpp new file mode 100644 index 00000000000..12a4b9ec5a0 --- /dev/null +++ b/src/server/shared/Realm/ClientBuildInfo.cpp @@ -0,0 +1,72 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "ClientBuildInfo.h" +#include +#include + +std::array ClientBuild::ToCharArray(uint32 value) +{ + auto normalize = [](uint8 c) -> char + { + if (!c || std::isprint(c)) + return char(c); + return ' '; + }; + + std::array chars = { char((value >> 24) & 0xFF), char((value >> 16) & 0xFF), char((value >> 8) & 0xFF), char(value & 0xFF), '\0' }; + + auto firstNonZero = std::ranges::find_if(chars, [](char c) { return c != '\0'; }); + if (firstNonZero != chars.end()) + { + // move leading zeros to end + std::ranges::rotate(chars, firstNonZero); + + // ensure we only have printable characters remaining + std::ranges::transform(chars, chars.begin(), normalize); + } + + return chars; +} + +bool ClientBuild::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) + { + case Win_x86: + case Win_x64: + case Win_arm64: + case Mac_x86: + case Mac_x64: + case Mac_arm64: + return true; + default: + break; + } + + return false; +} -- cgit v1.2.3