diff options
author | Samuel Barney <sbarney@instructure.com> | 2016-07-18 22:39:11 +0200 |
---|---|---|
committer | Samuel Barney <samjbarney@gmail.com> | 2016-08-15 19:13:03 +0200 |
commit | 24e89bbb2c656224d06aed084b952bbc885e3914 (patch) | |
tree | ba75a68cce6ea868acba60ae08efeeccf003736d /src/Bindings | |
parent | Switch out long download/compile links. (#3278) (diff) | |
download | cuberite-ChannelManagement.tar cuberite-ChannelManagement.tar.gz cuberite-ChannelManagement.tar.bz2 cuberite-ChannelManagement.tar.lz cuberite-ChannelManagement.tar.xz cuberite-ChannelManagement.tar.zst cuberite-ChannelManagement.zip |
Diffstat (limited to 'src/Bindings')
-rw-r--r-- | src/Bindings/AllToLua.pkg | 5 | ||||
-rw-r--r-- | src/Bindings/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Bindings/LuaState.cpp | 36 | ||||
-rw-r--r-- | src/Bindings/LuaState.h | 3 | ||||
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 597 | ||||
-rw-r--r-- | src/Bindings/Plugin.h | 9 | ||||
-rw-r--r-- | src/Bindings/PluginLua.cpp | 10 | ||||
-rw-r--r-- | src/Bindings/PluginLua.h | 6 | ||||
-rw-r--r-- | src/Bindings/PluginManager.cpp | 10 | ||||
-rw-r--r-- | src/Bindings/PluginManager.h | 3 |
10 files changed, 660 insertions, 21 deletions
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 6ca9c8658..1e8c797be 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -42,10 +42,12 @@ $cfile "LuaWindow.h" $cfile "../BlockID.h" $cfile "../BlockInfo.h" +$cfile "../ByteBuffer.h" $cfile "../StringUtils.h" $cfile "../Defines.h" $cfile "../ChatColor.h" $cfile "../ClientHandle.h" +$cfile "../ChannelManager.h" $cfile "../Server.h" $cfile "../World.h" $cfile "../Inventory.h" @@ -125,6 +127,3 @@ typedef unsigned char Byte; $renaming Vector3<double> @ Vector3d $renaming Vector3<float> @ Vector3f $renaming Vector3<int> @ Vector3i - - - diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt index 640fd60fa..e9adde150 100644 --- a/src/Bindings/CMakeLists.txt +++ b/src/Bindings/CMakeLists.txt @@ -84,6 +84,8 @@ set(BINDING_DEPENDENCIES ../BlockID.h ../BlockInfo.h ../BoundingBox.h + ../ByteBuffer.h + ../ChannelManager.h ../ChatColor.h ../ChunkDef.h ../ClientHandle.h diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 5e6c24365..75e667821 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -798,6 +798,18 @@ void cLuaState::Push(const Vector3i * a_Vector) +void cLuaState::Push(const cByteBuffer & a_Buffer) +{ + ASSERT(IsValid()); + + tolua_pushusertype(m_LuaState, reinterpret_cast<void *>(const_cast<cByteBuffer *>(&a_Buffer)), "cByteBuffer"); + m_NumCurrentFunctionArgs += 1; +} + + + + + void cLuaState::Push(bool a_Value) { ASSERT(IsValid()); @@ -948,6 +960,18 @@ void cLuaState::Push(long a_Value) +void cLuaState::Push(const Int64 a_Value) +{ + ASSERT(IsValid()); + + tolua_pushnumber(m_LuaState, a_Value); + m_NumCurrentFunctionArgs += 1; +} + + + + + void cLuaState::Push(UInt32 a_Value) { ASSERT(IsValid()); @@ -960,6 +984,18 @@ void cLuaState::Push(UInt32 a_Value) +void cLuaState::Push(const UInt64 a_Value) +{ + ASSERT(IsValid()); + + tolua_pushnumber(m_LuaState, a_Value); + m_NumCurrentFunctionArgs += 1; +} + + + + + void cLuaState::Push(std::chrono::milliseconds a_Value) { ASSERT(IsValid()); diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 106d8a783..f89076d95 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -358,6 +358,7 @@ public: void Push(const Vector3d * a_Vector); void Push(const Vector3i & a_Vector); void Push(const Vector3i * a_Vector); + void Push(const cByteBuffer & a_Buffer); // Push a simple value onto the stack (keep alpha-sorted): void Push(bool a_Value); @@ -368,7 +369,9 @@ public: void Push(double a_Value); void Push(int a_Value); void Push(long a_Value); + void Push(const Int64 a_Value); void Push(const UInt32 a_Value); + void Push(const UInt64 a_Value); void Push(std::chrono::milliseconds a_time); /** Pops the specified number of values off the top of the Lua stack. */ diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 8bcd5a4e6..d288d37f7 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -18,6 +18,7 @@ #include "../Entities/Player.h" #include "../WebAdmin.h" #include "../ClientHandle.h" +#include "../ChannelManager.h" #include "../BlockArea.h" #include "../BlockEntities/BeaconEntity.h" #include "../BlockEntities/BrewingstandEntity.h" @@ -39,6 +40,7 @@ #include "../BuildInfo.h" #include "../HTTP/UrlParser.h" #include "../BoundingBox.h" +#include "../ChannelCallback.h" @@ -3718,6 +3720,571 @@ static int tolua_cCompositeChat_UnderlineUrls(lua_State * tolua_S) +static int tolua_cChannelManager_RegisterChannel(lua_State * tolua_S) +{ + + // Retrieve the cPlugin from the LuaState: + cPluginLua * Plugin = cManualBindings::GetLuaPlugin(tolua_S); + if (Plugin == nullptr) + { + // An error message has been already printed in GetLuaPlugin() + return 0; + } + + // Check params: + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cChannelManager")) + { + return 0; + } + cChannelManager * self = reinterpret_cast<cChannelManager *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (self == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cChannelManager:RegisterChannel'"); + } + if (!L.CheckParamString(2) || !L.CheckParamFunction(3)) + { + return 0; + } + + AString Channel; + L.GetStackValue(2, Channel); + cLuaState::cCallbackPtr Callback; + L.GetStackValue(3, Callback); + auto ChannelCallback = std::make_shared<cChannelCallback>(*Plugin, Callback); + + auto Result = self->RegisterChannel(Channel, ChannelCallback); + + // Cut away everything from the stack and push on the result of RegisterChannel + lua_settop(L, 2); + L.Push(Result); + return 1; +} + + + + + +static int tolua_cByteBuffer_ReadBEInt8(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadBEInt8'"); + } + + Int8 Value = 0; + auto Success = Buffer->ReadBEInt8(Value); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadBEInt16(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadBEInt16'"); + } + + Int16 Value = 0; + auto Success = Buffer->ReadBEInt16(Value); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadBEInt32(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadBEInt32'"); + } + + Int32 Value = 0; + auto Success = Buffer->ReadBEInt32(Value); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadBEInt64(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadBEInt64'"); + } + + Int64 Value = 0; + auto Success = Buffer->ReadBEInt64(Value); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadBEUInt8(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadBEUInt8'"); + } + + UInt8 Value = 0; + auto Success = Buffer->ReadBEUInt8(Value); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadBEUInt16(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadBEUInt16'"); + } + + UInt16 Value = 0; + auto Success = Buffer->ReadBEUInt16(Value); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadBEUInt32(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadBEUInt32'"); + } + + UInt32 Value = 0; + auto Success = Buffer->ReadBEUInt32(Value); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadBEUInt64(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadBEUInt64'"); + } + + UInt64 Value = 0; + auto Success = Buffer->ReadBEUInt64(Value); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadBEFloat(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadBEFloat'"); + } + + float Value = 0.0f; + auto Success = Buffer->ReadBEFloat(Value); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadBEDouble(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadBEDouble'"); + } + + double Value = 0.0; + auto Success = Buffer->ReadBEDouble(Value); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadBool(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadBool'"); + } + + bool Value = false; + auto Success = Buffer->ReadBool(Value); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadVarInt32(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadVarInt32'"); + } + + UInt32 Value = 0; + auto Success = Buffer->ReadVarInt32(Value); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadVarInt64(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadVarInt64'"); + } + + UInt64 Value = 0; + auto Success = Buffer->ReadVarInt64(Value); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadVarUTF8String(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadVarUTF8String'"); + } + + AString Value; + auto Success = Buffer->ReadVarUTF8String(Value); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadLEInt(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadLEInt'"); + } + + int Value = 0; + auto Success = Buffer->ReadLEInt(Value); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadPosition64(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadPosition64'"); + } + + int X = 0; + int Y = 0; + int Z = 0; + auto Success = Buffer->ReadPosition64(X, Y, Z); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(X); + L.Push(Y); + L.Push(Z); + return 4; +} + + + + +static int tolua_cByteBuffer_ReadString(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadString'"); + } + if (!L.CheckParamNumber(2)) + { + return 0; + } + + AString Value; + size_t Count; + L.GetStackValue(2, Count); + auto Success = Buffer->ReadString(Value, Count); + + lua_settop(tolua_S, 2); + L.Push(Success); + L.Push(Value); + return 2; +} + + + + + +static int tolua_cByteBuffer_ReadAll(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadAll'"); + } + + AString Value; + Buffer->ReadAll(Value); + + lua_settop(tolua_S, 2); + L.Push(Value); + return 1; +} + + + + + +static int tolua_cByteBuffer_ReadAgain(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + if (!L.CheckParamUserType(1, "cByteBuffer")) + { + return 0; + } + + cByteBuffer * Buffer = reinterpret_cast<cByteBuffer *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (Buffer == nullptr) + { + return cManualBindings::lua_do_error(tolua_S, "invalid 'self' in function 'cByteBuffer:ReadAgain'"); + } + + AString Value; + Buffer->ReadAll(Value); + + lua_settop(tolua_S, 2); + L.Push(Value); + return 1; +} + + + + + void cManualBindings::Bind(lua_State * tolua_S) { tolua_beginmodule(tolua_S, nullptr); @@ -3929,13 +4496,35 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_variable(tolua_S, "PostParams", tolua_get_HTTPRequest_PostParams, nullptr); tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cChannelManager"); + tolua_function(tolua_S, "RegisterChannel", tolua_cChannelManager_RegisterChannel); + tolua_endmodule(tolua_S); + + tolua_beginmodule(tolua_S, "cByteBuffer"); + tolua_function(tolua_S, "ReadBEInt8", tolua_cByteBuffer_ReadBEInt8); + tolua_function(tolua_S, "ReadBEInt16", tolua_cByteBuffer_ReadBEInt16); + tolua_function(tolua_S, "ReadBEInt32", tolua_cByteBuffer_ReadBEInt32); + tolua_function(tolua_S, "ReadBEInt64", tolua_cByteBuffer_ReadBEInt64); + tolua_function(tolua_S, "ReadBEUInt8", tolua_cByteBuffer_ReadBEUInt8); + tolua_function(tolua_S, "ReadBEUInt16", tolua_cByteBuffer_ReadBEUInt16); + tolua_function(tolua_S, "ReadBEUInt32", tolua_cByteBuffer_ReadBEUInt32); + tolua_function(tolua_S, "ReadBEUInt64", tolua_cByteBuffer_ReadBEUInt64); + tolua_function(tolua_S, "ReadBEFloat", tolua_cByteBuffer_ReadBEFloat); + tolua_function(tolua_S, "ReadBEDouble", tolua_cByteBuffer_ReadBEDouble); + tolua_function(tolua_S, "ReadBool", tolua_cByteBuffer_ReadBool); + tolua_function(tolua_S, "ReadVarInt32", tolua_cByteBuffer_ReadVarInt32); + tolua_function(tolua_S, "ReadVarInt64", tolua_cByteBuffer_ReadVarInt64); + tolua_function(tolua_S, "ReadVarUTF8String", tolua_cByteBuffer_ReadVarUTF8String); + tolua_function(tolua_S, "ReadLEInt", tolua_cByteBuffer_ReadLEInt); + tolua_function(tolua_S, "ReadPosition64", tolua_cByteBuffer_ReadPosition64); + tolua_function(tolua_S, "ReadString", tolua_cByteBuffer_ReadString); + tolua_function(tolua_S, "ReadAll", tolua_cByteBuffer_ReadAll); + tolua_function(tolua_S, "ReadAgain", tolua_cByteBuffer_ReadAgain); + tolua_endmodule(tolua_S); + BindNetwork(tolua_S); BindRankManager(tolua_S); BindWorld(tolua_S); tolua_endmodule(tolua_S); } - - - - diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index 3276fde67..c477a97aa 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -15,6 +15,13 @@ + +class cByteBuffer; + + + + + // tolua_begin class cPlugin { @@ -91,7 +98,7 @@ public: virtual bool OnPlayerUsedItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) = 0; virtual bool OnPlayerUsingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerUsingItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) = 0; - virtual bool OnPluginMessage (cClientHandle & a_Client, const AString & a_Channel, const AString & a_Message) = 0; + virtual bool OnPluginMessage (cClientHandle & a_Client, const AString & a_Channel, const cByteBuffer & a_Message) = 0; virtual bool OnPluginsLoaded (void) = 0; virtual bool OnPostCrafting (cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe) = 0; virtual bool OnPreCrafting (cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index d1fc2ae4f..26c221200 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -12,11 +12,14 @@ #endif #include "PluginLua.h" +#include "../ByteBuffer.h" #include "../CommandOutput.h" #include "PluginManager.h" #include "../Item.h" #include "../Root.h" #include "../WebAdmin.h" +#include "../ChannelManager.h" +#include "../Server.h" extern "C" { @@ -185,6 +188,7 @@ void cPluginLua::Unload(void) { ClearWebTabs(); super::Unload(); + cRoot::Get()->GetServer()->GetChannelManager()->HandlePluginUnloading(this); Close(); } @@ -762,7 +766,7 @@ bool cPluginLua::OnPlayerUsingItem(cPlayer & a_Player, int a_BlockX, int a_Block -bool cPluginLua::OnPluginMessage(cClientHandle & a_Client, const AString & a_Channel, const AString & a_Message) +bool cPluginLua::OnPluginMessage(cClientHandle & a_Client, const AString & a_Channel, const cByteBuffer & a_Message) { return CallSimpleHooks(cPluginManager::HOOK_PLUGIN_MESSAGE, &a_Client, a_Channel, a_Message); } @@ -1148,7 +1152,3 @@ void cPluginLua::ClearWebTabs(void) webAdmin->RemoveAllPluginWebTabs(m_Name); } } - - - - diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index dc3c91880..de9343b08 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -119,7 +119,7 @@ public: virtual bool OnPlayerUsedItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; virtual bool OnPlayerUsingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerUsingItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; - virtual bool OnPluginMessage (cClientHandle & a_Client, const AString & a_Channel, const AString & a_Message) override; + virtual bool OnPluginMessage (cClientHandle & a_Client, const AString & a_Channel, const cByteBuffer & a_Message) override; virtual bool OnPluginsLoaded (void) override; virtual bool OnPostCrafting (cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe) override; virtual bool OnPreCrafting (cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe) override; @@ -207,7 +207,3 @@ protected: return false; } } ; // tolua_export - - - - diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 19d2e8b4d..fc37c2e2d 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -1188,14 +1188,20 @@ bool cPluginManager::CallHookPlayerUsingItem(cPlayer & a_Player, int a_BlockX, i -bool cPluginManager::CallHookPluginMessage(cClientHandle & a_Client, const AString & a_Channel, const AString & a_Message) +bool cPluginManager::CallHookPluginMessage(cClientHandle & a_Client, const AString & a_Channel, cByteBuffer & a_Buffer) { FIND_HOOK(HOOK_PLUGIN_MESSAGE); VERIFY_HOOK; + a_Buffer.CommitRead(); + AString Data; + a_Buffer.ReadAll(Data); + cByteBuffer Temp(Data.size()); + for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) { - if ((*itr)->OnPluginMessage(a_Client, a_Channel, a_Message)) + Temp.WriteBuf(Data.c_str(), Data.size()); + if ((*itr)->OnPluginMessage(a_Client, a_Channel, Temp)) { return true; } diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 0423d6af1..9ce88e583 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -11,6 +11,7 @@ // fwd: class cBlockEntityWithItems; class cBrewingstandEntity; +class cByteBuffer; class cChunkDesc; class cClientHandle; class cCommandOutputCallback; @@ -267,7 +268,7 @@ public: bool CallHookPlayerUsedItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); bool CallHookPlayerUsingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerUsingItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ); - bool CallHookPluginMessage (cClientHandle & a_Client, const AString & a_Channel, const AString & a_Message); + bool CallHookPluginMessage (cClientHandle & a_Client, const AString & a_Channel, cByteBuffer & a_Buffer); bool CallHookPluginsLoaded (void); bool CallHookPostCrafting (cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe); bool CallHookPreCrafting (cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe); |