| 391 | } |
| 392 | |
| 393 | void ODServer::serverThread() |
| 394 | { |
| 395 | GameMap* gameMap = mGameMap; |
| 396 | sf::Clock clock; |
| 397 | double turnLengthMs = 1000.0 / ODApplication::turnsPerSecond; |
| 398 | bool isClientConnected = true; |
| 399 | while(isConnected() && isClientConnected) |
| 400 | { |
| 401 | // doTask should return after the length of 1 turn even if their are communications. When |
| 402 | // it returns, we can launch next turn. |
| 403 | doTask(static_cast<int32_t>(turnLengthMs)); |
| 404 | // If all the clients are disconnected during a game, we close the server |
| 405 | if((mServerState == ServerState::StateGame) && |
| 406 | (mSockClients.empty())) |
| 407 | { |
| 408 | // Time to stop the game |
| 409 | isClientConnected = false; |
| 410 | continue; |
| 411 | } |
| 412 | |
| 413 | if(gameMap->getTurnNumber() == -1) |
| 414 | { |
| 415 | // The game is not started |
| 416 | if(mSeatsConfigured) |
| 417 | { |
| 418 | // We notify the master server that we are not waiting for players anymore |
| 419 | if(!mMasterServerGameId.empty()) |
| 420 | { |
| 421 | mMasterServerGameStatusUpdateTime = 0.0; |
| 422 | MasterServer::updateGame(mMasterServerGameId, MASTER_SERVER_STATUS_STARTED); |
| 423 | } |
| 424 | |
| 425 | // We configure the game for launching |
| 426 | const std::vector<Seat*>& seats = gameMap->getSeats(); |
| 427 | for (int jj = 0; jj < gameMap->getMapSizeY(); ++jj) |
| 428 | { |
| 429 | for (int ii = 0; ii < gameMap->getMapSizeX(); ++ii) |
| 430 | { |
| 431 | Tile* tile = gameMap->getTile(ii,jj); |
| 432 | tile->setSeats(seats); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | // We set allied seats |
| 437 | for(Seat* seat : seats) |
| 438 | { |
| 439 | for(Seat* alliedSeat : seats) |
| 440 | { |
| 441 | if(alliedSeat == seat) |
| 442 | continue; |
| 443 | if(!seat->isAlliedSeat(alliedSeat)) |
| 444 | continue; |
| 445 | seat->addAlliedSeat(alliedSeat); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | // Every client is connected and ready, we can launch the game |
| 450 | // Send turn 0 to init the map |
nothing calls this directly
no test coverage detected