瀏覽代碼

Added PackageReceived message to show when server starts pack processing

Ivan Savenko 3 月之前
父節點
當前提交
6b382a979a

+ 1 - 0
client/ClientNetPackVisitors.h

@@ -92,6 +92,7 @@ public:
 	void visitCatapultAttack(CatapultAttack & pack) override;
 	void visitEndAction(EndAction & pack) override;
 	void visitPackageApplied(PackageApplied & pack) override;
+	void visitPackageReceived(PackageReceived & pack) override;
 	void visitSystemMessage(SystemMessage & pack) override;
 	void visitPlayerBlocked(PlayerBlocked & pack) override;
 	void visitPlayerStartsTurn(PlayerStartsTurn & pack) override;

+ 5 - 0
client/NetPacksClient.cpp

@@ -926,6 +926,11 @@ void ApplyClientNetPackVisitor::visitPackageApplied(PackageApplied & pack)
 		logNetwork->warn("Surprising server message! PackageApplied for unknown requestID!");
 }
 
+void ApplyClientNetPackVisitor::visitPackageReceived(PackageReceived & pack)
+{
+	// No-op for now
+}
+
 void ApplyClientNetPackVisitor::visitSystemMessage(SystemMessage & pack)
 {
 	// usually used to receive error messages from server

+ 1 - 0
lib/networkPacks/NetPackVisitor.h

@@ -28,6 +28,7 @@ public:
 	virtual void visitForServer(CPackForServer & pack) {}
 	virtual void visitForClient(CPackForClient & pack) {}
 	virtual void visitPackageApplied(PackageApplied & pack) {}
+	virtual void visitPackageReceived(PackageReceived & pack) {}
 	virtual void visitSystemMessage(SystemMessage & pack) {}
 	virtual void visitPlayerBlocked(PlayerBlocked & pack) {}
 	virtual void visitPlayerCheated(PlayerCheated & pack) {}

+ 5 - 0
lib/networkPacks/NetPacksLib.cpp

@@ -74,6 +74,11 @@ void PackageApplied::visitTyped(ICPackVisitor & visitor)
 	visitor.visitPackageApplied(*this);
 }
 
+void PackageReceived::visitTyped(ICPackVisitor & visitor)
+{
+	visitor.visitPackageReceived(*this);
+}
+
 void SystemMessage::visitTyped(ICPackVisitor & visitor)
 {
 	visitor.visitSystemMessage(*this);

+ 42 - 7
lib/networkPacks/PacksForClient.h

@@ -52,23 +52,58 @@ using TTeleportExitsList = std::vector<std::pair<ObjectInstanceID, int3>>;
 struct DLL_LINKAGE PackageApplied : public CPackForClient
 {
 	PackageApplied() = default;
-	explicit PackageApplied(ui8 Result)
-		: result(Result)
+	PackageApplied(PlayerColor player, uint32_t requestID, uint16_t packType, bool result)
+		: player(player)
+		, requestID(requestID)
+		, packType(packType)
+		, result(result)
 	{
 	}
+
 	void visitTyped(ICPackVisitor & visitor) override;
 
-	ui8 result = 0; //0 - something went wrong, request hasn't been realized; 1 - OK
-	ui32 packType = 0; //type id of applied package
-	ui32 requestID = 0; //an ID given by client to the request that was applied
+	/// ID of player that sent this package
 	PlayerColor player;
+	/// request ID, as provided by player
+	uint32_t requestID = 0;
+	/// type id of applied package
+	uint16_t packType = 0;
+	/// If false, then pack failed to apply, for example - illegal request
+	bool result = false;
 
 	template <typename Handler> void serialize(Handler & h)
 	{
-		h & result;
-		h & packType;
+		h & player;
 		h & requestID;
+		h & packType;
+		h & result;
+	}
+};
+
+struct DLL_LINKAGE PackageReceived : public CPackForClient
+{
+	PackageReceived() = default;
+	PackageReceived(PlayerColor player, uint32_t requestID, uint16_t packType)
+		: player(player)
+		, requestID(requestID)
+		, packType(packType)
+	{
+	}
+
+	void visitTyped(ICPackVisitor & visitor) override;
+
+	/// ID of player that sent this package
+	PlayerColor player;
+	/// request ID, as provided by player
+	uint32_t requestID;
+	/// type id of applied package
+	uint16_t packType;
+
+	template <typename Handler> void serialize(Handler & h)
+	{
 		h & player;
+		h & requestID;
+		h & packType;
 	}
 };
 

+ 14 - 5
server/CGameHandler.cpp

@@ -481,14 +481,23 @@ void CGameHandler::handleReceivedPack(std::shared_ptr<CConnection> connection, C
 	//prepare struct informing that action was applied
 	auto sendPackageResponse = [&](bool successfullyApplied)
 	{
-		PackageApplied applied;
-		applied.player = pack.player;
-		applied.result = successfullyApplied;
-		applied.packType = CTypeList::getInstance().getTypeID(&pack);
-		applied.requestID = pack.requestID;
+		PackageApplied applied(
+			pack.player,
+			pack.requestID,
+			CTypeList::getInstance().getTypeID(&pack),
+			successfullyApplied
+		);
 		connection->sendPack(applied);
 	};
 
+	PackageReceived received(
+		pack.player,
+		pack.requestID,
+		CTypeList::getInstance().getTypeID(&pack)
+	);
+	connection->sendPack(received);
+
+
 	if(isBlockedByQueries(&pack, pack.player))
 	{
 		sendPackageResponse(false);