| 587 | } |
| 588 | |
| 589 | bool ODServer::processClientNotifications(ODSocketClient* clientSocket) |
| 590 | { |
| 591 | if (!clientSocket) |
| 592 | return false; |
| 593 | |
| 594 | GameMap* gameMap = mGameMap; |
| 595 | |
| 596 | ODPacket packetReceived; |
| 597 | |
| 598 | ODSocketClient::ODComStatus status = clientSocket->recv(packetReceived); |
| 599 | |
| 600 | // If the client closed the connection |
| 601 | if (status != ODSocketClient::ODComStatus::OK) |
| 602 | { |
| 603 | // If a client disconnects during seat configuration, we delete him from the list |
| 604 | if(mServerState != ServerState::StateConfiguration) |
| 605 | return (status != ODSocketClient::ODComStatus::Error); |
| 606 | |
| 607 | // If the client is in a state where he has been notified to the other clients, |
| 608 | // we notify his deconnexion |
| 609 | if(std::string("ready").compare(clientSocket->getState()) != 0) |
| 610 | return (status != ODSocketClient::ODComStatus::Error); |
| 611 | |
| 612 | OD_LOG_INF("Disconnected player: " + clientSocket->getPlayer()->getNick()); |
| 613 | // We notify |
| 614 | uint32_t nbPlayers = 1; |
| 615 | ODPacket packetSend; |
| 616 | packetSend << ServerNotificationType::removePlayers << nbPlayers; |
| 617 | int32_t id = clientSocket->getPlayer()->getId(); |
| 618 | packetSend << id; |
| 619 | sendMsg(nullptr, packetSend); |
| 620 | |
| 621 | ODSocketClient* otherHumanConnected = nullptr; |
| 622 | for(Seat* seat : gameMap->getSeats()) |
| 623 | { |
| 624 | if(seat->getConfigPlayerId() == id) |
| 625 | { |
| 626 | seat->setConfigPlayerId(-1); |
| 627 | if(clientSocket->getPlayer() == mPlayerConfig) |
| 628 | mPlayerConfig = nullptr; |
| 629 | } |
| 630 | |
| 631 | if(seat->getConfigPlayerId() < Seat::PLAYER_ID_HUMAN_MIN) |
| 632 | continue; |
| 633 | |
| 634 | otherHumanConnected = getClientFromPlayerId(seat->getConfigPlayerId()); |
| 635 | } |
| 636 | if((mPlayerConfig == nullptr) && |
| 637 | (otherHumanConnected != nullptr)) |
| 638 | { |
| 639 | mPlayerConfig = otherHumanConnected->getPlayer(); |
| 640 | ODPacket packetSend; |
| 641 | packetSend << ServerNotificationType::playerConfigChange; |
| 642 | otherHumanConnected->send(packetSend); |
| 643 | |
| 644 | OD_LOG_INF("Changing game host to " + mPlayerConfig->getNick()); |
| 645 | } |
| 646 | return (status != ODSocketClient::ODComStatus::Error); |
no test coverage detected