summaryrefslogtreecommitdiffstats
path: root/pacman-c++/server.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pacman-c++/server.cpp')
-rw-r--r--pacman-c++/server.cpp37
1 files changed, 21 insertions, 16 deletions
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp
index 2b43bb9..a7ff89a 100644
--- a/pacman-c++/server.cpp
+++ b/pacman-c++/server.cpp
@@ -30,10 +30,10 @@ bool Server::run()
30 m_tickTimer->setInterval(Constants::tick); 30 m_tickTimer->setInterval(Constants::tick);
31 connect(m_tickTimer, SIGNAL(timeout()), this, SLOT(tick())); 31 connect(m_tickTimer, SIGNAL(timeout()), this, SLOT(tick()));
32 32
33 qDebug() << "[Server] Running server..."; 33 std::cout << "[Server] Running server..." << std::endl
34 qDebug() << "[Server] Max players:" << m_maxplayers; 34 << "[Server] Max players: " << m_maxplayers << std::endl
35 qDebug() << "[Server] Number of bots:" << m_numbots; 35 << "[Server] Number of bots: " << m_numbots << std::endl
36 qDebug() << "[Server] Number of rounds:" << m_rounds; 36 << "[Server] Number of rounds: " << m_rounds << std::endl;
37 if (!waitForClientConnections()) 37 if (!waitForClientConnections())
38 return false; 38 return false;
39 39
@@ -240,6 +240,8 @@ invalid_direction:
240 foreach(Color::Color color, movements.keys()) 240 foreach(Color::Color color, movements.keys())
241 m_actors[color]->setPos(mapPositionToCoord(movements[color].first)); 241 m_actors[color]->setPos(mapPositionToCoord(movements[color].first));
242 242
243#ifndef QT_NO_DEBUG
244 /* collision sanity check: colors must be unique */
243 foreach(Color::Color col, m_eatingorder.toSet()) 245 foreach(Color::Color col, m_eatingorder.toSet())
244 { 246 {
245 QList<QPoint> found; 247 QList<QPoint> found;
@@ -252,8 +254,9 @@ invalid_direction:
252 } 254 }
253 } 255 }
254 if (found.count() > 1) 256 if (found.count() > 1)
255 qDebug() << "found" << found << "fields with color=" << col; 257 qCritical() << "[Collision] found" << found << "fields with color=" << col;
256 } 258 }
259#endif
257 260
258 return map; 261 return map;
259} 262}
@@ -360,11 +363,11 @@ bool Server::waitForClientConnections()
360 qCritical() << "Error while creating socket:" << qPrintable(tcpSrv->errorString()); 363 qCritical() << "Error while creating socket:" << qPrintable(tcpSrv->errorString());
361 return false; 364 return false;
362 } 365 }
363 qDebug() << "[Server] Listening on:" 366 std::cout << "[Server] Listening on: "
364 << qPrintable(QString("%1:%2").arg(tcpSrv->serverAddress().toString()) 367 << qPrintable(QString("%1:%2").arg(tcpSrv->serverAddress().toString())
365 .arg(tcpSrv->serverPort())); 368 .arg(tcpSrv->serverPort())) << std::endl;
366 369
367 qDebug() << "[Server] Waiting for clients"; 370 std::cout << "[Server] Waiting for clients" << std::endl;
368 ProtoBuf::Init packet; 371 ProtoBuf::Init packet;
369 packet.set_maxplayers(m_maxplayers); 372 packet.set_maxplayers(m_maxplayers);
370 for (unsigned int i = 0; i < (m_maxplayers - m_numbots); ++i) 373 for (unsigned int i = 0; i < (m_maxplayers - m_numbots); ++i)
@@ -380,7 +383,7 @@ bool Server::waitForClientConnections()
380 m_clientConnections[color] = socket; 383 m_clientConnections[color] = socket;
381 packet.set_color(color); 384 packet.set_color(color);
382 Util::sendPacket(packet, socket); 385 Util::sendPacket(packet, socket);
383 qDebug() << "[Connect] New Player: color=" << color; 386 std::cout << "[Connect] New Player: color=" << qPrintable(Util::colorToString(color)) << std::endl;
384 } 387 }
385 388
386 for (unsigned int i = (m_maxplayers - m_numbots); i < m_maxplayers; ++i) 389 for (unsigned int i = (m_maxplayers - m_numbots); i < m_maxplayers; ++i)
@@ -425,9 +428,10 @@ void Server::sendUpdate(Transmission::map_t map, bool firstPacket)
425 428
426 if (!Util::sendPacket(data.data(), socket)) 429 if (!Util::sendPacket(data.data(), socket))
427 { 430 {
428 qDebug() << "[sendUpdate] Error while sending data to client. Disconnecting..."; 431 qWarning() << "[Connect] Error while sending data to client" << i.key() << "-> Disconnecting...";
429 socket->close(); 432 socket->close();
430 qDebug() << "[sendUpdate] Actor" << i.key() << "is now a bot"; 433 std::cout << "[Connect] Actor color=" << qPrintable(Util::colorToString(i.key()))
434 << " is now a bot" << std::endl;
431 m_bots.append(i.key()); 435 m_bots.append(i.key());
432 ++m_numbots; 436 ++m_numbots;
433 i.remove(); 437 i.remove();
@@ -436,7 +440,7 @@ void Server::sendUpdate(Transmission::map_t map, bool firstPacket)
436 440
437 if (m_maxplayers == m_numbots) 441 if (m_maxplayers == m_numbots)
438 { 442 {
439 qDebug() << "[sendUpdate] No more real players left. Exiting..."; 443 std::cout << "[Connect] No more real players left. Exiting..." << std::endl;
440 qApp->quit(); 444 qApp->quit();
441 } 445 }
442} 446}
@@ -594,7 +598,7 @@ void Server::keyPressUpdate()
594 598
595void Server::initRoundMap() 599void Server::initRoundMap()
596{ 600{
597 qDebug() << "[initRoundMap] New round starts..."; 601 std::cout << "[Game] New round starts..." << std::endl;
598 m_tickTimer->stop(); 602 m_tickTimer->stop();
599 603
600 /* reset scene and clean up items */ 604 /* reset scene and clean up items */
@@ -605,7 +609,7 @@ void Server::initRoundMap()
605 Util::placeActors(map, m_maxplayers, Color::order); 609 Util::placeActors(map, m_maxplayers, Color::order);
606 Util::fillPoints(map); 610 Util::fillPoints(map);
607 611
608#if 0 // actor eating actor tests 612#if 0 // actor eating actor tests - TODO: remove
609 m_actorMovements.clear(); 613 m_actorMovements.clear();
610#if 0 614#if 0
611 //works 615 //works
@@ -706,6 +710,8 @@ void Server::stopGame(bool delay)
706 return; 710 return;
707 } 711 }
708 712
713 std::cout << "[Game] Round finished..." << std::endl;
714
709 /* do next-round work */ 715 /* do next-round work */
710 ++m_curRound; 716 ++m_curRound;
711 if(m_rounds == 0 || m_curRound < m_rounds) 717 if(m_rounds == 0 || m_curRound < m_rounds)
@@ -713,12 +719,11 @@ void Server::stopGame(bool delay)
713 else 719 else
714 { 720 {
715 /* end of game */ 721 /* end of game */
716 qDebug() << "All round finished. Exiting..."; 722 std::cout << "[Game] All round finished. Exiting..." << std::endl;
717 qApp->quit(); 723 qApp->quit();
718 } 724 }
719} 725}
720 726
721
722void Server::setFinishRound() 727void Server::setFinishRound()
723{ 728{
724 m_finishRound = true; 729 m_finishRound = true;