From c56add86d36034b1f32c5ef010b28156c022246e Mon Sep 17 00:00:00 2001 From: Tete Date: Mon, 10 Apr 2023 06:06:41 -0600 Subject: [PATCH] Fix #2774: Prevent kick during redirect (#2955) --- Server/mods/deathmatch/logic/CPlayer.h | 4 ++++ Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp | 1 + Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/Server/mods/deathmatch/logic/CPlayer.h b/Server/mods/deathmatch/logic/CPlayer.h index 845d32403e..bb64a6f51a 100644 --- a/Server/mods/deathmatch/logic/CPlayer.h +++ b/Server/mods/deathmatch/logic/CPlayer.h @@ -262,6 +262,9 @@ class CPlayer final : public CPed, public CClient void SetLeavingServer(bool bLeaving) noexcept { m_bIsLeavingServer = bLeaving; } bool IsLeavingServer() const noexcept { return m_bIsLeavingServer; } + void SetRedirecting(bool bRedirecting) noexcept { m_bIsRedirecting = bRedirecting; } + bool IsRedirecting() const noexcept { return m_bIsRedirecting; } + protected: bool ReadSpecialData(const int iLine) override { return true; } @@ -359,6 +362,7 @@ class CPlayer final : public CPed, public CClient CMtaVersion m_strPlayerVersion; bool m_bIsMuted; bool m_bIsLeavingServer; + bool m_bIsRedirecting; bool m_bIsJoined; bool m_bNametagColorOverridden; diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index b52679f8c5..498d14dd69 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -3462,6 +3462,7 @@ bool CStaticFunctionDefinitions::RedirectPlayer(CElement* pElement, const char* BitStream.pBitStream->Write(ucPasswordLength); BitStream.pBitStream->Write(szPassword, ucPasswordLength); } + pPlayer->SetRedirecting(true); pPlayer->Send(CLuaPacket(FORCE_RECONNECT, *BitStream.pBitStream)); usPort = usPort ? usPort : g_pGame->GetConfig()->GetServerPort(); diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp index f218000c5d..26645c6918 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp @@ -1929,6 +1929,12 @@ int CLuaPlayerDefs::KickPlayer(lua_State* luaVM) CScriptArgReader argStream(luaVM); argStream.ReadUserData(pPlayer); + if (pPlayer->IsRedirecting()) + { + lua_pushboolean(luaVM, false); + return 1; + } + if (argStream.NextIsUserData()) { CClient* pResponsible;