diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2016-12-19 21:12:23 +0100 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2017-08-07 20:24:16 +0200 |
commit | 4ef47aed62364f9cf1474864e5cf94232b4477af (patch) | |
tree | 28ca15247c2437b91e9aada48c2da4a1a3c00c17 /src/ClientHandle.cpp | |
parent | Removed unneeded includes (#3902) (diff) | |
download | cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar.gz cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar.bz2 cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar.lz cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar.xz cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar.zst cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.zip |
Diffstat (limited to 'src/ClientHandle.cpp')
-rw-r--r-- | src/ClientHandle.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index b015b745f..9366facf3 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -133,7 +133,7 @@ cClientHandle::~cClientHandle() } m_Player->DestroyNoScheduling(true); } - delete m_Player; + m_PlayerPtr.reset(); m_Player = nullptr; } @@ -157,8 +157,12 @@ void cClientHandle::Destroy(void) cCSLock Lock(m_CSOutgoingData); m_Link.reset(); } + + // Temporary (#3115-will-fix): variable to keep track of whether the client authenticated and had the opportunity to have ownership transferred to the world + bool WasAddedToWorld = false; { cCSLock Lock(m_CSState); + WasAddedToWorld = (m_State >= csAuthenticated); if (m_State >= csDestroying) { // Already called @@ -186,7 +190,23 @@ void cClientHandle::Destroy(void) { player->StopEveryoneFromTargetingMe(); player->SetIsTicking(false); - world->RemovePlayer(player, true); + + if (WasAddedToWorld) + { + // If ownership was transferred, our own smart pointer should be unset + ASSERT(!m_PlayerPtr); + + m_PlayerPtr = world->RemovePlayer(*player, true); + + // And RemovePlayer should have returned a valid smart pointer + ASSERT(m_PlayerPtr); + } + else + { + // If ownership was not transferred, our own smart pointer should be valid and RemovePlayer's should not + ASSERT(m_PlayerPtr); + ASSERT(!world->IsPlayerReferencedInWorldOrChunk(*player)); + } } player->RemoveClientHandle(); } @@ -359,7 +379,8 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, m_Protocol->SendLoginSuccess(); // Spawn player (only serversided, so data is loaded) - m_Player = new cPlayer(m_Self, GetUsername()); + m_PlayerPtr = cpp14::make_unique<cPlayer>(m_Self, GetUsername()); + m_Player = m_PlayerPtr.get(); /* LOGD("Created a new cPlayer object at %p for client %s @ %s (%p)", static_cast<void *>(m_Player), @@ -2203,7 +2224,7 @@ void cClientHandle::ServerTick(float a_Dt) // Add the player to the world (start ticking from there): m_State = csDownloadingWorld; - m_Player->Initialize(*(m_Player->GetWorld())); + m_Player->Initialize(std::move(m_PlayerPtr), *(m_Player->GetWorld())); return; } } // lock(m_CSState) |