Pārlūkot izejas kodu

CGameHandler: rename CPackForClient argument and add network logging

Arseniy Shestakov 7 gadi atpakaļ
vecāks
revīzija
74e5c5bf05

+ 1 - 1
client/Client.h

@@ -203,7 +203,7 @@ public:
 	void setManaPoints(ObjectInstanceID hid, int val) override {};
 	void giveHero(ObjectInstanceID id, PlayerColor player) override {};
 	void changeObjPos(ObjectInstanceID objid, int3 newPos, ui8 flags) override {};
-	void sendAndApply(CPackForClient * info) override {};
+	void sendAndApply(CPackForClient * pack) override {};
 	void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2) override {};
 
 	void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide) override {}

+ 1 - 1
lib/IGameCallback.h

@@ -91,7 +91,7 @@ public:
 	virtual void setManaPoints(ObjectInstanceID hid, int val)=0;
 	virtual void giveHero(ObjectInstanceID id, PlayerColor player)=0;
 	virtual void changeObjPos(ObjectInstanceID objid, int3 newPos, ui8 flags)=0;
-	virtual void sendAndApply(CPackForClient * info)=0;
+	virtual void sendAndApply(CPackForClient * pack) = 0;
 	virtual void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2)=0; //when two heroes meet on adventure map
 	virtual void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide) = 0;
 	virtual void changeFogOfWar(std::unordered_set<int3, ShashInt3> &tiles, PlayerColor player, bool hide) = 0;

+ 1 - 1
lib/serializer/Connection.cpp

@@ -207,7 +207,7 @@ CPack * CConnection::retrievePack()
 	CPack * pack = nullptr;
 	boost::unique_lock<boost::mutex> lock(*mutexRead);
 	iser & pack;
-	logNetwork->trace("\treceived CPack of type %s", (pack ? typeid(*pack).name() : "nullptr"));
+	logNetwork->trace("Received CPack of type %s", (pack ? typeid(*pack).name() : "nullptr"));
 	if(pack == nullptr)
 	{
 		logNetwork->error("Received a nullptr CPack! You should check whether client and server ABI matches.");

+ 1 - 1
lib/spells/Magic.h

@@ -60,7 +60,7 @@ class DLL_LINKAGE PacketSender
 {
 public:
 	virtual ~PacketSender(){};
-	virtual void sendAndApply(CPackForClient * info) const = 0;
+	virtual void sendAndApply(CPackForClient * pack) const = 0;
 	virtual void complain(const std::string & problem) const = 0;
 };
 

+ 21 - 20
server/CGameHandler.cpp

@@ -61,7 +61,7 @@ class ServerSpellCastEnvironment : public SpellCastEnvironment
 public:
 	ServerSpellCastEnvironment(CGameHandler * gh);
 	~ServerSpellCastEnvironment() = default;
-	void sendAndApply(CPackForClient * info) const override;
+	void sendAndApply(CPackForClient * pack) const override;
 	CRandomGenerator & getRandomGenerator() const override;
 	void complain(const std::string & problem) const override;
 	const CMap * getMap() const override;
@@ -2694,46 +2694,47 @@ void CGameHandler::heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2)
 	}
 }
 
-void CGameHandler::sendToAllClients(CPackForClient * info)
+void CGameHandler::sendToAllClients(CPackForClient * pack)
 {
-	logNetwork->trace("Sending to all clients a package of type %s", typeid(*info).name());
+	logNetwork->trace("\tSending to all clients: %s", typeid(*pack).name());
 	for (auto c : lobby->connections)
 	{
 		if(!c->isOpen())
 			continue;
 
-		c->sendPack(info);
+		c->sendPack(pack);
 	}
 }
 
-void CGameHandler::sendAndApply(CPackForClient * info)
+void CGameHandler::sendAndApply(CPackForClient * pack)
 {
-	sendToAllClients(info);
-	gs->apply(info);
+	sendToAllClients(pack);
+	gs->apply(pack);
+	logNetwork->trace("\tApplied on gs: %s", typeid(*pack).name());
 }
 
