From 9210501af5ab0b91e331e9b4d27ac7fd63888f48 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Tue, 31 Mar 2020 11:39:23 +0000 Subject: Prevent player from being destroyed by plugins (#4584) * Prevent player from being destroyed by plugins Add manual binding, bails out with error message if attempted entity to destroy is player. * Improve warnings and documentation, remove automatic binding * Remove old and unnecessary deprecated function --- src/Bindings/ManualBindings.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/Bindings') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 1ab3cbaa0..bf53b8b7c 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -4081,6 +4081,37 @@ static int tolua_cCuboid_Move(lua_State * tolua_S) +static int tolua_cEntity_Destroy(lua_State * tolua_S) +{ + // Check the params: + cLuaState L(tolua_S); + if (!L.CheckParamSelf("cEntity")) + { + return 0; + } + + // Get the params: + cEntity * self = nullptr; + L.GetStackValue(1, self); + + if (lua_gettop(L) == 2) + { + LOGWARNING("cEntity:Destroy(bool) is deprecated, use cEntity:Destroy() instead."); + } + + if (self->IsPlayer()) + { + return L.ApiParamError("Cannot call cEntity:Destroy() on a cPlayer, use cClientHandle:Kick() instead."); + } + + self->Destroy(); + return 0; +} + + + + + static int tolua_cEntity_IsSubmerged(lua_State * tolua_S) { // Check the params: @@ -4256,6 +4287,7 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_beginmodule(tolua_S, "cEntity"); tolua_constant(tolua_S, "INVALID_ID", cEntity::INVALID_ID); + tolua_function(tolua_S, "Destroy", tolua_cEntity_Destroy); tolua_function(tolua_S, "IsSubmerged", tolua_cEntity_IsSubmerged); tolua_function(tolua_S, "IsSwimming", tolua_cEntity_IsSwimming); tolua_function(tolua_S, "GetPosition", tolua_cEntity_GetPosition); -- cgit v1.2.3