From 9020dc993241a4a90e8e98b3435d9b2576f313ea Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 13 Aug 2013 22:45:29 +0200 Subject: Clients are now ticked in cServer first, then in cWorld once they get assigned a world. --- source/Server.cpp | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'source/Server.cpp') 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(a_Client)); + m_ClientsToRemove.push_back(const_cast(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[] } -- cgit v1.2.3