-void CGameHandler::applyAndSend(CPackForClient * info)
+void CGameHandler::applyAndSend(CPackForClient * pack)
 {
-	gs->apply(info);
-	sendToAllClients(info);
+	gs->apply(pack);
+	sendToAllClients(pack);
 }
 
-void CGameHandler::sendAndApply(CGarrisonOperationPack * info)
+void CGameHandler::sendAndApply(CGarrisonOperationPack * pack)
 {
-	sendAndApply(static_cast<CPackForClient*>(info));
+	sendAndApply(static_cast<CPackForClient *>(pack));
 	checkVictoryLossConditionsForAll();
 }
 
-void CGameHandler::sendAndApply(SetResources * info)
+void CGameHandler::sendAndApply(SetResources * pack)
 {
-	sendAndApply(static_cast<CPackForClient*>(info));
-	checkVictoryLossConditionsForPlayer(info->player);
+	sendAndApply(static_cast<CPackForClient *>(pack));
+	checkVictoryLossConditionsForPlayer(pack->player);
 }
 
-void CGameHandler::sendAndApply(NewStructures * info)
+void CGameHandler::sendAndApply(NewStructures * pack)
 {
-	sendAndApply(static_cast<CPackForClient*>(info));
-	checkVictoryLossConditionsForPlayer(getTown(info->tid)->tempOwner);
+	sendAndApply(static_cast<CPackForClient *>(pack));
+	checkVictoryLossConditionsForPlayer(getTown(pack->tid)->tempOwner);
 }
 
 void CGameHandler::save(const std::string & filename)
@@ -6726,9 +6727,9 @@ ServerSpellCastEnvironment::ServerSpellCastEnvironment(CGameHandler * gh): gh(gh
 
 }
 
-void ServerSpellCastEnvironment::sendAndApply(CPackForClient * info) const
+void ServerSpellCastEnvironment::sendAndApply(CPackForClient * pack) const
 {
-	gh->sendAndApply(info);
+	gh->sendAndApply(pack);
 }
 
 CRandomGenerator & ServerSpellCastEnvironment::getRandomGenerator() const

+ 6 - 6
server/CGameHandler.h

@@ -254,12 +254,12 @@ public:
 
 	void sendMessageToAll(const std::string &message);
 	void sendMessageTo(std::shared_ptr<CConnection> c, const std::string &message);
-	void sendToAllClients(CPackForClient * info);
-	void sendAndApply(CPackForClient * info) override;
-	void applyAndSend(CPackForClient * info);
-	void sendAndApply(CGarrisonOperationPack * info);
-	void sendAndApply(SetResources * info);
-	void sendAndApply(NewStructures * info);
+	void sendToAllClients(CPackForClient * pack);
+	void sendAndApply(CPackForClient * pack) override;
+	void applyAndSend(CPackForClient * pack);
+	void sendAndApply(CGarrisonOperationPack * pack);
+	void sendAndApply(SetResources * pack);
+	void sendAndApply(NewStructures * pack);
 
 	struct FinishingBattleHelper
 	{

+ 2 - 2
test/game/CGameStateTest.cpp

@@ -44,9 +44,9 @@ public:
 		IObjectInterface::cb = nullptr;
 	}
 
-	void sendAndApply(CPackForClient * info) const override
+	void sendAndApply(CPackForClient * pack) const override
 	{
-		gameState->apply(info);
+		gameState->apply(pack);
 	}
 
 	void complain(const std::string & problem) const

+ 2 - 2
test/mock/mock_IGameCallback.cpp

@@ -32,7 +32,7 @@ void GameCallbackMock::commitPackage(CPackForClient * pack)
 	sendAndApply(pack);
 }
 
-void GameCallbackMock::sendAndApply(CPackForClient * info)
+void GameCallbackMock::sendAndApply(CPackForClient * pack)
 {
-	upperCallback->sendAndApply(info);
+	upperCallback->sendAndApply(pack);
 }

+ 1 - 1
test/mock/mock_IGameCallback.h

@@ -86,7 +86,7 @@ public:
 
 	///useful callback methods
 	void commitPackage(CPackForClient * pack) override;
-	void sendAndApply(CPackForClient * info) override;
+	void sendAndApply(CPackForClient * pack) override;
 private:
 	const UpperCallback * upperCallback;
 };