summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-08-03 12:12:28 +0200
committermadmaxoft <github@xoft.cz>2014-08-03 22:04:50 +0200
commit003f18bd0f7593bddf5c6af89e3f6fc13632300d (patch)
treea485b0c959ec99cf9e956d9774f6a5b3aa10263f
parentToLua driver: disabled output buffering. (diff)
downloadcuberite-003f18bd0f7593bddf5c6af89e3f6fc13632300d.tar
cuberite-003f18bd0f7593bddf5c6af89e3f6fc13632300d.tar.gz
cuberite-003f18bd0f7593bddf5c6af89e3f6fc13632300d.tar.bz2
cuberite-003f18bd0f7593bddf5c6af89e3f6fc13632300d.tar.lz
cuberite-003f18bd0f7593bddf5c6af89e3f6fc13632300d.tar.xz
cuberite-003f18bd0f7593bddf5c6af89e3f6fc13632300d.tar.zst
cuberite-003f18bd0f7593bddf5c6af89e3f6fc13632300d.zip
-rw-r--r--MCServer/Plugins/APIDump/APIDesc.lua1
-rw-r--r--src/Protocol/MojangAPI.cpp28
-rw-r--r--src/Protocol/MojangAPI.h7
3 files changed, 36 insertions, 0 deletions
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 1fa2608b3..4f8567530 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -1630,6 +1630,7 @@ a_Player:OpenWindow(Window);
Functions =
{
AddPlayerNameToUUIDMapping = { Params = "PlayerName, UUID", Return = "", Notes = "Adds the specified PlayerName-to-UUID mapping into the cache, with current timestamp." },
+ GetUUIDFromPlayerName = { Params = "PlayerName, [UseOnlyCached]", Return = "UUID", Notes = "Returns the UUID that corresponds to the given playername, or an empty string on error. If UseOnlyCached is false (the default), queries the Mojang servers if the playername is not in the cache. <br /><b>WARNING</b>: Do NOT use this function with UseOnlyCached set to false while the server is running. Only use it when the server is starting up (inside the Initialize() method), otherwise you will lag the server severely." },
GetUUIDsFromPlayerNames = { Params = "PlayerNames, [UseOnlyCached]", Return = "table", Notes = "Returns a table that contains the map, 'PlayerName' -> 'UUID', for all valid playernames in the input array-table. PlayerNames not recognized will not be set in the returned map. If UseOnlyCached is false (the default), queries the Mojang servers for the results that are not in the cache. <br /><b>WARNING</b>: Do NOT use this function with UseOnlyCached set to false while the server is running. Only use it when the server is starting up (inside the Initialize() method), otherwise you will lag the server severely." },
MakeUUIDDashed = { Params = "UUID", Return = "DashedUUID", Notes = "(STATIC) Converts the UUID to a dashed format (\"01234567-8901-2345-6789-012345678901\"). Accepts both dashed and short UUIDs. Logs a warning and returns an empty string if UUID format not recognized." },
MakeUUIDShort = { Params = "UUID", Return = "ShortUUID", Notes = "(STATIC) Converts the UUID to a short format (without dashes, \"01234567890123456789012345678901\"). Accepts both dashed and short UUIDs. Logs a warning and returns an empty string if UUID format not recognized." },
diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp
index 45baa5a4f..f53df1cba 100644
--- a/src/Protocol/MojangAPI.cpp
+++ b/src/Protocol/MojangAPI.cpp
@@ -129,6 +129,34 @@ void cMojangAPI::Start(cIniFile & a_SettingsIni)
+AString cMojangAPI::GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_UseOnlyCached)
+{
+ // Convert the playername to lowercase:
+ AString lcPlayerName(a_PlayerName);
+ StrToLower(lcPlayerName);
+
+ // Request the cache to populate any names not yet contained:
+ if (!a_UseOnlyCached)
+ {
+ AStringVector PlayerNames;
+ PlayerNames.push_back(lcPlayerName);
+ CacheNamesToUUIDs(PlayerNames);
+ }
+
+ // Retrieve from cache:
+ cNameToUUIDMap::const_iterator itr = m_NameToUUID.find(lcPlayerName);
+ if (itr == m_NameToUUID.end())
+ {
+ // No UUID found
+ return "";
+ }
+ return itr->second.m_PlayerName;
+}
+
+
+
+
+
AStringVector cMojangAPI::GetUUIDsFromPlayerNames(const AStringVector & a_PlayerNames, bool a_UseOnlyCached)
{
// Convert all playernames to lowercase:
diff --git a/src/Protocol/MojangAPI.h b/src/Protocol/MojangAPI.h
index ac8995bb5..7f3ef4e39 100644
--- a/src/Protocol/MojangAPI.h
+++ b/src/Protocol/MojangAPI.h
@@ -45,6 +45,13 @@ public:
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.
+ 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 GetUUIDFromPlayerName(const AString & a_PlayerName, bool a_UseOnlyCached = false);
+
// tolua_end
/** Converts the player names into UUIDs.