AString cMojangAPI::GetPlayerNameFromUUID(const AString & a_UUID, bool a_UseOnlyCached) { // Normalize the UUID to lowercase short format that is used as the map key: AString UUID = MakeUUIDShort(a_UUID); // Retrieve from caches: { cCSLock Lock(m_CSUUIDToProfile); cProfileMap::const_iterator itr = m_UUIDToProfile.find(UUID); if (itr != m_UUIDToProfile.end()) { return itr->second.m_PlayerName; } } { cCSLock Lock(m_CSUUIDToName); cProfileMap::const_iterator itr = m_UUIDToName.find(UUID); if (itr != m_UUIDToName.end()) { return itr->second.m_PlayerName; } } // Name not yet cached, request cache and retry: if (!a_UseOnlyCached) { CacheUUIDToProfile(UUID); return GetPlayerNameFromUUID(a_UUID, true); } // No value found, none queried. Return an error: return ""; }
AString cMojangAPI::GetPlayerNameFromUUID(const cUUID & a_UUID, bool a_UseOnlyCached) { // Retrieve from caches: { cCSLock Lock(m_CSUUIDToProfile); auto itr = m_UUIDToProfile.find(a_UUID); if (itr != m_UUIDToProfile.end()) { return itr->second.m_PlayerName; } } { cCSLock Lock(m_CSUUIDToName); auto itr = m_UUIDToName.find(a_UUID); if (itr != m_UUIDToName.end()) { return itr->second.m_PlayerName; } } // Name not yet cached, request cache and retry: if (!a_UseOnlyCached) { CacheUUIDToProfile(a_UUID); return GetPlayerNameFromUUID(a_UUID, true); } // No value found, none queried. Return an error: return {}; }