TrinityCore
Loading...
Searching...
No Matches
ClientBuildInfo.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "ClientBuildInfo.h"
19#include "DatabaseEnv.h"
20#include "Log.h"
21#include <algorithm>
22
23namespace
24{
25std::vector<ClientBuild::Info> Builds;
26}
27
28namespace ClientBuild
29{
30bool Program::IsValid(std::string_view program)
31{
32 if (program.length() > sizeof(uint32))
33 return false;
34
35 switch (Id::FromString(program))
36 {
37 case WoW:
38 return true;
39 default:
40 break;
41 }
42
43 return false;
44}
45
46bool Platform::IsValid(std::string_view platform)
47{
48 if (platform.length() > sizeof(uint32))
49 return false;
50
51 switch (Id::FromString(platform))
52 {
53 case Win_x86:
54 case Win_x64:
55 case Win_arm64:
56 case Mac_x86:
57 case Mac_x64:
58 case Mac_arm64:
59 return true;
60 default:
61 break;
62 }
63
64 return false;
65}
66
67bool PlatformType::IsValid(std::string_view platformType)
68{
69 if (platformType.length() > sizeof(uint32))
70 return false;
71
72 switch (Id::FromString(platformType))
73 {
74 case Windows:
75 case macOS:
76 return true;
77 default:
78 break;
79 }
80
81 return false;
82}
83
84bool Arch::IsValid(std::string_view arch)
85{
86 if (arch.length() > sizeof(uint32))
87 return false;
88
89 switch (Id::FromString(arch))
90 {
91 case x86:
92 case x64:
93 case Arm32:
94 case Arm64:
95 case WA32:
96 return true;
97 default:
98 break;
99 }
100
101 return false;
102}
103
104bool Type::IsValid(std::string_view type)
105{
106 if (type.length() > sizeof(uint32))
107 return false;
108
109 switch (Id::FromString(type))
110 {
111 case Retail:
112 case RetailChina:
113 case Beta:
114 case BetaRelease:
115 case Ptr:
116 case PtrRelease:
117 return true;
118 default:
119 break;
120 }
121
122 return false;
123}
124
126{
127 Builds.clear();
128
129 // 0 1 2 3 4
130 if (QueryResult result = LoginDatabase.Query("SELECT majorVersion, minorVersion, bugfixVersion, hotfixVersion, build FROM build_info ORDER BY build ASC"))
131 {
132 do
133 {
134 Field* fields = result->Fetch();
135 Info& build = Builds.emplace_back();
136 build.MajorVersion = fields[0].GetUInt32();
137 build.MinorVersion = fields[1].GetUInt32();
138 build.BugfixVersion = fields[2].GetUInt32();
139 std::string_view hotfixVersion = fields[3].GetStringView();
140 if (hotfixVersion.length() < build.HotfixVersion.size())
141 std::ranges::copy(hotfixVersion, build.HotfixVersion.begin());
142 else
143 build.HotfixVersion = { };
144
145 build.Build = fields[4].GetUInt32();
146
147 } while (result->NextRow());
148 }
149
150 // 0 1 2 3 4
151 if (QueryResult result = LoginDatabase.Query("SELECT `build`, `platform`, `arch`, `type`, `key` FROM `build_auth_key`"))
152 {
153 do
154 {
155 Field* fields = result->Fetch();
156
157 uint32 build = fields[0].GetInt32();
158 auto buildInfo = std::ranges::find(Builds, build, &Info::Build);
159 if (buildInfo == Builds.end())
160 {
161 TC_LOG_ERROR("sql.sql", "ClientBuild::LoadBuildInfo: Unknown `build` {} in `build_auth_key` - missing from `build_info`, skipped.", build);
162 continue;
163 }
164
165 std::string_view platformType = fields[1].GetStringView();
166 if (!PlatformType::IsValid(platformType))
167 {
168 TC_LOG_ERROR("sql.sql", "ClientBuild::LoadBuildInfo: Invalid platform {} for `build` {} in `build_auth_key`, skipped.", platformType, build);
169 continue;
170 }
171
172 std::string_view arch = fields[2].GetStringView();
173 if (!Arch::IsValid(arch))
174 {
175 TC_LOG_ERROR("sql.sql", "ClientBuild::LoadBuildInfo: Invalid `arch` {} for `build` {} in `build_auth_key`, skipped.", arch, build);
176 continue;
177 }
178
179 std::string_view type = fields[3].GetStringView();
180 if (!Type::IsValid(type))
181 {
182 TC_LOG_ERROR("sql.sql", "ClientBuild::LoadBuildInfo: Invalid `type` {} for `build` {} in `build_auth_key`, skipped.", type, build);
183 continue;
184 }
185
186 AuthKey& buildKey = buildInfo->AuthKeys.emplace_back();
187 buildKey.Variant = { .Platform = Platform::Id::FromString(platformType), .Arch = Arch::Id::FromString(arch), .Type = Type::Id::FromString(type) };
188 buildKey.Key = fields[4].GetBinary<AuthKey::Size>();
189
190 } while (result->NextRow());
191 }
192}
193
195{
196 auto buildInfo = std::ranges::find(Builds, build, &Info::Build);
197 return buildInfo != Builds.end() ? &*buildInfo : nullptr;
198}
199
201{
202 auto buildInfo = std::ranges::lower_bound(Builds, build, {}, &Info::Build);
203 return buildInfo != Builds.end() ? (buildInfo->MajorVersion * 10000 + buildInfo->MinorVersion * 100 + buildInfo->BugfixVersion) : 0;
204}
205}
std::shared_ptr< ResultSet > QueryResult
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
uint32_t uint32
Definition Define.h:154
#define TC_LOG_ERROR(filterType__, message__,...)
Definition Log.h:182
Class used to access individual fields of database query result.
Definition Field.h:94
std::vector< uint8 > GetBinary() const noexcept
Definition Field.cpp:125
uint32 GetUInt32() const noexcept
Definition Field.cpp:57
std::string_view GetStringView() const noexcept
Definition Field.cpp:118
int32 GetInt32() const noexcept
Definition Field.cpp:64
uint32 GetMinorMajorBugfixVersionForBuild(uint32 build)
Info const * GetBuildInfo(uint32 build)
static constexpr Id x86
static constexpr Id WA32
static constexpr Id Arm64
static constexpr Id Arm32
static TC_SHARED_API bool IsValid(std::string_view arch)
static constexpr Id x64
std::array< uint8, Size > Key
static constexpr std::size_t Size
std::array< char, 4 > HotfixVersion
static constexpr Id Windows
static constexpr Id macOS
static TC_SHARED_API bool IsValid(std::string_view platformType)
static constexpr Id Win_arm64
static constexpr Id Mac_arm64
static constexpr Id Win_x86
static TC_SHARED_API bool IsValid(std::string_view platform)
static constexpr Id Mac_x86
static constexpr Id Win_x64
static constexpr Id Mac_x64
static constexpr Id WoW
static TC_SHARED_API bool IsValid(std::string_view program)
static constexpr Id BetaRelease
static constexpr Id Beta
static constexpr Id PtrRelease
static constexpr Id Retail
static constexpr Id Ptr
static TC_SHARED_API bool IsValid(std::string_view type)
static constexpr Id RetailChina
ClientBuild::Platform::Id Platform
static constexpr FourCC FromString(std::string_view text)
Definition FourCC.h:33