diff options
| author | manuel <manuel@mausz.at> | 2011-04-14 19:18:48 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-04-14 19:18:48 +0200 |
| commit | 197708500f3adaaa50bc1a5a94aec0db8ea621e5 (patch) | |
| tree | 9fd6c9de8aef4f62e34e2d28fd485eaf52a5c909 /pacman-c++/server.cpp | |
| parent | 3fd1334e6d5339cad07ac4e4e23991a73d960a8e (diff) | |
| download | foop-197708500f3adaaa50bc1a5a94aec0db8ea621e5.tar.gz foop-197708500f3adaaa50bc1a5a94aec0db8ea621e5.tar.bz2 foop-197708500f3adaaa50bc1a5a94aec0db8ea621e5.zip | |
add dynamic player count for client. currently works only with 1 player as server doesn't send the initial map to the clients
Diffstat (limited to 'pacman-c++/server.cpp')
| -rw-r--r-- | pacman-c++/server.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index 50ee3b7..e09d126 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp | |||
| @@ -17,6 +17,9 @@ Server::Server(QWidget *parent) | |||
| 17 | 17 | ||
| 18 | bool Server::run() | 18 | bool Server::run() |
| 19 | { | 19 | { |
| 20 | qDebug() << "[Server] Running server..."; | ||
| 21 | qDebug() << "[Server] Max players:" << m_maxplayers; | ||
| 22 | qDebug() << "[Server] Number of bots:" << m_numbots; | ||
| 20 | if (!waitForClientConnections()) | 23 | if (!waitForClientConnections()) |
| 21 | return false; | 24 | return false; |
| 22 | 25 | ||
| @@ -164,20 +167,14 @@ bool Server::waitForClientConnections() | |||
| 164 | qCritical() << "Error while creating socket:" << qPrintable(tcpSrv->errorString()); | 167 | qCritical() << "Error while creating socket:" << qPrintable(tcpSrv->errorString()); |
| 165 | return false; | 168 | return false; |
| 166 | } | 169 | } |
| 167 | |||
| 168 | qDebug() << "[Server] Listening on:" | 170 | qDebug() << "[Server] Listening on:" |
| 169 | << qPrintable(QString("%1:%2").arg(tcpSrv->serverAddress().toString()) | 171 | << qPrintable(QString("%1:%2").arg(tcpSrv->serverAddress().toString()) |
| 170 | .arg(tcpSrv->serverPort())); | 172 | .arg(tcpSrv->serverPort())); |
| 173 | |||
| 171 | qDebug() << "[Server] Waiting for clients"; | 174 | qDebug() << "[Server] Waiting for clients"; |
| 172 | ProtoBuf::WhoAmI packet; | 175 | ProtoBuf::Init packet; |
| 173 | #define SINGLE | 176 | for (unsigned int i = 0; i < m_maxplayers; ++i) |
| 174 | #ifdef SINGLE | ||
| 175 | for (unsigned int i = 0; i < 1; ++i) | ||
| 176 | { | ||
| 177 | #else | ||
| 178 | for (unsigned int i = 0; Color::order[i] != Color::none; ++i) | ||
| 179 | { | 177 | { |
| 180 | #endif | ||
| 181 | bool connectionAvailable = tcpSrv->waitForNewConnection(-1); | 178 | bool connectionAvailable = tcpSrv->waitForNewConnection(-1); |
| 182 | Q_ASSERT(connectionAvailable); | 179 | Q_ASSERT(connectionAvailable); |
| 183 | Q_UNUSED(connectionAvailable); | 180 | Q_UNUSED(connectionAvailable); |
| @@ -189,6 +186,7 @@ bool Server::waitForClientConnections() | |||
| 189 | m_clientConnections[color] = socket; | 186 | m_clientConnections[color] = socket; |
| 190 | /* notify player of color */ | 187 | /* notify player of color */ |
| 191 | packet.set_color(color); | 188 | packet.set_color(color); |
| 189 | packet.set_maxplayers(m_maxplayers); | ||
| 192 | Util::sendPacket(packet, socket); | 190 | Util::sendPacket(packet, socket); |
| 193 | 191 | ||
| 194 | qDebug() << "[Connect] New Player: color=" << color; | 192 | qDebug() << "[Connect] New Player: color=" << color; |
| @@ -208,7 +206,7 @@ void Server::sendUpdate(Transmission::map_t map) | |||
| 208 | m_updatepacket.add_field(map[x][y]); | 206 | m_updatepacket.add_field(map[x][y]); |
| 209 | } | 207 | } |
| 210 | 208 | ||
| 211 | for(unsigned i = 0; Color::order[i] != Color::none; ++i) | 209 | for(unsigned i = 0; i < m_maxplayers; ++i) |
| 212 | { | 210 | { |
| 213 | m_updatepacket.add_round_points(m_actors.value(Color::order[i])->getRoundPoints()); | 211 | m_updatepacket.add_round_points(m_actors.value(Color::order[i])->getRoundPoints()); |
| 214 | m_updatepacket.add_game_points(m_actors.value(Color::order[i])->getGamePoints()); | 212 | m_updatepacket.add_game_points(m_actors.value(Color::order[i])->getGamePoints()); |
