diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index 43a65a9f7..2899906a9 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -170,7 +170,7 @@ void CServerHandler::resetStateForLobby(EStartMode mode, ESelectionScreen screen serverMode = newServerMode; mapToStart = nullptr; th = std::make_unique(); - c.reset(); + logicConnection.reset(); si = std::make_shared(); playerNames.clear(); si->difficulty = 1; @@ -329,9 +329,9 @@ void CServerHandler::onConnectionEstablished(const NetworkConnectionPtr & netCon getGlobalLobby().sendProxyConnectionLogin(netConnection); } - c = std::make_shared(netConnection); - c->uuid = uuid; - c->enterLobbyConnectionMode(); + logicConnection = std::make_shared(netConnection); + logicConnection->uuid = uuid; + logicConnection->enterLobbyConnectionMode(); sendClientConnecting(); } @@ -344,22 +344,22 @@ void CServerHandler::applyPackOnLobbyScreen(CPackForLobby & pack) std::set CServerHandler::getHumanColors() { - return clientHumanColors(c->connectionID); + return clientHumanColors(logicConnection->connectionID); } PlayerColor CServerHandler::myFirstColor() const { - return clientFirstColor(c->connectionID); + return clientFirstColor(logicConnection->connectionID); } bool CServerHandler::isMyColor(PlayerColor color) const { - return isClientColor(c->connectionID, color); + return isClientColor(logicConnection->connectionID, color); } ui8 CServerHandler::myFirstId() const { - return clientFirstId(c->connectionID); + return clientFirstId(logicConnection->connectionID); } EClientState CServerHandler::getState() const @@ -379,12 +379,12 @@ bool CServerHandler::isServerLocal() const bool CServerHandler::isHost() const { - return c && hostClientId == c->connectionID; + return logicConnection && hostClientId == logicConnection->connectionID; } bool CServerHandler::isGuest() const { - return !c || hostClientId != c->connectionID; + return !logicConnection || hostClientId != logicConnection->connectionID; } const std::string & CServerHandler::getLocalHostname() const @@ -438,7 +438,7 @@ void CServerHandler::sendClientDisconnecting() setState(EClientState::DISCONNECTING); mapToStart = nullptr; LobbyClientDisconnected lcd; - lcd.clientId = c->connectionID; + lcd.clientId = logicConnection->connectionID; logNetwork->info("Connection has been requested to be closed."); if(isServerLocal()) { @@ -452,7 +452,7 @@ void CServerHandler::sendClientDisconnecting() sendLobbyPack(lcd); networkConnection->close(); networkConnection.reset(); - c.reset(); + logicConnection.reset(); } void CServerHandler::setCampaignState(std::shared_ptr newCampaign) @@ -684,7 +684,7 @@ void CServerHandler::startGameplay(VCMI_LIB_WRAP_NAMESPACE(CGameState) * gameSta throw std::runtime_error("Invalid mode"); } // After everything initialized we can accept CPackToClient netpacks - c->enterGameplayConnectionMode(client->gameState()); + logicConnection->enterGameplayConnectionMode(client->gameState()); setState(EClientState::GAMEPLAY); } @@ -714,7 +714,7 @@ void CServerHandler::restartGameplay() client->endGame(); client.reset(); - c->enterLobbyConnectionMode(); + logicConnection->enterLobbyConnectionMode(); } void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared_ptr cs) @@ -798,7 +798,7 @@ ELoadMode CServerHandler::getLoadMode() return ELoadMode::CAMPAIGN; for(auto pn : playerNames) { - if(pn.second.connection != c->connectionID) + if(pn.second.connection != logicConnection->connectionID) return ELoadMode::MULTI; } if(howManyPlayerInterfaces() > 1) //this condition will work for hotseat mode OR multiplayer with allowed more than 1 color per player to control @@ -892,7 +892,7 @@ void CServerHandler::onPacketReceived(const std::shared_ptr return; } - CPack * pack = c->retrievePack(message); + CPack * pack = logicConnection->retrievePack(message); ServerHandlerCPackVisitor visitor(*this); pack->visit(visitor); } @@ -921,7 +921,7 @@ void CServerHandler::onDisconnected(const std::shared_ptr & else { LobbyClientDisconnected lcd; - lcd.clientId = c->connectionID; + lcd.clientId = logicConnection->connectionID; applyPackOnLobbyScreen(lcd); } @@ -995,7 +995,7 @@ void CServerHandler::threadRunServer(bool connectToLobby) void CServerHandler::sendLobbyPack(const CPackForLobby & pack) const { if(getState() != EClientState::STARTING) - c->sendPack(&pack); + logicConnection->sendPack(&pack); } bool CServerHandler::inLobbyRoom() const @@ -1005,5 +1005,5 @@ bool CServerHandler::inLobbyRoom() const bool CServerHandler::inGame() const { - return c != nullptr; + return logicConnection != nullptr; } diff --git a/client/CServerHandler.h b/client/CServerHandler.h index 4ec530209..59573676d 100644 --- a/client/CServerHandler.h +++ b/client/CServerHandler.h @@ -128,7 +128,8 @@ class CServerHandler final : public IServerAPI, public LobbyInfo, public INetwor bool isServerLocal() const; public: - std::shared_ptr c; + /// High-level connection overlay that is capable of (de)serializing network data + std::shared_ptr logicConnection; //////////////////// // FIXME: Bunch of crutches to glue it all together diff --git a/client/Client.cpp b/client/Client.cpp index a68608fee..9ff148e9e 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -298,7 +298,7 @@ void CClient::serialize(BinaryDeserializer & h) bool shouldResetInterface = true; // Client no longer handle this player at all - if(!vstd::contains(CSH->getAllClientPlayers(CSH->c->connectionID), pid)) + if(!vstd::contains(CSH->getAllClientPlayers(CSH->logicConnection->connectionID), pid)) { logGlobal->trace("Player %s is not belong to this client. Destroying interface", pid); } @@ -398,7 +398,7 @@ void CClient::initPlayerEnvironments() { playerEnvironments.clear(); - auto allPlayers = CSH->getAllClientPlayers(CSH->c->connectionID); + auto allPlayers = CSH->getAllClientPlayers(CSH->logicConnection->connectionID); bool hasHumanPlayer = false; for(auto & color : allPlayers) { @@ -428,7 +428,7 @@ void CClient::initPlayerInterfaces() for(auto & playerInfo : gs->scenarioOps->playerInfos) { PlayerColor color = playerInfo.first; - if(!vstd::contains(CSH->getAllClientPlayers(CSH->c->connectionID), color)) + if(!vstd::contains(CSH->getAllClientPlayers(CSH->logicConnection->connectionID), color)) continue; if(!vstd::contains(playerint, color)) @@ -458,7 +458,7 @@ void CClient::initPlayerInterfaces() installNewPlayerInterface(std::make_shared(PlayerColor::SPECTATOR), PlayerColor::SPECTATOR, true); } - if(CSH->getAllClientPlayers(CSH->c->connectionID).count(PlayerColor::NEUTRAL)) + if(CSH->getAllClientPlayers(CSH->logicConnection->connectionID).count(PlayerColor::NEUTRAL)) installNewBattleInterface(CDynLibHandler::getNewBattleAI(settings["server"]["neutralAI"].String()), PlayerColor::NEUTRAL); logNetwork->trace("Initialized player interfaces %d ms", CSH->th->getDiff()); @@ -545,7 +545,7 @@ int CClient::sendRequest(const CPackForServer * request, PlayerColor player) waitingRequest.pushBack(requestID); request->requestID = requestID; request->player = player; - CSH->c->sendPack(request); + CSH->logicConnection->sendPack(request); if(vstd::contains(playerint, player)) playerint[player]->requestSent(request, requestID); diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index e22cb04be..d01890f37 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -424,7 +424,7 @@ void ApplyClientNetPackVisitor::visitPlayerReinitInterface(PlayerReinitInterface cl.initPlayerEnvironments(); initInterfaces(); } - else if(pack.playerConnectionId == CSH->c->connectionID) + else if(pack.playerConnectionId == CSH->logicConnection->connectionID) { plSettings.connectedPlayerIDs.insert(pack.playerConnectionId); cl.playerint.clear(); diff --git a/client/NetPacksLobbyClient.cpp b/client/NetPacksLobbyClient.cpp index 6ea57b941..6b7108527 100644 --- a/client/NetPacksLobbyClient.cpp +++ b/client/NetPacksLobbyClient.cpp @@ -40,9 +40,9 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientConnected(LobbyClientCon result = false; // Check if it's LobbyClientConnected for our client - if(pack.uuid == handler.c->uuid) + if(pack.uuid == handler.logicConnection->uuid) { - handler.c->connectionID = pack.clientId; + handler.logicConnection->connectionID = pack.clientId; if(handler.mapToStart) { handler.setMapInfo(handler.mapToStart); @@ -79,7 +79,7 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientConnected(LobbyClientCon void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientDisconnected(LobbyClientDisconnected & pack) { - if(pack.clientId != handler.c->connectionID) + if(pack.clientId != handler.logicConnection->connectionID) { result = false; return; @@ -145,20 +145,20 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyRestartGame(LobbyRestartGame & void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyPrepareStartGame(LobbyPrepareStartGame & pack) { handler.client = std::make_unique(); - handler.c->enterLobbyConnectionMode(); - handler.c->setCallback(handler.client.get()); + handler.logicConnection->enterLobbyConnectionMode(); + handler.logicConnection->setCallback(handler.client.get()); } void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pack) { - if(pack.clientId != -1 && pack.clientId != handler.c->connectionID) + if(pack.clientId != -1 && pack.clientId != handler.logicConnection->connectionID) { result = false; return; } handler.setState(EClientState::STARTING); - if(handler.si->mode != EStartMode::LOAD_GAME || pack.clientId == handler.c->connectionID) + if(handler.si->mode != EStartMode::LOAD_GAME || pack.clientId == handler.logicConnection->connectionID) { auto modeBackup = handler.si->mode; handler.si = pack.initializedStartInfo;