Browse Source

code review

Laserlicht 2 years ago
parent
commit
c3373ea34c

+ 1 - 1
client/CPlayerInterface.cpp

@@ -1706,7 +1706,7 @@ void CPlayerInterface::requestReturningToMainMenu(bool won)
 			if(!ps->checkVanquished())
 				param.allDefeated = false;
 	}
-	param.land = cb->getMapHeader()->name;
+	param.scenarioName = cb->getMapHeader()->name;
 	HighScoreCalculation highScoreCalc;
 	highScoreCalc.parameters.push_back(param);
 	highScoreCalc.isCampaign = false;

+ 1 - 1
client/CServerHandler.cpp

@@ -684,7 +684,7 @@ void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared
 		highScoreCalc->isCampaign = true;
 		highScoreCalc->parameters.clear();
 	}
-	param.campaign = cs->getName();
+	param.campaignName = cs->getName();
 	highScoreCalc->parameters.push_back(param);
 
 	GH.dispatchMainThread([ourCampaign, this]()

+ 4 - 4
client/mainmenu/CHighScoreScreen.cpp

@@ -156,7 +156,7 @@ void CHighScoreScreen::addHighScores()
 
 		if(highscorepage == HighScorePage::SCENARIO)
 		{
-			std::string tmp = curData["land"].String();
+			std::string tmp = curData["scenarioName"].String();
 			TextOperations::trimRightUnicode(tmp, std::max(0, (int)TextOperations::getUnicodeCharactersCount(tmp) - 25));
 			texts.push_back(std::make_shared<CLabel>(405, y + i * 50, FONT_MEDIUM, ETextAlignment::CENTER, color, tmp));
 			texts.push_back(std::make_shared<CLabel>(557, y + i * 50, FONT_MEDIUM, ETextAlignment::CENTER, color, std::to_string(curData["days"].Integer())));
@@ -164,7 +164,7 @@ void CHighScoreScreen::addHighScores()
 		}
 		else
 		{
-			std::string tmp = curData["campaign"].String();
+			std::string tmp = curData["campaignName"].String();
 			TextOperations::trimRightUnicode(tmp, std::max(0, (int)TextOperations::getUnicodeCharactersCount(tmp) - 25));
 			texts.push_back(std::make_shared<CLabel>(405, y + i * 50, FONT_MEDIUM, ETextAlignment::CENTER, color, tmp));
 			texts.push_back(std::make_shared<CLabel>(592, y + i * 50, FONT_MEDIUM, ETextAlignment::CENTER, color, std::to_string(curData["points"].Integer())));
@@ -259,9 +259,9 @@ int CHighScoreInputScreen::addEntry(std::string text) {
 	JsonNode newNode = JsonNode();
 	newNode["player"].String() = text;
 	if(calc.isCampaign)
-		newNode["campaign"].String() = calc.calculate().cheater ? CGI->generaltexth->translate("core.genrltxt.260") : calc.parameters[0].campaign;
+		newNode["campaignName"].String() = calc.calculate().cheater ? CGI->generaltexth->translate("core.genrltxt.260") : calc.parameters[0].campaignName;
 	else
-		newNode["land"].String() = calc.calculate().cheater ? CGI->generaltexth->translate("core.genrltxt.260") : calc.parameters[0].land;
+		newNode["scenarioName"].String() = calc.calculate().cheater ? CGI->generaltexth->translate("core.genrltxt.260") : calc.parameters[0].scenarioName;
 	newNode["days"].Integer() = calc.calculate().sumDays;
 	newNode["points"].Integer() = calc.calculate().cheater ? 0 : calc.calculate().total;
 	newNode["datetime"].String() = vstd::getFormattedDateTime(std::time(0));

+ 3 - 3
client/mainmenu/CHighScoreScreen.h

@@ -27,8 +27,8 @@ public:
 	bool usedCheat;
 	bool hasGrail;
 	bool allDefeated;
-	std::string campaign;
-	std::string land;
+	std::string campaignName;
+	std::string scenarioName;
 };
 
 class HighScoreCalculation
@@ -68,7 +68,7 @@ private:
 
 	int highlighted;
 public:
-	CHighScoreScreen(HighScorePage highscorepage = HighScorePage::SCENARIO, int highlighted = -1);
+	CHighScoreScreen(HighScorePage highscorepage, int highlighted = -1);
 };
 
 class CHighScoreInput : public CWindowObject

+ 1 - 1
client/mainmenu/CMainMenu.cpp

@@ -392,7 +392,7 @@ void CMainMenu::startTutorial()
 
 void CMainMenu::openHighScoreScreen()
 {
-	GH.windows().createAndPushWindow<CHighScoreScreen>();
+	GH.windows().createAndPushWindow<CHighScoreScreen>(CHighScoreScreen::HighScorePage::SCENARIO);
 	return;
 }
 

+ 19 - 12
server/processors/PlayerMessageProcessor.cpp

@@ -109,11 +109,18 @@ bool PlayerMessageProcessor::handleHostCommand(PlayerColor player, const std::st
 	}
 	if(words.size() == 2 && words[1] == "cheaters")
 	{
-		if (cheaters.empty())
-			broadcastSystemMessage("No cheaters registered!");
+		int playersCheated = 0;
+		for (const auto & player : gameHandler->gameState()->players)
+		{
+			if(player.second.cheated)
+			{
+				broadcastSystemMessage("Player " + player.first.toString() + " is cheater!");
+				playersCheated++;
+			}
+		}
 
-		for (auto const & entry : cheaters)
-			broadcastSystemMessage("Player " + entry.toString() + " is cheater!");
+		if (!playersCheated)
+			broadcastSystemMessage("No cheaters registered!");
 
 		return true;
 	}
@@ -411,7 +418,10 @@ bool PlayerMessageProcessor::handleCheatCode(const std::string & cheat, PlayerCo
 
 		std::vector<std::string> parameters = words;
 
-		cheaters.insert(i.first);
+		PlayerCheated pc;
+		pc.player = i.first;
+		gameHandler->sendAndApply(&pc);
+
 		playerTargetedCheat = true;
 		parameters.erase(parameters.begin());
 
@@ -430,7 +440,10 @@ bool PlayerMessageProcessor::handleCheatCode(const std::string & cheat, PlayerCo
 	if (!playerTargetedCheat)
 		executeCheatCode(cheatName, player, currObj, words);
 
-	cheaters.insert(player);
+	PlayerCheated pc;
+	pc.player = player;
+	gameHandler->sendAndApply(&pc);
+	
 	return true;
 }
 
@@ -513,13 +526,7 @@ void PlayerMessageProcessor::executeCheatCode(const std::string & cheatName, Pla
 
 	assert(callbacks.count(cheatName));
 	if (callbacks.count(cheatName))
-	{
-		PlayerCheated pc;
-		pc.player = player;
-		gameHandler->sendAndApply(&pc);
-
 		callbacks.at(cheatName)();
-	}
 }
 
 void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<CConnection> connection, const std::string & message)

+ 0 - 3
server/processors/PlayerMessageProcessor.h

@@ -21,8 +21,6 @@ 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);
@@ -60,6 +58,5 @@ public:
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
-		h & cheaters;
 	}
 };