diff options
author | Mattes D <github@xoft.cz> | 2014-08-01 22:35:12 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2014-08-01 22:35:12 +0200 |
commit | 941a182d8a8a210bb6400cc6b2750a06b5f6c038 (patch) | |
tree | 82dfee0f38536020345a820c84ff2c4f01c3213b /src/Bindings | |
parent | Merge pull request #1273 from Howaner/GlobalFixes (diff) | |
parent | Merged branch 'master' into NameToUUID. (diff) | |
download | cuberite-941a182d8a8a210bb6400cc6b2750a06b5f6c038.tar cuberite-941a182d8a8a210bb6400cc6b2750a06b5f6c038.tar.gz cuberite-941a182d8a8a210bb6400cc6b2750a06b5f6c038.tar.bz2 cuberite-941a182d8a8a210bb6400cc6b2750a06b5f6c038.tar.lz cuberite-941a182d8a8a210bb6400cc6b2750a06b5f6c038.tar.xz cuberite-941a182d8a8a210bb6400cc6b2750a06b5f6c038.tar.zst cuberite-941a182d8a8a210bb6400cc6b2750a06b5f6c038.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Bindings/AllToLua.pkg | 1 | ||||
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 71 |
2 files changed, 72 insertions, 0 deletions
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 621358662..88faa9dfc 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -78,6 +78,7 @@ $cfile "../Map.h" $cfile "../MapManager.h" $cfile "../Scoreboard.h" $cfile "../Statistics.h" +$cfile "../Protocol/MojangAPI.h" diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 460d879d5..34f0d7e30 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -27,6 +27,7 @@ #include "../BlockEntities/MobHeadEntity.h" #include "../BlockEntities/FlowerPotEntity.h" #include "../LineBlockTracer.h" +#include "../Protocol/Authenticator.h" #include "../WorldStorage/SchematicFileSerializer.h" #include "../CompositeChat.h" @@ -2157,6 +2158,72 @@ static int tolua_cClientHandle_SendPluginMessage(lua_State * L) +static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L) +{ + cLuaState S(L); + if ( + !S.CheckParamUserTable(1, "cMojangAPI") || + !S.CheckParamTable(2) || + !S.CheckParamEnd(4) + ) + { + return 0; + } + + // Convert the input table into AStringVector: + AStringVector PlayerNames; + int NumNames = luaL_getn(L, 2); + PlayerNames.reserve(NumNames); + for (int i = 1; i <= NumNames; i++) + { + lua_rawgeti(L, 2, i); + AString Name; + S.GetStackValue(-1, Name); + if (!Name.empty()) + { + PlayerNames.push_back(Name); + } + lua_pop(L, 1); + } + + // If the UseOnlyCached param was given, read it; default to false + bool ShouldUseCacheOnly = false; + if (lua_gettop(L) == 3) + { + ShouldUseCacheOnly = (lua_toboolean(L, 3) != 0); + lua_pop(L, 1); + } + + // Push the output table onto the stack: + lua_newtable(L); + + // Get the UUIDs: + AStringVector UUIDs = cRoot::Get()->GetMojangAPI().GetUUIDsFromPlayerNames(PlayerNames, ShouldUseCacheOnly); + if (UUIDs.size() != PlayerNames.size()) + { + // A hard error has occured while processing the request, no UUIDs were returned. Return an empty table: + return 1; + } + + // Convert to output table, PlayerName -> UUID: + size_t len = UUIDs.size(); + for (size_t i = 0; i < len; i++) + { + if (UUIDs[i].empty()) + { + // No UUID was provided for PlayerName[i], skip it in the resulting table + continue; + } + lua_pushlstring(L, UUIDs[i].c_str(), UUIDs[i].length()); + lua_setfield(L, 3, PlayerNames[i].c_str()); + } + return 1; +} + + + + + static int Lua_ItemGrid_GetSlotCoords(lua_State * L) { tolua_Error tolua_err; @@ -3090,6 +3157,10 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage); tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cMojangAPI"); + tolua_function(tolua_S, "GetUUIDsFromPlayerNames", tolua_cMojangAPI_GetUUIDsFromPlayerNames); + tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cItemGrid"); tolua_function(tolua_S, "GetSlotCoords", Lua_ItemGrid_GetSlotCoords); tolua_endmodule(tolua_S); |