summaryrefslogtreecommitdiffstats
path: root/source/Server.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/Server.cpp48
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[]
}