浏览代码

Store cheater state per player

Ivan Savenko 2 年之前
父节点
当前提交
fcb13771f3
共有 2 个文件被更改,包括 17 次插入3 次删除
  1. 12 0
      server/PlayerMessageProcessor.cpp
  2. 5 3
      server/PlayerMessageProcessor.h

+ 12 - 0
server/PlayerMessageProcessor.cpp

@@ -105,6 +105,16 @@ bool PlayerMessageProcessor::handleHostCommand(PlayerColor player, const std::st
 		}
 		return true;
 	}
+	if(words.size() == 2 && words[1] == "cheaters")
+	{
+		if (cheaters.empty())
+			broadcastSystemMessage("No cheaters registered!");
+
+		for (auto const & entry : cheaters)
+			broadcastSystemMessage("Player " + entry.getStr() + " is cheater!");
+
+		return true;
+	}
 
 	return false;
 }
@@ -384,6 +394,7 @@ bool PlayerMessageProcessor::handleCheatCode(const std::string & cheat, PlayerCo
 
 		std::vector<std::string> parameters = words;
 
+		cheaters.insert(i.first);
 		playerTargetedCheat = true;
 		parameters.erase(parameters.begin());
 
@@ -402,6 +413,7 @@ bool PlayerMessageProcessor::handleCheatCode(const std::string & cheat, PlayerCo
 	if (!playerTargetedCheat)
 		executeCheatCode(cheatName, player, currObj, words);
 
+	cheaters.insert(player);
 	return true;
 }
 

+ 5 - 3
server/PlayerMessageProcessor.h

@@ -9,9 +9,9 @@
  */
 #pragma once
 
+#include "../lib/GameConstants.h"
+
 VCMI_LIB_NAMESPACE_BEGIN
-class PlayerColor;
-class ObjectInstanceID;
 class CGHeroInstance;
 class CGTownInstance;
 class CConnection;
@@ -21,6 +21,8 @@ class CGameHandler;
 
 class PlayerMessageProcessor
 {
+	std::set<PlayerColor> cheaters;
+
 	void executeCheatCode(const std::string & cheatName, PlayerColor player, ObjectInstanceID currObj, const std::vector<std::string> & arguments );
 	bool handleCheatCode(const std::string & cheatFullCommand, PlayerColor player, ObjectInstanceID currObj);
 	bool handleHostCommand(PlayerColor player, const std::string & message);
@@ -58,6 +60,6 @@ public:
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
-
+		h & cheaters;
 	}
 };