diff options
| -rw-r--r-- | pacman-c++/server.cpp | 20 | ||||
| -rw-r--r-- | 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) | |||
| 331 | } | 331 | } |
| 332 | 332 | ||
| 333 | QSharedPointer<QByteArray> data = Util::createPacket(m_updatepacket); | 333 | QSharedPointer<QByteArray> data = Util::createPacket(m_updatepacket); |
| 334 | foreach(QTcpSocket *socket, m_clientConnections) | 334 | QMutableMapIterator<Color::Color, QTcpSocket *> i(m_clientConnections); |
| 335 | while(i.hasNext()) | ||
| 335 | { | 336 | { |
| 337 | i.next(); | ||
| 338 | QTcpSocket *socket = i.value(); | ||
| 339 | |||
| 336 | if (!Util::sendPacket(data.data(), socket)) | 340 | if (!Util::sendPacket(data.data(), socket)) |
| 337 | { | 341 | { |
| 338 | qDebug() << "[sendUpdate] Error while sending data to client, exiting..."; | 342 | qDebug() << "[sendUpdate] Error while sending data to client. Disconnecting..."; |
| 339 | qApp->quit(); | 343 | socket->close(); |
| 344 | qDebug() << "[sendUpdate] Actor" << i.key() << "is now a bot"; | ||
| 345 | m_bots.append(i.key()); | ||
| 346 | ++m_numbots; | ||
| 347 | i.remove(); | ||
| 340 | } | 348 | } |
| 341 | } | 349 | } |
| 350 | |||
| 351 | if (m_maxplayers == m_numbots) | ||
| 352 | { | ||
| 353 | qDebug() << "[sendUpdate] No more real players left. Exiting..."; | ||
| 354 | qApp->quit(); | ||
| 355 | } | ||
| 342 | } | 356 | } |
| 343 | 357 | ||
| 344 | void Server::keyPressUpdate() | 358 | 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: | |||
| 39 | 39 | ||
| 40 | protected: | 40 | protected: |
| 41 | QMap<Color::Color, QTcpSocket *> m_clientConnections; | 41 | QMap<Color::Color, QTcpSocket *> m_clientConnections; |
| 42 | QList<Color::Color> m_bots; | ||
| 42 | 43 | ||
| 43 | /* current movements. required to make pacmans continue their movement */ | 44 | /* current movements. required to make pacmans continue their movement */ |
| 44 | QMap<Color::Color, Actor::Movement> m_actorMovements; | 45 | QMap<Color::Color, Actor::Movement> m_actorMovements; |
