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 +++++++++++++++++--- pacman-c++/server.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) 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() diff --git a/pacman-c++/server.h b/pacman-c++/server.h index a50cfe3..1a25137 100644 --- a/pacman-c++/server.h +++ b/pacman-c++/server.h @@ -39,6 +39,7 @@ protected: protected: QMap m_clientConnections; + QList m_bots; /* current movements. required to make pacmans continue their movement */ QMap m_actorMovements; -- cgit v1.2.3