summaryrefslogtreecommitdiffstats
path: root/src/Protocol/MojangAPI.h
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2017-08-27 08:13:40 +0200
committerLogicParrot <LogicParrot@users.noreply.github.com>2017-08-27 08:13:40 +0200
commite274d0dd8a6eefeb6e84272ffd09ac55b2c08900 (patch)
tree377f52ed5738810c157e631ec31f626fbe5acef6 /src/Protocol/MojangAPI.h
parentd (diff)
parentImplement anvil chunk sparsing (diff)
downloadcuberite-e274d0dd8a6eefeb6e84272ffd09ac55b2c08900.tar
cuberite-e274d0dd8a6eefeb6e84272ffd09ac55b2c08900.tar.gz
cuberite-e274d0dd8a6eefeb6e84272ffd09ac55b2c08900.tar.bz2
cuberite-e274d0dd8a6eefeb6e84272ffd09ac55b2c08900.tar.lz
cuberite-e274d0dd8a6eefeb6e84272ffd09ac55b2c08900.tar.xz
cuberite-e274d0dd8a6eefeb6e84272ffd09ac55b2c08900.tar.zst
cuberite-e274d0dd8a6eefeb6e84272ffd09ac55b2c08900.zip
Diffstat (limited to 'src/Protocol/MojangAPI.h')
-rw-r--r--src/Protocol/MojangAPI.h50
1 files changed, 20 insertions, 30 deletions
diff --git a/src/Protocol/MojangAPI.h b/src/Protocol/MojangAPI.h
index 3cd0376be..4d1751f1c 100644
--- a/src/Protocol/MojangAPI.h
+++ b/src/Protocol/MojangAPI.h
@@ -11,6 +11,8 @@
#include <time.h>
+#include "../UUID.h"
+
@@ -45,49 +47,38 @@ public:
Returns true if all was successful, false on failure. */
static bool SecureRequest(const AString & a_ServerName, const AString & a_Request, AString & a_Response);
- /** Normalizes the given UUID to its short form (32 bytes, no dashes, lowercase).
- Logs a warning and returns empty string if not a UUID.
- Note: only checks the string's length, not the actual content. */
- static AString MakeUUIDShort(const AString & a_UUID);
-
- /** Normalizes the given UUID to its dashed form (36 bytes, 4 dashes, lowercase).
- Logs a warning and returns empty string if not a UUID.
- Note: only checks the string's length, not the actual content. */
- static AString MakeUUIDDashed(const AString & a_UUID);
-
/** Converts a player name into a UUID.
- The UUID will be empty on error.
+ The UUID will be nil on error.
If a_UseOnlyCached is true, the function only consults the cached values.
If a_UseOnlyCached is false and the name is not found in the cache, it is looked up online, which is a blocking
operation, do not use this in world-tick thread!
If you have multiple names to resolve, use the GetUUIDsFromPlayerNames() function, it uses a single request for multiple names. */
- AString GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_UseOnlyCached = false);
+ cUUID GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_UseOnlyCached = false);
/** Converts a UUID into a playername.
The returned playername will be empty on error.
- Both short and dashed UUID formats are accepted.
Uses both m_UUIDToName and m_UUIDToProfile to search for the value. Uses m_UUIDToProfile for cache.
If a_UseOnlyCached is true, the function only consults the cached values.
If a_UseOnlyCached is false and the name is not found in the cache, it is looked up online, which is a blocking
operation, do not use this in world-tick thread! */
- AString GetPlayerNameFromUUID(const AString & a_UUID, bool a_UseOnlyCached = false);
+ AString GetPlayerNameFromUUID(const cUUID & a_UUID, bool a_UseOnlyCached = false);
/** Converts the player names into UUIDs.
a_PlayerName[idx] will be converted to UUID and returned as idx-th value
- The UUID will be empty on error.
+ The UUID will be nil on error.
If a_UseOnlyCached is true, only the cached values are returned.
If a_UseOnlyCached is false, the names not found in the cache are looked up online, which is a blocking
operation, do not use this in world-tick thread! */
- AStringVector GetUUIDsFromPlayerNames(const AStringVector & a_PlayerName, bool a_UseOnlyCached = false);
+ std::vector<cUUID> GetUUIDsFromPlayerNames(const AStringVector & a_PlayerName, bool a_UseOnlyCached = false);
/** Called by the Authenticator to add a PlayerName -> UUID mapping that it has received from
authenticating a user. This adds the cache item and "refreshes" it if existing, adjusting its datetime
stamp to now. */
- void AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const AString & a_UUID);
+ void AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const cUUID & a_UUID);
/** Called by the Authenticator to add a profile that it has received from authenticating a user. Adds
the profile to the respective mapping caches and updtes their datetime stamp to now. */
- void AddPlayerProfile(const AString & a_PlayerName, const AString & a_UUID, const Json::Value & a_Properties);
+ void AddPlayerProfile(const AString & a_PlayerName, const cUUID & a_UUID, const Json::Value & a_Properties);
/** Sets the m_RankMgr that is used for name-uuid notifications. Accepts nullptr to remove the binding. */
void SetRankManager(cRankManager * a_RankManager) { m_RankMgr = a_RankManager; }
@@ -101,7 +92,7 @@ protected:
struct sProfile
{
AString m_PlayerName; // Case-correct playername
- AString m_UUID; // Short lowercased UUID
+ cUUID m_UUID; // Player UUID
AString m_Textures; // The Textures field of the profile properties
AString m_TexturesSignature; // The signature of the Textures field of the profile properties
Int64 m_DateTime; // UNIXtime of the profile lookup
@@ -119,7 +110,7 @@ protected:
/** Constructor for the storage creation. */
sProfile(
const AString & a_PlayerName,
- const AString & a_UUID,
+ const cUUID & a_UUID,
const AString & a_Textures,
const AString & a_TexturesSignature,
Int64 a_DateTime
@@ -135,12 +126,13 @@ protected:
/** Constructor that parses the values from the Json profile. */
sProfile(
const AString & a_PlayerName,
- const AString & a_UUID,
+ const cUUID & a_UUID,
const Json::Value & a_Properties,
Int64 a_DateTime
);
};
typedef std::map<AString, sProfile> cProfileMap;
+ typedef std::map<cUUID, sProfile> cUUIDProfileMap;
/** The server to connect to when converting player names to UUIDs. For example "api.mojang.com". */
@@ -164,14 +156,14 @@ protected:
cCriticalSection m_CSNameToUUID;
/** Cache for the Name-to-UUID lookups. The map key is lowercased short UUID. Protected by m_CSUUIDToName. */
- cProfileMap m_UUIDToName;
+ cUUIDProfileMap m_UUIDToName;
/** Protects m_UUIDToName against simultaneous multi-threaded access. */
cCriticalSection m_CSUUIDToName;
/** Cache for the UUID-to-profile lookups. The map key is lowercased short UUID.
Protected by m_CSUUIDToProfile. */
- cProfileMap m_UUIDToProfile;
+ cUUIDProfileMap m_UUIDToProfile;
/** Protects m_UUIDToProfile against simultaneous multi-threaded access. */
cCriticalSection m_CSUUIDToProfile;
@@ -204,18 +196,16 @@ protected:
void QueryNamesToUUIDs(AStringVector & a_PlayerNames);
/** Makes sure the specified UUID is in the m_UUIDToProfile cache. If missing, downloads it from Mojang API servers.
- UUIDs that are not valid will not be added into the cache.
- ASSUMEs that a_UUID is a lowercased short UUID. */
- void CacheUUIDToProfile(const AString & a_UUID);
+ UUIDs that are not valid will not be added into the cache. */
+ void CacheUUIDToProfile(const cUUID & a_UUID);
/** Queries the specified UUID's profile and stores it in the m_UUIDToProfile cache. If already present, updates the cache entry.
- UUIDs that are not valid will not be added into the cache.
- ASSUMEs that a_UUID is a lowercased short UUID. */
- void QueryUUIDToProfile(const AString & a_UUID);
+ UUIDs that are not valid will not be added into the cache. */
+ void QueryUUIDToProfile(const cUUID & a_UUID);
/** Called for each name-uuid pairing that is discovered.
If assigned, notifies the m_RankManager of the event. */
- void NotifyNameUUID(const AString & a_PlayerName, const AString & a_PlayerUUID);
+ void NotifyNameUUID(const AString & a_PlayerName, const cUUID & a_PlayerUUID);
/** Updates the stale values in the DB from the Mojang servers. Called from the cUpdateThread, blocks on the HTTPS API calls. */
void Update(void);