From 2fcca70231dbc34faa46254860fae438169c1e08 Mon Sep 17 00:00:00 2001 From: manuel Date: Sun, 17 Apr 2011 20:32:55 +0200 Subject: if a player disconnect the player will now be a bot --- pacman-c++/server.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'pacman-c++/server.cpp') diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index 628faa2..e42cfbc 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp @@ -331,14 +331,28 @@ void Server::sendUpdate(Transmission::map_t map) } QSharedPointer data = Util::createPacket(m_updatepacket); - foreach(QTcpSocket *socket, m_clientConnections) + QMutableMapIterator i(m_clientConnections); + while(i.hasNext()) { + i.next(); + QTcpSocket *socket = i.value(); + if (!Util::sendPacket(data.data(), socket)) { - qDebug() << "[sendUpdate] Error while sending data to client, exiting..."; - qApp->quit(); + qDebug() << "[sendUpdate] Error while sending data to client. Disconnecting..."; + socket->close(); + qDebug() << "[sendUpdate] Actor" << i.key() << "is now a bot"; + m_bots.append(i.key()); + ++m_numbots; + i.remove(); } } + + if (m_maxplayers == m_numbots) + { + qDebug() << "[sendUpdate] No more real players left. Exiting..."; + qApp->quit(); + } } void Server::keyPressUpdate() -- cgit v1.2.3