summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pacman-c++/server.cpp19
-rw-r--r--pacman-c++/server.h4
2 files changed, 22 insertions, 1 deletions
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp
index 07e4c72..4051807 100644
--- a/pacman-c++/server.cpp
+++ b/pacman-c++/server.cpp
@@ -11,7 +11,7 @@
11 11
12Server::Server(QWidget *parent) 12Server::Server(QWidget *parent)
13 : SceneHolder(parent), m_bindaddress(QHostAddress::Any), 13 : SceneHolder(parent), m_bindaddress(QHostAddress::Any),
14 m_port(Constants::Networking::port), m_numbots(0) 14 m_port(Constants::Networking::port), m_rounds(3), m_numbots(0), m_curRound(0)
15{ 15{
16 /* determine max players by using order array */ 16 /* determine max players by using order array */
17 for(m_maxplayers = 0; Color::order[m_maxplayers] != Color::none; ++m_maxplayers); 17 for(m_maxplayers = 0; Color::order[m_maxplayers] != Color::none; ++m_maxplayers);
@@ -26,6 +26,7 @@ bool Server::run()
26 26
27 qDebug() << "[Server] Running server..."; 27 qDebug() << "[Server] Running server...";
28 qDebug() << "[Server] Max players:" << m_maxplayers; 28 qDebug() << "[Server] Max players:" << m_maxplayers;
29 qDebug() << "[Server] Number of rounds:" << m_rounds;
29 qDebug() << "[Server] Number of bots:" << m_numbots; 30 qDebug() << "[Server] Number of bots:" << m_numbots;
30 if (!waitForClientConnections()) 31 if (!waitForClientConnections())
31 return false; 32 return false;
@@ -535,6 +536,10 @@ bool Server::parseCommandline()
535 out << " --nocolorblocks" << endl 536 out << " --nocolorblocks" << endl
536 << " Disable random colorized blocks" << endl 537 << " Disable random colorized blocks" << endl
537 << endl; 538 << endl;
539 opt.setOption("rounds", 'r');
540 out << " -r, --rounds [1..n]" << endl
541 << " Number of rounds to play" << endl
542 << endl;
538 opt.setFlag("nocolorblocks"); 543 opt.setFlag("nocolorblocks");
539 out << " -h, --help" << endl 544 out << " -h, --help" << endl
540 << " Prints this help message" << endl; 545 << " Prints this help message" << endl;
@@ -603,6 +608,18 @@ bool Server::parseCommandline()
603 m_numbots = numbots; 608 m_numbots = numbots;
604 } 609 }
605 610
611 if (opt.getValue("rounds") != NULL)
612 {
613 bool ok;
614 unsigned int rounds = QString(opt.getValue("rounds")).toUInt(&ok);
615 if (!ok || rounds == 0)
616 {
617 qCritical() << "Invalid number of rounds: " << opt.getValue("rounds") << endl;
618 return false;
619 }
620 m_rounds = rounds;
621 }
622
606 this->setProperty("coloredblocks", !opt.getFlag("nocolorblocks")); 623 this->setProperty("coloredblocks", !opt.getFlag("nocolorblocks"));
607 624
608 return true; 625 return true;
diff --git a/pacman-c++/server.h b/pacman-c++/server.h
index 826c701..fd1b571 100644
--- a/pacman-c++/server.h
+++ b/pacman-c++/server.h
@@ -56,7 +56,11 @@ protected:
56 QHostAddress m_bindaddress; 56 QHostAddress m_bindaddress;
57 unsigned int m_port; 57 unsigned int m_port;
58 unsigned int m_maxplayers; 58 unsigned int m_maxplayers;
59 unsigned int m_rounds; // number of rounds (>= 1)
59 unsigned int m_numbots; 60 unsigned int m_numbots;
61
62 unsigned int m_curRound; // current round starting with 0
63
60}; 64};
61 65
62#endif // SERVER_H 66#endif // SERVER_H