Cuberite
A lightweight, fast and extensible game server for Minecraft
MojangAPI.cpp
Go to the documentation of this file.
1 
2 // MojangAPI.cpp
3 
4 // Implements the cMojangAPI class representing the various API points provided by Mojang's webservices, and a cache for their results
5 
6 #include "Globals.h"
7 #include "MojangAPI.h"
8 #include "SQLiteCpp/Database.h"
9 #include "SQLiteCpp/Statement.h"
10 #include "../IniFile.h"
11 #include "json/json.h"
12 #include "../mbedTLS++/BlockingSslClientSocket.h"
13 #include "../mbedTLS++/SslConfig.h"
14 #include "../RankManager.h"
15 #include "../OSSupport/IsThread.h"
16 #include "../Root.h"
17 
18 
19 
20 
21 
23 const Int64 MAX_AGE = 7 * 24 * 60 * 60; // 7 days ago
24 
26 const int MAX_PER_QUERY = 100;
27 
28 
29 
30 
31 
32 #define DEFAULT_NAME_TO_UUID_SERVER "api.mojang.com"
33 #define DEFAULT_NAME_TO_UUID_ADDRESS "/profiles/minecraft"
34 #define DEFAULT_UUID_TO_PROFILE_SERVER "sessionserver.mojang.com"
35 #define DEFAULT_UUID_TO_PROFILE_ADDRESS "/session/minecraft/profile/%UUID%?unsigned=false"
36 
37 
38 
39 
40 
43 {
44  static const char CertString[] =
45  // GeoTrust root CA cert
46  // Currently used for signing *.mojang.com's cert
47  // Exported from Mozilla Firefox's built-in CA repository
48  "-----BEGIN CERTIFICATE-----\n"
49  "MIIDVDCCAjygAwIBAgIDAjRWMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT\n"
50  "MRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMRswGQYDVQQDExJHZW9UcnVzdCBHbG9i\n"
51  "YWwgQ0EwHhcNMDIwNTIxMDQwMDAwWhcNMjIwNTIxMDQwMDAwWjBCMQswCQYDVQQG\n"
52  "EwJVUzEWMBQGA1UEChMNR2VvVHJ1c3QgSW5jLjEbMBkGA1UEAxMSR2VvVHJ1c3Qg\n"
53  "R2xvYmFsIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2swYYzD9\n"
54  "9BcjGlZ+W988bDjkcbd4kdS8odhM+KhDtgPpTSEHCIjaWC9mOSm9BXiLnTjoBbdq\n"
55  "fnGk5sRgprDvgOSJKA+eJdbtg/OtppHHmMlCGDUUna2YRpIuT8rxh0PBFpVXLVDv\n"
56  "iS2Aelet8u5fa9IAjbkU+BQVNdnARqN7csiRv8lVK83Qlz6cJmTM386DGXHKTubU\n"
57  "1XupGc1V3sjs0l44U+VcT4wt/lAjNvxm5suOpDkZALeVAjmRCw7+OC7RHQWa9k0+\n"
58  "bw8HHa8sHo9gOeL6NlMTOdReJivbPagUvTLrGAMoUgRx5aszPeE4uwc2hGKceeoW\n"
59  "MPRfwCvocWvk+QIDAQABo1MwUTAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTA\n"
60  "ephojYn7qwVkDBF9qn1luMrMTjAfBgNVHSMEGDAWgBTAephojYn7qwVkDBF9qn1l\n"
61  "uMrMTjANBgkqhkiG9w0BAQUFAAOCAQEANeMpauUvXVSOKVCUn5kaFOSPeCpilKIn\n"
62  "Z57QzxpeR+nBsqTP3UEaBU6bS+5Kb1VSsyShNwrrZHYqLizz/Tt1kL/6cdjHPTfS\n"
63  "tQWVYrmm3ok9Nns4d0iXrKYgjy6myQzCsplFAMfOEVEiIuCl6rYVSAlk6l5PdPcF\n"
64  "PseKUgzbFbS9bZvlxrFUaKnjaZC2mqUPuLk/IH2uSrW4nOQdtqvmlKXBx4Ot2/Un\n"
65  "hw4EbNX/3aBd7YdStysVAq45pmp06drE57xNNB6pXE0zX5IJL4hmXXeXxx12E6nV\n"
66  "5fEWCRE11azbJHFwLJhWC9kXtNHjUStedejV0NxPNO3CBWaAocvmMw==\n"
67  "-----END CERTIFICATE-----\n\n"
68 
69  // Equifax root CA cert
70  // Exported from Mozilla Firefox's built-in CA repository
71  "-----BEGIN CERTIFICATE-----\n"
72  "MIIDIDCCAomgAwIBAgIENd70zzANBgkqhkiG9w0BAQUFADBOMQswCQYDVQQGEwJV\n"
73  "UzEQMA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2Vy\n"
74  "dGlmaWNhdGUgQXV0aG9yaXR5MB4XDTk4MDgyMjE2NDE1MVoXDTE4MDgyMjE2NDE1\n"
75  "MVowTjELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0VxdWlmYXgxLTArBgNVBAsTJEVx\n"
76  "dWlmYXggU2VjdXJlIENlcnRpZmljYXRlIEF1dGhvcml0eTCBnzANBgkqhkiG9w0B\n"
77  "AQEFAAOBjQAwgYkCgYEAwV2xWGcIYu6gmi0fCG2RFGiYCh7+2gRvE4RiIcPRfM6f\n"
78  "BeC4AfBONOziipUEZKzxa1NfBbPLZ4C/QgKO/t0BCezhABRP/PvwDN1Dulsr4R+A\n"
79  "cJkVV5MW8Q+XarfCaCMczE1ZMKxRHjuvK9buY0V7xdlfUNLjUA86iOe/FP3gx7kC\n"
80  "AwEAAaOCAQkwggEFMHAGA1UdHwRpMGcwZaBjoGGkXzBdMQswCQYDVQQGEwJVUzEQ\n"
81  "MA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2VydGlm\n"
82  "aWNhdGUgQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMBoGA1UdEAQTMBGBDzIwMTgw\n"
83  "ODIyMTY0MTUxWjALBgNVHQ8EBAMCAQYwHwYDVR0jBBgwFoAUSOZo+SvSspXXR9gj\n"
84  "IBBPM5iQn9QwHQYDVR0OBBYEFEjmaPkr0rKV10fYIyAQTzOYkJ/UMAwGA1UdEwQF\n"
85  "MAMBAf8wGgYJKoZIhvZ9B0EABA0wCxsFVjMuMGMDAgbAMA0GCSqGSIb3DQEBBQUA\n"
86  "A4GBAFjOKer89961zgK5F7WF0bnj4JXMJTENAKaSbn+2kmOeUJXRmm/kEd5jhW6Y\n"
87  "7qj/WsjTVbJmcVfewCHrPSqnI0kBBIZCe/zuf6IWUrVnZ9NA2zsmWLIodz2uFHdh\n"
88  "1voqZiegDfqnc1zqcPGUIWVEX/r87yloqaKHee9570+sB3c4\n"
89  "-----END CERTIFICATE-----\n\n"
90 
91  // Starfield G2 cert
92  // This is the data of the root certs for Starfield Technologies, the CA that used to sign sessionserver.mojang.com's cert
93  // Downloaded from https://certs.starfieldtech.com/repository/
94  "-----BEGIN CERTIFICATE-----\n"
95  "MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMx\n"
96  "EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoT\n"
97  "HFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAMTKVN0YXJmaWVs\n"
98  "ZCBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5MDkwMTAwMDAw\n"
99  "MFoXDTM3MTIzMTIzNTk1OVowgY8xCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6\n"
100  "b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxTdGFyZmllbGQgVGVj\n"
101  "aG5vbG9naWVzLCBJbmMuMTIwMAYDVQQDEylTdGFyZmllbGQgUm9vdCBDZXJ0aWZp\n"
102  "Y2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\n"
103  "ggEBAL3twQP89o/8ArFvW59I2Z154qK3A2FWGMNHttfKPTUuiUP3oWmb3ooa/RMg\n"
104  "nLRJdzIpVv257IzdIvpy3Cdhl+72WoTsbhm5iSzchFvVdPtrX8WJpRBSiUZV9Lh1\n"
105  "HOZ/5FSuS/hVclcCGfgXcVnrHigHdMWdSL5stPSksPNkN3mSwOxGXn/hbVNMYq/N\n"
106  "Hwtjuzqd+/x5AJhhdM8mgkBj87JyahkNmcrUDnXMN/uLicFZ8WJ/X7NfZTD4p7dN\n"
107  "dloedl40wOiWVpmKs/B/pM293DIxfJHP4F8R+GuqSVzRmZTRouNjWwl2tVZi4Ut0\n"
108  "HZbUJtQIBFnQmA4O5t78w+wfkPECAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAO\n"
109  "BgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFHwMMh+n2TB/xH1oo2Kooc6rB1snMA0G\n"
110  "CSqGSIb3DQEBCwUAA4IBAQARWfolTwNvlJk7mh+ChTnUdgWUXuEok21iXQnCoKjU\n"
111  "sHU48TRqneSfioYmUeYs0cYtbpUgSpIB7LiKZ3sx4mcujJUDJi5DnUox9g61DLu3\n"
112  "4jd/IroAow57UvtruzvE03lRTs2Q9GcHGcg8RnoNAX3FWOdt5oUwF5okxBDgBPfg\n"
113  "8n/Uqgr/Qh037ZTlZFkSIHc40zI+OIF1lnP6aI+xy84fxez6nH7PfrHxBy22/L/K\n"
114  "pL/QlwVKvOoYKAKQvVR4CSFx09F9HdkWsKlhPdAKACL8x3vLCWRFCztAgfd9fDL1\n"
115  "mMpYjn0q7pBZc2T5NnReJaH1ZgUufzkVqSr7UIuOhWn0\n"
116  "-----END CERTIFICATE-----\n\n"
117 
118  // Starfield original (G1) cert:
119  "-----BEGIN CERTIFICATE-----\n"
120  "MIIEDzCCAvegAwIBAgIBADANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJVUzEl\n"
121  "MCMGA1UEChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMp\n"
122  "U3RhcmZpZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDQw\n"
123  "NjI5MTczOTE2WhcNMzQwNjI5MTczOTE2WjBoMQswCQYDVQQGEwJVUzElMCMGA1UE\n"
124  "ChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMpU3RhcmZp\n"
125  "ZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEgMA0GCSqGSIb3\n"
126  "DQEBAQUAA4IBDQAwggEIAoIBAQC3Msj+6XGmBIWtDBFk385N78gDGIc/oav7PKaf\n"
127  "8MOh2tTYbitTkPskpD6E8J7oX+zlJ0T1KKY/e97gKvDIr1MvnsoFAZMej2YcOadN\n"
128  "+lq2cwQlZut3f+dZxkqZJRRU6ybH838Z1TBwj6+wRir/resp7defqgSHo9T5iaU0\n"
129  "X9tDkYI22WY8sbi5gv2cOj4QyDvvBmVmepsZGD3/cVE8MC5fvj13c7JdBmzDI1aa\n"
130  "K4UmkhynArPkPw2vCHmCuDY96pzTNbO8acr1zJ3o/WSNF4Azbl5KXZnJHoe0nRrA\n"
131  "1W4TNSNe35tfPe/W93bC6j67eA0cQmdrBNj41tpvi/JEoAGrAgEDo4HFMIHCMB0G\n"
132  "A1UdDgQWBBS/X7fRzt0fhvRbVazc1xDCDqmI5zCBkgYDVR0jBIGKMIGHgBS/X7fR\n"
133  "zt0fhvRbVazc1xDCDqmI56FspGowaDELMAkGA1UEBhMCVVMxJTAjBgNVBAoTHFN0\n"
134  "YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAsTKVN0YXJmaWVsZCBD\n"
135  "bGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8w\n"
136  "DQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGsafPzWdqbAYcaT1epoXkJKtv3\n"
137  "L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLMPUxA2IGvd56D\n"
138  "eruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJl\n"
139  "xy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynp\n"
140  "VSJYACPq4xJDKVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEY\n"
141  "WQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q=\n"
142  "-----END CERTIFICATE-----\n"
143  ;
144 
145  static auto X509Cert = [&]()
146  {
147  auto Cert = std::make_shared<cX509Cert>();
148  VERIFY(0 == Cert->Parse(CertString, sizeof(CertString)));
149  return Cert;
150  }();
151 
152  return X509Cert;
153 }
154 
155 
156 
157 
158 
160 static std::shared_ptr<const cSslConfig> GetSslConfig()
161 {
162  static const std::shared_ptr<const cSslConfig> Config = []()
163  {
164  auto Conf = cSslConfig::MakeDefaultConfig(true);
165  Conf->SetCACerts(GetCACerts());
166  Conf->SetAuthMode(eSslAuthMode::Required);
167  return Conf;
168  }();
169  return Config;
170 }
171 
172 
173 
174 
175 
177 // cMojangAPI::sProfile:
178 
180  const AString & a_PlayerName,
181  const cUUID & a_UUID,
182  const Json::Value & a_Properties,
183  Int64 a_DateTime
184 ) :
185  m_PlayerName(a_PlayerName),
186  m_UUID(a_UUID),
187  m_Textures(),
188  m_TexturesSignature(),
189  m_DateTime(a_DateTime)
190 {
191  /*
192  Example a_Profile contents:
193  "properties":
194  [
195  {
196  "name": "textures",
197  "value": "eyJ0aW1lc3RhbXAiOjE0MDcwNzAzMjEyNzEsInByb2ZpbGVJZCI6ImIxY2FmMjQyMDJhODQxYTc4MDU1YTA3OWM0NjBlZWU3IiwicHJvZmlsZU5hbWUiOiJ4b2Z0IiwiaXNQdWJsaWMiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9iNzc5YmFiZjVhNTg3Zjk0OGFkNjc0N2VhOTEyNzU0MjliNjg4Mjk1YWUzYzA3YmQwZTJmNWJmNGQwNTIifX19",
198  "signature": "XCty+jGEF39hEPrPhYNnCX087kPaoCjYruzYI/DS4nkL5hbjnkSM5Rh15hnUyv/FHhC8OF5rif3D1tQjtMI19KSVaXoUFXpbJM8/+PB8GDgEbX8Fc3u9nYkzOcM/xfxdYsFAdFhLQMkvase/BZLSuPhdy9DdI+TCrO7xuSTZfYmmwVuWo3w5gCY+mSIAnqltnOzaOOTcly75xvO0WYpVk7nJdnR2tvSi0wfrQPDrIg/uzhX7p0SnDqijmBU4QaNez/TNKiFxy69dAzt0RSotlQzqkDbyVKhhv9a4eY8h3pXi4UMftKEj4FAKczxLImkukJXuOn5NN15/Q+le0rJVBC60/xjKIVzltEsMN6qjWD0lQjey7WEL+4pGhCVuWY5KzuZjFvgqszuJTFz7lo+bcHiceldJtea8/fa02eTRObZvdLxbWC9ZfFY0IhpOVKfcLdno/ddDMNMQMi5kMrJ8MZZ/PcW1w5n7MMGWPGCla1kOaC55AL0QYSMGRVEZqgU9wXI5M7sHGZKGM4mWxkbEJYBkpI/p3GyxWgV6v33ZWlsz65TqlNrR1gCLaoFCm7Sif8NqPBZUAONHYon0roXhin/DyEanS93WV6i6FC1Wisscjq2AcvnOlgTo/5nN/1QsMbjNumuMGo37sqjRqlXoPb8zEUbAhhztYuJjEfQ2Rd8="
199  }
200  ]
201  */
202 
203  // Parse the Textures and TexturesSignature from the Profile:
204  if (!a_Properties.isArray())
205  {
206  // Properties is not a valid array, bail out
207  return;
208  }
209  Json::UInt Size = a_Properties.size();
210  for (Json::UInt i = 0; i < Size; i++)
211  {
212  const Json::Value & Prop = a_Properties[i];
213  AString PropName = Prop.get("name", "").asString();
214  if (PropName != "textures")
215  {
216  continue;
217  }
218  m_Textures = Prop.get("value", "").asString();
219  m_TexturesSignature = Prop.get("signature", "").asString();
220  break;
221  } // for i - Properties[]
222 }
223 
224 
225 
226 
227 
229 // cMojangAPI::cUpdateThread:
230 
232  public cIsThread
233 {
234  typedef cIsThread super;
235 public:
236  cUpdateThread(cMojangAPI & a_MojangAPI) :
237  super("cMojangAPI::cUpdateThread"),
238  m_MojangAPI(a_MojangAPI)
239  {
240  }
241 
242  virtual ~cUpdateThread() override
243  {
244  // Notify the thread that it should stop:
245  m_ShouldTerminate = true;
246  m_evtNotify.Set();
247 
248  // Wait for the thread to actually finish work:
249  Stop();
250  }
251 
252 protected:
253 
256 
259 
260 
261  // cIsThread override:
262  virtual void Execute(void) override
263  {
264  do
265  {
266  m_MojangAPI.Update();
267  } while (!m_ShouldTerminate && !m_evtNotify.Wait(60 * 60 * 1000)); // Repeat every 60 minutes until termination request
268  }
269 } ;
270 
271 
272 
273 
274 
276 // cMojangAPI:
277 
283  m_RankMgr(nullptr),
284  m_UpdateThread(new cUpdateThread(*this))
285 {
286 }
287 
288 
289 
290 
291 
293 {
295 }
296 
297 
298 
299 
300 
301 void cMojangAPI::Start(cSettingsRepositoryInterface & a_Settings, bool a_ShouldAuth)
302 {
303  m_NameToUUIDServer = a_Settings.GetValueSet("MojangAPI", "NameToUUIDServer", DEFAULT_NAME_TO_UUID_SERVER);
304  m_NameToUUIDAddress = a_Settings.GetValueSet("MojangAPI", "NameToUUIDAddress", DEFAULT_NAME_TO_UUID_ADDRESS);
305  m_UUIDToProfileServer = a_Settings.GetValueSet("MojangAPI", "UUIDToProfileServer", DEFAULT_UUID_TO_PROFILE_SERVER);
306  m_UUIDToProfileAddress = a_Settings.GetValueSet("MojangAPI", "UUIDToProfileAddress", DEFAULT_UUID_TO_PROFILE_ADDRESS);
308  if (a_ShouldAuth)
309  {
310  m_UpdateThread->Start();
311  }
312 }
313 
314 
315 
316 
317 
318 cUUID cMojangAPI::GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_UseOnlyCached)
319 {
320  // Convert the playername to lowercase:
321  AString lcPlayerName = StrToLower(a_PlayerName);
322 
323  // Request the cache to query the name if not yet cached:
324  if (!a_UseOnlyCached)
325  {
326  AStringVector PlayerNames{ lcPlayerName };
327  CacheNamesToUUIDs(PlayerNames);
328  }
329 
330  // Retrieve from cache:
331  cCSLock Lock(m_CSNameToUUID);
332  cProfileMap::const_iterator itr = m_NameToUUID.find(lcPlayerName);
333  if (itr == m_NameToUUID.end())
334  {
335  // No UUID found
336  return {};
337  }
338  return itr->second.m_UUID;
339 }
340 
341 
342 
343 
344 
345 AString cMojangAPI::GetPlayerNameFromUUID(const cUUID & a_UUID, bool a_UseOnlyCached)
346 {
347  // Retrieve from caches:
348  {
350  auto itr = m_UUIDToProfile.find(a_UUID);
351  if (itr != m_UUIDToProfile.end())
352  {
353  return itr->second.m_PlayerName;
354  }
355  }
356  {
357  cCSLock Lock(m_CSUUIDToName);
358  auto itr = m_UUIDToName.find(a_UUID);
359  if (itr != m_UUIDToName.end())
360  {
361  return itr->second.m_PlayerName;
362  }
363  }
364 
365  // Name not yet cached, request cache and retry:
366  if (!a_UseOnlyCached)
367  {
368  CacheUUIDToProfile(a_UUID);
369  return GetPlayerNameFromUUID(a_UUID, true);
370  }
371 
372  // No value found, none queried. Return an error:
373  return {};
374 }
375 
376 
377 
378 
379 
380 std::vector<cUUID> cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_PlayerNames, bool a_UseOnlyCached)
381 {
382  // Convert all playernames to lowercase:
383  AStringVector PlayerNames;
384  for (AStringVector::const_iterator itr = a_PlayerNames.begin(), end = a_PlayerNames.end(); itr != end; ++itr)
385  {
386  PlayerNames.push_back(StrToLower(*itr));
387  } // for itr - a_PlayerNames[]
388 
389  // Request the cache to populate any names not yet contained:
390  if (!a_UseOnlyCached)
391  {
392  CacheNamesToUUIDs(PlayerNames);
393  }
394 
395  // Retrieve from cache:
396  size_t idx = 0;
397  std::vector<cUUID> res;
398  res.resize(PlayerNames.size());
399  cCSLock Lock(m_CSNameToUUID);
400  for (AStringVector::const_iterator itr = PlayerNames.begin(), end = PlayerNames.end(); itr != end; ++itr, ++idx)
401  {
402  cProfileMap::const_iterator itrN = m_NameToUUID.find(*itr);
403  if (itrN != m_NameToUUID.end())
404  {
405  res[idx] = itrN->second.m_UUID;
406  }
407  } // for itr - PlayerNames[]
408  return res;
409 }
410 
411 
412 
413 
414 
415 void cMojangAPI::AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const cUUID & a_UUID)
416 {
417  Int64 Now = time(nullptr);
418  {
419  cCSLock Lock(m_CSNameToUUID);
420  m_NameToUUID[StrToLower(a_PlayerName)] = sProfile(a_PlayerName, a_UUID, "", "", Now);
421  }
422  {
423  cCSLock Lock(m_CSUUIDToName);
424  m_UUIDToName[a_UUID] = sProfile(a_PlayerName, a_UUID, "", "", Now);
425  }
426  NotifyNameUUID(a_PlayerName, a_UUID);
427 }
428 
429 
430 
431 
432 
433 void cMojangAPI::AddPlayerProfile(const AString & a_PlayerName, const cUUID & a_UUID, const Json::Value & a_Properties)
434 {
435  Int64 Now = time(nullptr);
436  {
437  cCSLock Lock(m_CSNameToUUID);
438  m_NameToUUID[StrToLower(a_PlayerName)] = sProfile(a_PlayerName, a_UUID, "", "", Now);
439  }
440  {
441  cCSLock Lock(m_CSUUIDToName);
442  m_UUIDToName[a_UUID] = sProfile(a_PlayerName, a_UUID, "", "", Now);
443  }
444  {
446  m_UUIDToProfile[a_UUID] = sProfile(a_PlayerName, a_UUID, a_Properties, Now);
447  }
448  NotifyNameUUID(a_PlayerName, a_UUID);
449 }
450 
451 
452 
453 
454 
455 bool cMojangAPI::SecureRequest(const AString & a_ServerName, const AString & a_Request, AString & a_Response)
456 {
457  // Connect the socket:
459  Socket.SetSslConfig(GetSslConfig());
460  Socket.SetExpectedPeerName(a_ServerName);
461  if (!Socket.Connect(a_ServerName, 443))
462  {
463  LOGWARNING("%s: Can't connect to %s: %s", __FUNCTION__, a_ServerName.c_str(), Socket.GetLastErrorText().c_str());
464  return false;
465  }
466 
467  if (!Socket.Send(a_Request.c_str(), a_Request.size()))
468  {
469  LOGWARNING("%s: Writing SSL data failed: %s", __FUNCTION__, Socket.GetLastErrorText().c_str());
470  return false;
471  }
472 
473  // Read the HTTP response:
474  unsigned char buf[1024];
475 
476  for (;;)
477  {
478  int ret = Socket.Receive(buf, sizeof(buf));
479 
480  if ((ret == MBEDTLS_ERR_SSL_WANT_READ) || (ret == MBEDTLS_ERR_SSL_WANT_WRITE))
481  {
482  // This value should never be returned, it is handled internally by cBlockingSslClientSocket
483  LOGWARNING("%s: SSL reading failed internally", __FUNCTION__);
484  return false;
485  }
486  if (ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY)
487  {
488  break;
489  }
490  if (ret < 0)
491  {
492  LOGWARNING("%s: SSL reading failed: -0x%x", __FUNCTION__, -ret);
493  return false;
494  }
495  if (ret == 0)
496  {
497  break;
498  }
499 
500  a_Response.append(reinterpret_cast<const char *>(buf), static_cast<size_t>(ret));
501  }
502 
503  return true;
504 }
505 
506 
507 
508 
509 
511 {
512  try
513  {
514  // Open up the SQLite DB:
515  SQLite::Database db("MojangAPI.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
516  db.exec("CREATE TABLE IF NOT EXISTS PlayerNameToUUID (PlayerName, UUID, DateTime)");
517  db.exec("CREATE TABLE IF NOT EXISTS UUIDToProfile (UUID, PlayerName, Textures, TexturesSignature, DateTime)");
518 
519  // Retrieve all entries:
520  {
521  SQLite::Statement stmt(db, "SELECT PlayerName, UUID, DateTime FROM PlayerNameToUUID");
522  while (stmt.executeStep())
523  {
524  AString PlayerName = stmt.getColumn(0);
525  AString StringUUID = stmt.getColumn(1);
526  Int64 DateTime = stmt.getColumn(2);
527 
528  cUUID UUID;
529  if (!UUID.FromString(StringUUID))
530  {
531  continue; // Invalid UUID
532  }
533 
534  m_NameToUUID[StrToLower(PlayerName)] = sProfile(PlayerName, UUID, "", "", DateTime);
535  m_UUIDToName[UUID] = sProfile(PlayerName, UUID, "", "", DateTime);
536  }
537  }
538  {
539  SQLite::Statement stmt(db, "SELECT PlayerName, UUID, Textures, TexturesSignature, DateTime FROM UUIDToProfile");
540  while (stmt.executeStep())
541  {
542  AString PlayerName = stmt.getColumn(0);
543  AString StringUUID = stmt.getColumn(1);
544  AString Textures = stmt.getColumn(2);
545  AString TexturesSignature = stmt.getColumn(2);
546  Int64 DateTime = stmt.getColumn(4);
547 
548  cUUID UUID;
549  if (!UUID.FromString(StringUUID))
550  {
551  continue; // Invalid UUID
552  }
553 
554  m_UUIDToProfile[UUID] = sProfile(PlayerName, UUID, Textures, TexturesSignature, DateTime);
555  }
556  }
557  }
558  catch (const SQLite::Exception & ex)
559  {
560  LOGINFO("Loading MojangAPI cache failed: %s", ex.what());
561  }
562 }
563 
564 
565 
566 
567 
569 {
570  try
571  {
572  // Open up the SQLite DB:
573  SQLite::Database db("MojangAPI.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
574  db.exec("CREATE TABLE IF NOT EXISTS PlayerNameToUUID (PlayerName, UUID, DateTime)");
575  db.exec("CREATE TABLE IF NOT EXISTS UUIDToProfile (UUID, PlayerName, Textures, TexturesSignature, DateTime)");
576 
577  // Remove all entries:
578  db.exec("DELETE FROM PlayerNameToUUID");
579  db.exec("DELETE FROM UUIDToProfile");
580 
581  // Save all cache entries - m_PlayerNameToUUID:
582  Int64 LimitDateTime = time(nullptr) - MAX_AGE;
583  {
584  SQLite::Statement stmt(db, "INSERT INTO PlayerNameToUUID(PlayerName, UUID, DateTime) VALUES (?, ?, ?)");
585  cCSLock Lock(m_CSNameToUUID);
586  for (auto & NameToUUID : m_NameToUUID)
587  {
588  auto & Profile = NameToUUID.second;
589  if (Profile.m_DateTime < LimitDateTime)
590  {
591  // This item is too old, do not save
592  continue;
593  }
594  stmt.bind(1, Profile.m_PlayerName);
595  stmt.bind(2, Profile.m_UUID.ToShortString());
596  stmt.bind(3, Profile.m_DateTime);
597  stmt.exec();
598  stmt.reset();
599  }
600  }
601 
602  // Save all cache entries - m_UUIDToProfile:
603  {
604  SQLite::Statement stmt(db, "INSERT INTO UUIDToProfile(UUID, PlayerName, Textures, TexturesSignature, DateTime) VALUES (?, ?, ?, ?, ?)");
606  for (auto & UUIDToProfile : m_UUIDToProfile)
607  {
608  auto & Profile = UUIDToProfile.second;
609  if (Profile.m_DateTime < LimitDateTime)
610  {
611  // This item is too old, do not save
612  continue;
613  }
614  stmt.bind(1, Profile.m_UUID.ToShortString());
615  stmt.bind(2, Profile.m_PlayerName);
616  stmt.bind(3, Profile.m_Textures);
617  stmt.bind(4, Profile.m_TexturesSignature);
618  stmt.bind(5, Profile.m_DateTime);
619  stmt.exec();
620  stmt.reset();
621  }
622  }
623  }
624  catch (const SQLite::Exception & ex)
625  {
626  LOGINFO("Saving MojangAPI cache failed: %s", ex.what());
627  }
628 }
629 
630 
631 
632 
633 
634 void cMojangAPI::CacheNamesToUUIDs(const AStringVector & a_PlayerNames)
635 {
636  // Create a list of names to query, by removing those that are already cached:
637  AStringVector NamesToQuery;
638  NamesToQuery.reserve(a_PlayerNames.size());
639  {
640  cCSLock Lock(m_CSNameToUUID);
641  for (AStringVector::const_iterator itr = a_PlayerNames.begin(), end = a_PlayerNames.end(); itr != end; ++itr)
642  {
643  if (m_NameToUUID.find(*itr) == m_NameToUUID.end())
644  {
645  NamesToQuery.push_back(*itr);
646  }
647  } // for itr - a_PlayerNames[]
648  } // Lock(m_CSNameToUUID)
649 
650  QueryNamesToUUIDs(NamesToQuery);
651 }
652 
653 
654 
655 
656 
658 {
659  while (!a_NamesToQuery.empty())
660  {
661  // Create the request body - a JSON containing up to MAX_PER_QUERY playernames:
662  Json::Value root;
663  int Count = 0;
664  AStringVector::iterator itr = a_NamesToQuery.begin(), end = a_NamesToQuery.end();
665  for (; (itr != end) && (Count < MAX_PER_QUERY); ++itr, ++Count)
666  {
667  Json::Value req(*itr);
668  root.append(req);
669  } // for itr - a_PlayerNames[]
670  a_NamesToQuery.erase(a_NamesToQuery.begin(), itr);
671  Json::FastWriter Writer;
672  AString RequestBody = Writer.write(root);
673 
674  // Create the HTTP request:
675  AString Request;
676  Request += "POST " + m_NameToUUIDAddress + " HTTP/1.0\r\n"; // We need to use HTTP 1.0 because we don't handle Chunked transfer encoding
677  Request += "Host: " + m_NameToUUIDServer + "\r\n";
678  Request += "User-Agent: Cuberite\r\n";
679  Request += "Connection: close\r\n";
680  Request += "Content-Type: application/json\r\n";
681  Request += Printf("Content-Length: %u\r\n", static_cast<unsigned>(RequestBody.length()));
682  Request += "\r\n";
683  Request += RequestBody;
684 
685  // Get the response from the server:
686  AString Response;
687  if (!SecureRequest(m_NameToUUIDServer, Request, Response))
688  {
689  continue;
690  }
691 
692  // Check the HTTP status line:
693  const AString Prefix("HTTP/1.1 200 OK");
694  AString HexDump;
695  if (Response.compare(0, Prefix.size(), Prefix))
696  {
697  LOGINFO("%s failed: bad HTTP status line received", __FUNCTION__);
698  LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
699  continue;
700  }
701 
702  // Erase the HTTP headers from the response:
703  size_t idxHeadersEnd = Response.find("\r\n\r\n");
704  if (idxHeadersEnd == AString::npos)
705  {
706  LOGINFO("%s failed: bad HTTP response header received", __FUNCTION__);
707  LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
708  continue;
709  }
710  Response.erase(0, idxHeadersEnd + 4);
711 
712  // Parse the returned string into Json:
713  Json::Reader reader;
714  if (!reader.parse(Response, root, false) || !root.isArray())
715  {
716  LOGWARNING("%s failed: Cannot parse received data (NameToUUID) to JSON: \"%s\"", __FUNCTION__, reader.getFormattedErrorMessages().c_str());
717  LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
718  continue;
719  }
720 
721  // Store the returned results into cache:
722  Json::Value::UInt JsonCount = root.size();
723  Int64 Now = time(nullptr);
724  {
725  cCSLock Lock(m_CSNameToUUID);
726  for (Json::Value::UInt idx = 0; idx < JsonCount; ++idx)
727  {
728  Json::Value & Val = root[idx];
729  AString JsonName = Val.get("name", "").asString();
730  cUUID JsonUUID;
731  if (!JsonUUID.FromString(Val.get("id", "").asString()))
732  {
733  continue;
734  }
735  m_NameToUUID[StrToLower(JsonName)] = sProfile(JsonName, JsonUUID, "", "", Now);
736  NotifyNameUUID(JsonName, JsonUUID);
737  } // for idx - root[]
738  } // cCSLock (m_CSNameToUUID)
739 
740  // Also cache the UUIDToName:
741  {
742  cCSLock Lock(m_CSUUIDToName);
743  for (Json::Value::UInt idx = 0; idx < JsonCount; ++idx)
744  {
745  Json::Value & Val = root[idx];
746  AString JsonName = Val.get("name", "").asString();
747  cUUID JsonUUID;
748  if (!JsonUUID.FromString(Val.get("id", "").asString()))
749  {
750  continue;
751  }
752  m_UUIDToName[JsonUUID] = sProfile(JsonName, JsonUUID, "", "", Now);
753  } // for idx - root[]
754  }
755  } // while (!NamesToQuery.empty())
756 }
757 
758 
759 
760 
761 
763 {
764  // Check if already present:
765  {
767  if (m_UUIDToProfile.find(a_UUID) != m_UUIDToProfile.end())
768  {
769  return;
770  }
771  }
772 
773  QueryUUIDToProfile(a_UUID);
774 }
775 
776 
777 
778 
779 
781 {
782  // Create the request address:
784  ReplaceString(Address, "%UUID%", a_UUID.ToShortString());
785 
786  // Create the HTTP request:
787  AString Request;
788  Request += "GET " + Address + " HTTP/1.0\r\n"; // We need to use HTTP 1.0 because we don't handle Chunked transfer encoding
789  Request += "Host: " + m_UUIDToProfileServer + "\r\n";
790  Request += "User-Agent: Cuberite\r\n";
791  Request += "Connection: close\r\n";
792  Request += "Content-Length: 0\r\n";
793  Request += "\r\n";
794 
795  // Get the response from the server:
796  AString Response;
797  if (!SecureRequest(m_UUIDToProfileServer, Request, Response))
798  {
799  return;
800  }
801 
802  // Check the HTTP status line:
803  const AString Prefix("HTTP/1.1 200 OK");
804  AString HexDump;
805  if (Response.compare(0, Prefix.size(), Prefix))
806  {
807  LOGINFO("%s failed: bad HTTP status line received", __FUNCTION__);
808  LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
809  return;
810  }
811 
812  // Erase the HTTP headers from the response:
813  size_t idxHeadersEnd = Response.find("\r\n\r\n");
814  if (idxHeadersEnd == AString::npos)
815  {
816  LOGINFO("%s failed: bad HTTP response header received", __FUNCTION__);
817  LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
818  return;
819  }
820  Response.erase(0, idxHeadersEnd + 4);
821 
822  // Parse the returned string into Json:
823  Json::Reader reader;
824  Json::Value root;
825  if (!reader.parse(Response, root, false) || !root.isObject())
826  {
827  LOGWARNING("%s failed: Cannot parse received data (NameToUUID) to JSON: \"%s\"", __FUNCTION__, reader.getFormattedErrorMessages().c_str());
828  LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
829  return;
830  }
831 
832  /* Example response:
833  {
834  "id": "b1caf24202a841a78055a079c460eee7",
835  "name": "xoft",
836  "properties":
837  [
838  {
839  "name": "textures",
840  "value": "eyJ0aW1lc3RhbXAiOjE0MDcwNzAzMjEyNzEsInByb2ZpbGVJZCI6ImIxY2FmMjQyMDJhODQxYTc4MDU1YTA3OWM0NjBlZWU3IiwicHJvZmlsZU5hbWUiOiJ4b2Z0IiwiaXNQdWJsaWMiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9iNzc5YmFiZjVhNTg3Zjk0OGFkNjc0N2VhOTEyNzU0MjliNjg4Mjk1YWUzYzA3YmQwZTJmNWJmNGQwNTIifX19",
841  "signature": "XCty+jGEF39hEPrPhYNnCX087kPaoCjYruzYI/DS4nkL5hbjnkSM5Rh15hnUyv/FHhC8OF5rif3D1tQjtMI19KSVaXoUFXpbJM8/+PB8GDgEbX8Fc3u9nYkzOcM/xfxdYsFAdFhLQMkvase/BZLSuPhdy9DdI+TCrO7xuSTZfYmmwVuWo3w5gCY+mSIAnqltnOzaOOTcly75xvO0WYpVk7nJdnR2tvSi0wfrQPDrIg/uzhX7p0SnDqijmBU4QaNez/TNKiFxy69dAzt0RSotlQzqkDbyVKhhv9a4eY8h3pXi4UMftKEj4FAKczxLImkukJXuOn5NN15/Q+le0rJVBC60/xjKIVzltEsMN6qjWD0lQjey7WEL+4pGhCVuWY5KzuZjFvgqszuJTFz7lo+bcHiceldJtea8/fa02eTRObZvdLxbWC9ZfFY0IhpOVKfcLdno/ddDMNMQMi5kMrJ8MZZ/PcW1w5n7MMGWPGCla1kOaC55AL0QYSMGRVEZqgU9wXI5M7sHGZKGM4mWxkbEJYBkpI/p3GyxWgV6v33ZWlsz65TqlNrR1gCLaoFCm7Sif8NqPBZUAONHYon0roXhin/DyEanS93WV6i6FC1Wisscjq2AcvnOlgTo/5nN/1QsMbjNumuMGo37sqjRqlXoPb8zEUbAhhztYuJjEfQ2Rd8="
842  }
843  ]
844  }
845  */
846 
847  // Store the returned result into caches:
848  AString PlayerName = root.get("name", "").asString();
849  if (PlayerName.empty())
850  {
851  // No valid playername, bail out
852  return;
853  }
854  Json::Value Properties = root.get("properties", "");
855  Int64 Now = time(nullptr);
856  {
858  m_UUIDToProfile[a_UUID] = sProfile(PlayerName, a_UUID, Properties, Now);
859  }
860  {
861  cCSLock Lock(m_CSUUIDToName);
862  m_UUIDToName[a_UUID] = sProfile(PlayerName, a_UUID, Properties, Now);
863  }
864  {
865  cCSLock Lock(m_CSNameToUUID);
866  m_NameToUUID[StrToLower(PlayerName)] = sProfile(PlayerName, a_UUID, Properties, Now);
867  }
868  NotifyNameUUID(PlayerName, a_UUID);
869 }
870 
871 
872 
873 
874 
875 void cMojangAPI::NotifyNameUUID(const AString & a_PlayerName, const cUUID & a_UUID)
876 {
877  // Notify the rank manager:
878  cCSLock Lock(m_CSRankMgr);
879  if (m_RankMgr != nullptr)
880  {
881  m_RankMgr->NotifyNameUUID(a_PlayerName, a_UUID);
882  }
883 }
884 
885 
886 
887 
888 
890 {
891  Int64 LimitDateTime = time(nullptr) - MAX_AGE;
892 
893  // Re-query all playernames that are stale:
894  AStringVector PlayerNames;
895  {
896  cCSLock Lock(m_CSNameToUUID);
897  for (const auto & NameToUUID : m_NameToUUID)
898  {
899  if (NameToUUID.second.m_DateTime < LimitDateTime)
900  {
901  PlayerNames.push_back(NameToUUID.first);
902  }
903  } // for itr - m_NameToUUID[]
904  }
905  if (!PlayerNames.empty())
906  {
907  LOG("cMojangAPI: Updating name-to-uuid cache for %u names", static_cast<unsigned>(PlayerNames.size()));
908  QueryNamesToUUIDs(PlayerNames);
909  }
910 
911  // Re-query all profiles that are stale:
912  std::vector<cUUID> ProfileUUIDs;
913  {
915  for (auto & UUIDToProfile : m_UUIDToProfile)
916  {
917  if (UUIDToProfile.second.m_DateTime < LimitDateTime)
918  {
919  ProfileUUIDs.push_back(UUIDToProfile.first);
920  }
921  } // for itr - m_UUIDToProfile[]
922  }
923  if (!ProfileUUIDs.empty())
924  {
925  LOG("cMojangAPI: Updating uuid-to-profile cache for %u uuids", static_cast<unsigned>(ProfileUUIDs.size()));
926  for (const auto & UUID : ProfileUUIDs)
927  {
928  QueryUUIDToProfile(UUID);
929  }
930  }
931 }
void QueryNamesToUUIDs(AStringVector &a_PlayerNames)
Queries all the specified names and stores them into the m_PlayerNameToUUID cache.
Definition: MojangAPI.cpp:657
AString m_UUIDToProfileAddress
The URL to use for converting UUID to profile, without the server part.
Definition: MojangAPI.h:150
void SetExpectedPeerName(AString a_ExpectedPeerName)
Sets the Expected peer name.
void SaveCachesToDisk(void)
Saves the caches to a disk storage.
Definition: MojangAPI.cpp:568
void Update(void)
Updates the stale values in the DB from the Mojang servers.
Definition: MojangAPI.cpp:889
cMojangAPI & m_MojangAPI
The cMojangAPI instance to update.
Definition: MojangAPI.cpp:255
std::vector< cUUID > GetUUIDsFromPlayerNames(const AStringVector &a_PlayerName, bool a_UseOnlyCached=false)
Converts the player names into UUIDs.
Definition: MojangAPI.cpp:380
void NotifyNameUUID(const AString &a_PlayerName, const cUUID &a_PlayerUUID)
Called for each name-uuid pairing that is discovered.
Definition: MojangAPI.cpp:875
const Int64 MAX_AGE
The maximum age for items to be kept in the cache.
Definition: MojangAPI.cpp:23
std::shared_ptr< cX509Cert > cX509CertPtr
Definition: SslConfig.h:13
#define VERIFY(x)
Definition: Globals.h:339
AString ToShortString() const
Converts the UUID to a short form string (i.e without dashes).
Definition: UUID.cpp:133
void AddPlayerNameToUUIDMapping(const AString &a_PlayerName, const cUUID &a_UUID)
Called by the Authenticator to add a PlayerName -> UUID mapping that it has received from authenticat...
Definition: MojangAPI.cpp:415
Definition: Event.h:17
bool FromString(const AString &a_StringUUID)
Tries to interpret the string as a short or long form UUID and assign from it.
Definition: UUID.cpp:102
Holds data for a single player profile.
Definition: MojangAPI.h:92
cRankManager * m_RankMgr
The rank manager that is notified of the name-uuid pairings.
Definition: MojangAPI.h:172
cCriticalSection m_CSNameToUUID
Protects m_NameToUUID against simultaneous multi-threaded access.
Definition: MojangAPI.h:156
void Start(cSettingsRepositoryInterface &a_Settings, bool a_ShouldAuth)
Initializes the API; reads the settings from the specified ini file.
Definition: MojangAPI.cpp:301
void CacheNamesToUUIDs(const AStringVector &a_PlayerNames)
Makes sure all specified names are in the m_PlayerNameToUUID cache.
Definition: MojangAPI.cpp:634
cCriticalSection m_CSUUIDToName
Protects m_UUIDToName against simultaneous multi-threaded access.
Definition: MojangAPI.h:162
AString m_UUIDToProfileServer
The server to connect to when converting UUID to profile.
Definition: MojangAPI.h:146
virtual ~cUpdateThread() override
Definition: MojangAPI.cpp:242
void NotifyNameUUID(const AString &a_PlayerName, const cUUID &a_UUID)
Called by cMojangAPI whenever the playername-uuid pairing is discovered.
void ReplaceString(AString &iHayStack, const AString &iNeedle, const AString &iReplaceWith)
Replaces each occurence of iNeedle in iHayStack with iReplaceWith.
AString m_NameToUUIDServer
The server to connect to when converting player names to UUIDs.
Definition: MojangAPI.h:139
void AddPlayerProfile(const AString &a_PlayerName, const cUUID &a_UUID, const Json::Value &a_Properties)
Called by the Authenticator to add a profile that it has received from authenticating a user...
Definition: MojangAPI.cpp:433
void SetSslConfig(std::shared_ptr< const cSslConfig > a_Config)
Set the config to be used by the SSL context.
cEvent m_evtNotify
The event used for notifying that the thread should terminate, as well as timing. ...
Definition: MojangAPI.cpp:258
sProfile(void)
Default constructor for the container&#39;s sake.
Definition: MojangAPI.h:101
static std::shared_ptr< cSslConfig > MakeDefaultConfig(bool a_IsClient)
Creates a new config with some sensible defaults on top of mbedTLS basic settings.
Definition: SslConfig.cpp:226
Definition: UUID.h:10
#define DEFAULT_UUID_TO_PROFILE_ADDRESS
Definition: MojangAPI.cpp:35
std::vector< AString > AStringVector
Definition: StringUtils.h:14
cUpdateThread(cMojangAPI &a_MojangAPI)
Definition: MojangAPI.cpp:236
static bool SecureRequest(const AString &a_ServerName, const AString &a_Request, AString &a_Response)
Connects to the specified server using SSL, sends the given request and receives the response...
Definition: MojangAPI.cpp:455
AString GetPlayerNameFromUUID(const cUUID &a_UUID, bool a_UseOnlyCached=false)
Converts a UUID into a playername.
Definition: MojangAPI.cpp:345
void Wait(void)
Waits until the event has been set.
Definition: Event.cpp:24
static cX509CertPtr GetCACerts(void)
Returns the CA certificates that should be trusted for Mojang-related connections.
Definition: MojangAPI.cpp:42
AString m_NameToUUIDAddress
The URL to use for converting player names to UUIDs, without server part.
Definition: MojangAPI.h:143
const AString & GetLastErrorText(void) const
Returns the text of the last error that has occurred in this instance.
void LOGINFO(const char *a_Format, fmt::ArgList a_ArgList)
Definition: Logger.cpp:165
AString & Printf(AString &str, const char *format, fmt::ArgList args)
Output the formatted text into the string.
Definition: StringUtils.cpp:55
#define DEFAULT_NAME_TO_UUID_SERVER
Definition: MojangAPI.cpp:32
void LOGWARNING(const char *a_Format, fmt::ArgList a_ArgList)
Definition: Logger.cpp:174
#define LOGD(...)
Definition: LoggerSimple.h:40
cMojangAPI(void)
Definition: MojangAPI.cpp:278
virtual AString GetValueSet(const AString &keyname, const AString &valuename, const AString &defValue="")=0
Gets the value; if not found, write the default to the repository.
cUUIDProfileMap m_UUIDToProfile
Cache for the UUID-to-profile lookups.
Definition: MojangAPI.h:166
cUUIDProfileMap m_UUIDToName
Cache for the Name-to-UUID lookups.
Definition: MojangAPI.h:159
void QueryUUIDToProfile(const cUUID &a_UUID)
Queries the specified UUID&#39;s profile and stores it in the m_UUIDToProfile cache.
Definition: MojangAPI.cpp:780
cUUID GetUUIDFromPlayerName(const AString &a_PlayerName, bool a_UseOnlyCached=false)
Converts a player name into a UUID.
Definition: MojangAPI.cpp:318
std::shared_ptr< cUpdateThread > m_UpdateThread
The thread that periodically updates the stale data in the DB from the Mojang servers.
Definition: MojangAPI.h:178
cCriticalSection m_CSUUIDToProfile
Protects m_UUIDToProfile against simultaneous multi-threaded access.
Definition: MojangAPI.h:169
std::string AString
Definition: StringUtils.h:13
void LoadCachesFromDisk(void)
Loads the caches from a disk storage.
Definition: MojangAPI.cpp:510
void LOG(const char *a_Format, fmt::ArgList a_ArgList)
Definition: Logger.cpp:156
AString & CreateHexDump(AString &a_Out, const void *a_Data, size_t a_Size, size_t a_BytesPerLine)
format binary data this way: 00001234: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 1234567890abcd...
static std::shared_ptr< const cSslConfig > GetSslConfig()
Returns the config to be used for secure requests.
Definition: MojangAPI.cpp:160
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.
#define DEFAULT_UUID_TO_PROFILE_SERVER
Definition: MojangAPI.cpp:34
#define DEFAULT_NAME_TO_UUID_ADDRESS
Definition: MojangAPI.cpp:33
bool Connect(const AString &a_ServerName, UInt16 a_Port)
Connects to the specified server and performs SSL handshake.
void CacheUUIDToProfile(const cUUID &a_UUID)
Makes sure the specified UUID is in the m_UUIDToProfile cache.
Definition: MojangAPI.cpp:762
int Receive(void *a_Data, size_t a_MaxBytes)
Receives data from the connection.
virtual void Execute(void) override
This is the main thread entrypoint.
Definition: MojangAPI.cpp:262
AString StrToLower(const AString &s)
Returns a lower-cased copy of the string.
const int MAX_PER_QUERY
The maximum number of names to send in a single query.
Definition: MojangAPI.cpp:26
signed long long Int64
Definition: Globals.h:107
cProfileMap m_NameToUUID
Cache for the Name-to-UUID lookups.
Definition: MojangAPI.h:153
cCriticalSection m_CSRankMgr
Protects m_RankMgr agains simultaneous multi-threaded access.
Definition: MojangAPI.h:175
AString m_TexturesSignature
Definition: MojangAPI.h:97
bool Send(const void *a_Data, size_t a_NumBytes)
Sends the specified data over the connection.