Cuberite
A lightweight, fast and extensible game server for Minecraft
|
#include <MojangAPI.h>
Classes | |
class | cUpdateThread |
struct | sProfile |
Holds data for a single player profile. More... | |
Public Member Functions | |
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 authenticating a user. More... | |
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. More... | |
cMojangAPI (void) | |
AString | GetPlayerNameFromUUID (const cUUID &a_UUID, bool a_UseOnlyCached=false) |
Converts a UUID into a playername. More... | |
cUUID | GetUUIDFromPlayerName (const AString &a_PlayerName, bool a_UseOnlyCached=false) |
Converts a player name into a UUID. More... | |
std::vector< cUUID > | GetUUIDsFromPlayerNames (const AStringVector &a_PlayerName, bool a_UseOnlyCached=false) |
Converts the player names into UUIDs. More... | |
void | SetRankManager (cRankManager *a_RankManager) |
Sets the m_RankMgr that is used for name-uuid notifications. More... | |
void | Start (cSettingsRepositoryInterface &a_Settings, bool a_ShouldAuth) |
Initializes the API; reads the settings from the specified ini file. More... | |
~cMojangAPI () | |
Protected Types | |
using | cProfileMap = std::map< AString, sProfile > |
using | cUUIDProfileMap = std::map< cUUID, sProfile > |
Protected Member Functions | |
void | CacheNamesToUUIDs (const AStringVector &a_PlayerNames) |
Makes sure all specified names are in the m_PlayerNameToUUID cache. More... | |
void | CacheUUIDToProfile (const cUUID &a_UUID) |
Makes sure the specified UUID is in the m_UUIDToProfile cache. More... | |
void | LoadCachesFromDisk (void) |
Loads the caches from a disk storage. More... | |
void | NotifyNameUUID (const AString &a_PlayerName, const cUUID &a_PlayerUUID) |
Called for each name-uuid pairing that is discovered. More... | |
void | QueryNamesToUUIDs (AStringVector &a_PlayerNames) |
Queries all the specified names and stores them into the m_PlayerNameToUUID cache. More... | |
void | QueryUUIDToProfile (const cUUID &a_UUID) |
Queries the specified UUID's profile and stores it in the m_UUIDToProfile cache. More... | |
void | SaveCachesToDisk (void) |
Saves the caches to a disk storage. More... | |
void | Update (void) |
Updates the stale values in the DB from the Mojang servers. More... | |
Protected Attributes | |
cCriticalSection | m_CSNameToUUID |
Protects m_NameToUUID against simultaneous multi-threaded access. More... | |
cCriticalSection | m_CSRankMgr |
Protects m_RankMgr agains simultaneous multi-threaded access. More... | |
cCriticalSection | m_CSUUIDToName |
Protects m_UUIDToName against simultaneous multi-threaded access. More... | |
cCriticalSection | m_CSUUIDToProfile |
Protects m_UUIDToProfile against simultaneous multi-threaded access. More... | |
cProfileMap | m_NameToUUID |
Cache for the Name-to-UUID lookups. More... | |
AString | m_NameToUUIDUrl |
The full URL to check when converting player names to UUIDs. More... | |
cRankManager * | m_RankMgr |
The rank manager that is notified of the name-uuid pairings. More... | |
std::shared_ptr< cUpdateThread > | m_UpdateThread |
The thread that periodically updates the stale data in the DB from the Mojang servers. More... | |
cUUIDProfileMap | m_UUIDToName |
Cache for the Name-to-UUID lookups. More... | |
cUUIDProfileMap | m_UUIDToProfile |
Cache for the UUID-to-profile lookups. More... | |
AString | m_UUIDToProfileUrl |
The full URL to use for converting UUID to profile. More... | |
Definition at line 33 of file MojangAPI.h.
|
protected |
Definition at line 129 of file MojangAPI.h.
|
protected |
Definition at line 130 of file MojangAPI.h.
cMojangAPI::cMojangAPI | ( | void | ) |
Definition at line 216 of file MojangAPI.cpp.
cMojangAPI::~cMojangAPI | ( | ) |
Definition at line 226 of file MojangAPI.cpp.
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.
Definition at line 351 of file MojangAPI.cpp.
void cMojangAPI::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.
Adds the profile to the respective mapping caches and updtes their datetime stamp to now.
Definition at line 369 of file MojangAPI.cpp.
|
protected |
Makes sure all specified names are in the m_PlayerNameToUUID cache.
Downloads any missing ones from Mojang API servers. Names that are not valid are not added into the cache. ASSUMEs that a_PlayerNames contains lowercased player names.
Definition at line 515 of file MojangAPI.cpp.
|
protected |
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.
Definition at line 613 of file MojangAPI.cpp.
Converts a UUID into a playername.
The returned playername will be empty on error. 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!
Definition at line 281 of file MojangAPI.cpp.
cUUID cMojangAPI::GetUUIDFromPlayerName | ( | const AString & | a_PlayerName, |
bool | a_UseOnlyCached = false |
||
) |
Converts a player name into a UUID.
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.
Definition at line 254 of file MojangAPI.cpp.
std::vector< cUUID > cMojangAPI::GetUUIDsFromPlayerNames | ( | const AStringVector & | a_PlayerName, |
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 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!
Definition at line 316 of file MojangAPI.cpp.
|
protected |
Loads the caches from a disk storage.
Definition at line 391 of file MojangAPI.cpp.
|
protected |
Called for each name-uuid pairing that is discovered.
If assigned, notifies the m_RankManager of the event.
Definition at line 698 of file MojangAPI.cpp.
|
protected |
Queries all the specified names and stores them into the m_PlayerNameToUUID cache.
Names that are not valid are not added into the cache. ASSUMEs that a_PlayerNames contans lowercased player names. For performance reasons takes a non-const reference and modifies the list given to it, until empty.
Definition at line 538 of file MojangAPI.cpp.
|
protected |
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.
Definition at line 631 of file MojangAPI.cpp.
|
protected |
Saves the caches to a disk storage.
Definition at line 449 of file MojangAPI.cpp.
|
inline |
Sets the m_RankMgr that is used for name-uuid notifications.
Accepts nullptr to remove the binding.
Definition at line 79 of file MojangAPI.h.
void cMojangAPI::Start | ( | cSettingsRepositoryInterface & | a_Settings, |
bool | a_ShouldAuth | ||
) |
Initializes the API; reads the settings from the specified ini file.
Loads cached results from disk.
Definition at line 235 of file MojangAPI.cpp.
|
protected |
Updates the stale values in the DB from the Mojang servers.
Called from the cUpdateThread, blocks on the HTTPS API calls.
Definition at line 712 of file MojangAPI.cpp.
|
protected |
Protects m_NameToUUID against simultaneous multi-threaded access.
Definition at line 146 of file MojangAPI.h.
|
protected |
Protects m_RankMgr agains simultaneous multi-threaded access.
Definition at line 165 of file MojangAPI.h.
|
protected |
Protects m_UUIDToName against simultaneous multi-threaded access.
Definition at line 152 of file MojangAPI.h.
|
protected |
Protects m_UUIDToProfile against simultaneous multi-threaded access.
Definition at line 159 of file MojangAPI.h.
|
protected |
Cache for the Name-to-UUID lookups.
The map key is lowercased PlayerName. Protected by m_CSNameToUUID.
Definition at line 143 of file MojangAPI.h.
|
protected |
The full URL to check when converting player names to UUIDs.
For example: "https://api.mojang.com/profiles/page/1".
Definition at line 135 of file MojangAPI.h.
|
protected |
The rank manager that is notified of the name-uuid pairings.
May be nullptr. Protected by m_CSRankMgr.
Definition at line 162 of file MojangAPI.h.
|
protected |
The thread that periodically updates the stale data in the DB from the Mojang servers.
Definition at line 168 of file MojangAPI.h.
|
protected |
Cache for the Name-to-UUID lookups.
The map key is lowercased short UUID. Protected by m_CSUUIDToName.
Definition at line 149 of file MojangAPI.h.
|
protected |
Cache for the UUID-to-profile lookups.
The map key is lowercased short UUID. Protected by m_CSUUIDToProfile.
Definition at line 156 of file MojangAPI.h.
|
protected |
The full URL to use for converting UUID to profile.
UUID% will get replaced with the actual UUID. For example "https://sessionserver.mojang.com/session/minecraft/profile/%UUID%?unsigned=false".
Definition at line 140 of file MojangAPI.h.