MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / processClientNotifications

Method processClientNotifications

source/network/ODServer.cpp:589–1825  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

587}
588
589bool 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);

Callers 1

frameRenderingQueuedMethod · 0.45

Calls 15

writeGameMapToFileFunction · 0.85
Vector3Class · 0.85
recvMethod · 0.80
getConfigPlayerIdMethod · 0.80
setConfigPlayerIdMethod · 0.80
sendMethod · 0.80
setStateMethod · 0.80
getMapSizeXMethod · 0.80
getMapSizeYMethod · 0.80
numClassDescriptionsMethod · 0.80
getClassDescriptionMethod · 0.80
numWeaponsMethod · 0.80

Tested by

no test coverage detected