Browse Source

Rename 'c' to 'logicConnection'

Ivan Savenko 1 year ago
parent
commit
38ba42ef7a

+ 19 - 19
client/CServerHandler.cpp

@@ -170,7 +170,7 @@ void CServerHandler::resetStateForLobby(EStartMode mode, ESelectionScreen screen
 	serverMode = newServerMode;
 	mapToStart = nullptr;
 	th = std::make_unique<CStopWatch>();
-	c.reset();
+	logicConnection.reset();
 	si = std::make_shared<StartInfo>();
 	playerNames.clear();
 	si->difficulty = 1;
@@ -329,9 +329,9 @@ void CServerHandler::onConnectionEstablished(const NetworkConnectionPtr & netCon
 		getGlobalLobby().sendProxyConnectionLogin(netConnection);
 	}
 
-	c = std::make_shared<CConnection>(netConnection);
-	c->uuid = uuid;
-	c->enterLobbyConnectionMode();
+	logicConnection = std::make_shared<CConnection>(netConnection);
+	logicConnection->uuid = uuid;
+	logicConnection->enterLobbyConnectionMode();
 	sendClientConnecting();
 }
 
@@ -344,22 +344,22 @@ void CServerHandler::applyPackOnLobbyScreen(CPackForLobby & pack)
 
 std::set<PlayerColor> 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<CampaignState> 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<CampaignState> 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<INetworkConnection>
 		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<INetworkConnection> &
 	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;
 }

+ 2 - 1
client/CServerHandler.h

@@ -128,7 +128,8 @@ class CServerHandler final : public IServerAPI, public LobbyInfo, public INetwor
 	bool isServerLocal() const;
 
 public:
-	std::shared_ptr<CConnection> c;
+	/// High-level connection overlay that is capable of (de)serializing network data
+	std::shared_ptr<CConnection> logicConnection;
 
 	////////////////////
 	// FIXME: Bunch of crutches to glue it all together

+ 5 - 5
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<CPlayerInterface>(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);
 

+ 1 - 1
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();

+ 7 - 7
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<CClient>();
-	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;