diff options
author | madmaxoft <github@xoft.cz> | 2013-08-13 22:45:29 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-08-13 22:45:29 +0200 |
commit | 9020dc993241a4a90e8e98b3435d9b2576f313ea (patch) | |
tree | 477b87baeecb8321cc8002e55fdcceb7bd085e3c /source/Server.cpp | |
parent | Fixed logging into debug console. (diff) | |
download | cuberite-9020dc993241a4a90e8e98b3435d9b2576f313ea.tar cuberite-9020dc993241a4a90e8e98b3435d9b2576f313ea.tar.gz cuberite-9020dc993241a4a90e8e98b3435d9b2576f313ea.tar.bz2 cuberite-9020dc993241a4a90e8e98b3435d9b2576f313ea.tar.lz cuberite-9020dc993241a4a90e8e98b3435d9b2576f313ea.tar.xz cuberite-9020dc993241a4a90e8e98b3435d9b2576f313ea.tar.zst cuberite-9020dc993241a4a90e8e98b3435d9b2576f313ea.zip |
Diffstat (limited to 'source/Server.cpp')
-rw-r--r-- | source/Server.cpp | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/source/Server.cpp b/source/Server.cpp index 82a4cb9f5..31a1925a8 100644 --- a/source/Server.cpp +++ b/source/Server.cpp @@ -165,7 +165,7 @@ void cServer::RemoveClient(const cClientHandle * a_Client) void cServer::ClientMovedToWorld(const cClientHandle * a_Client) { cCSLock Lock(m_CSClients); - m_Clients.remove(const_cast<cClientHandle *>(a_Client)); + m_ClientsToRemove.push_back(const_cast<cClientHandle *>(a_Client)); } @@ -312,14 +312,44 @@ bool cServer::Tick(float a_Dt) { cRoot::Get()->TickCommands(); + TickClients(a_Dt); + + if (!m_bRestarting) + { + return true; + } + else + { + m_bRestarting = false; + m_RestartEvent.Set(); + return false; + } +} + + + + + +void cServer::TickClients(float a_Dt) +{ cClientHandleList RemoveClients; { cCSLock Lock(m_CSClients); + + // Remove clients that have moved to a world (the world will be ticking them from now on) + for (cClientHandleList::const_iterator itr = m_ClientsToRemove.begin(), end = m_ClientsToRemove.end(); itr != end; ++itr) + { + m_Clients.remove(*itr); + } // for itr - m_ClientsToRemove[] + m_ClientsToRemove.clear(); + + // Tick the remaining clients, take out those that have been destroyed into RemoveClients for (cClientHandleList::iterator itr = m_Clients.begin(); itr != m_Clients.end();) { if ((*itr)->IsDestroyed()) { - RemoveClients.push_back(*itr); // Remove the client later, when CS is not held, to avoid deadlock ( http://forum.mc-server.org/showthread.php?tid=374 ) + // Remove the client later, when CS is not held, to avoid deadlock ( http://forum.mc-server.org/showthread.php?tid=374 ) + RemoveClients.push_back(*itr); itr = m_Clients.erase(itr); continue; } @@ -327,21 +357,12 @@ bool cServer::Tick(float a_Dt) ++itr; } // for itr - m_Clients[] } + + // Delete the clients that have been destroyed for (cClientHandleList::iterator itr = RemoveClients.begin(); itr != RemoveClients.end(); ++itr) { delete *itr; } // for itr - RemoveClients[] - - if (!m_bRestarting) - { - return true; - } - else - { - m_bRestarting = false; - m_RestartEvent.Set(); - return false; - } } @@ -492,6 +513,7 @@ void cServer::AuthenticateUser(int a_ClientID) if ((*itr)->GetUniqueID() == a_ClientID) { (*itr)->Authenticate(); + return; } } // for itr - m_Clients[] } |