diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index bd91adec..9383f4e0 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -696,14 +696,16 @@ ServerGame::ResetComputerPlayerList() void ServerGame::GracefulRemoveSession(SessionWrapper session, int reason) { - if (!session.sessionData.get()) + if (!session.sessionData) throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0); - GetSessionManager().RemoveSession(session.sessionData->GetId()); - boost::shared_ptr tmpPlayerData = session.playerData; - if (tmpPlayerData.get() && !tmpPlayerData->GetName().empty()) + if (GetSessionManager().RemoveSession(session.sessionData->GetId())) { - RemovePlayerData(tmpPlayerData, reason); + boost::shared_ptr tmpPlayerData = session.playerData; + if (tmpPlayerData && !tmpPlayerData->GetName().empty()) + { + RemovePlayerData(tmpPlayerData, reason); + } } } diff --git a/src/net/common/sessionmanager.cpp b/src/net/common/sessionmanager.cpp index 8645931d..274da580 100644 --- a/src/net/common/sessionmanager.cpp +++ b/src/net/common/sessionmanager.cpp @@ -73,11 +73,11 @@ SessionManager::SetSessionPlayerData(SessionId session, boost::shared_ptrsecond.playerData = playerData; } -void +bool SessionManager::RemoveSession(SessionId session) { boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex); - m_sessionMap.erase(session); + return m_sessionMap.erase(session) == 1; } SessionWrapper diff --git a/src/net/sessionmanager.h b/src/net/sessionmanager.h index d88bcc73..f8fb7427 100644 --- a/src/net/sessionmanager.h +++ b/src/net/sessionmanager.h @@ -51,7 +51,7 @@ public: void AddSession(boost::shared_ptr sessionData); // new Sessions without player data void AddSession(SessionWrapper session); void SetSessionPlayerData(SessionId session, boost::shared_ptr playerData); - void RemoveSession(SessionId session); + bool RemoveSession(SessionId session); SessionWrapper GetSessionById(SessionId id) const; SessionWrapper GetSessionByPlayerName(const std::string playerName) const;