From 31b95afd79886a90f7629b0a7038d90790660e7d Mon Sep 17 00:00:00 2001 From: tycho Date: Mon, 25 May 2015 11:10:26 +0100 Subject: [PATCH] Fixed ClientHandle not getting properly removed from the world when socket is closed whilst the client is being added to the world Fixes #1969 --- src/ClientHandle.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 13972b0f5..765ccdee2 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2957,13 +2957,20 @@ void cClientHandle::PacketError(UInt32 a_PacketType) void cClientHandle::SocketClosed(void) { // The socket has been closed for any reason - + if (!m_Username.empty()) // Ignore client pings { LOGD("Client %s @ %s disconnected", m_Username.c_str(), m_IPString.c_str()); cRoot::Get()->GetPluginManager()->CallHookDisconnect(*this, "Player disconnected"); } - + if (m_State < csDestroying) + { + cWorld * World = m_Player->GetWorld(); + if (World != nullptr) + { + World->RemovePlayer(m_Player, true); // Must be called before cPlayer::Destroy() as otherwise cChunk tries to delete the player, and then we do it again + } + } Destroy(); }