浏览代码

Publish if cheats or unlimited replays allowed to all players

Laserlicht 1 年之前
父节点
当前提交
8b59b78003
共有 4 个文件被更改,包括 47 次插入2 次删除
  1. 5 1
      Mods/vcmi/config/vcmi/english.json
  2. 5 1
      Mods/vcmi/config/vcmi/german.json
  3. 35 0
      server/CVCMIServer.cpp
  4. 2 0
      server/CVCMIServer.h

+ 5 - 1
Mods/vcmi/config/vcmi/english.json

@@ -63,7 +63,11 @@
 	"vcmi.mainMenu.serverClosing" : "Closing...",
 	"vcmi.mainMenu.hostTCP" : "Host TCP/IP game",
 	"vcmi.mainMenu.joinTCP" : "Join TCP/IP game",
-	
+
+	"vcmi.multiplayerWelcomeMessage.additionalSettings" : "Additional settings",
+	"vcmi.multiplayerWelcomeMessage.cheatsAllowed" : "Cheats allowed",
+	"vcmi.multiplayerWelcomeMessage.unlimitedReplays" : "Unlimited battle replays",
+
 	"vcmi.lobby.filepath" : "File path",
 	"vcmi.lobby.creationDate" : "Creation date",
 	"vcmi.lobby.scenarioName" : "Scenario name",

+ 5 - 1
Mods/vcmi/config/vcmi/german.json

@@ -63,7 +63,11 @@
 	"vcmi.mainMenu.serverClosing" : "Trenne...",
 	"vcmi.mainMenu.hostTCP" : "Hoste TCP/IP Spiel",
 	"vcmi.mainMenu.joinTCP" : "Trete TCP/IP Spiel bei",
-	
+
+	"vcmi.multiplayerWelcomeMessage.additionalSettings" : "Zusätzliche Einstellungen",
+	"vcmi.multiplayerWelcomeMessage.cheatsAllowed" : "Cheats erlaubt",
+	"vcmi.multiplayerWelcomeMessage.unlimitedReplays" : "Unbegrenzte Kampfwiederholungen",
+
 	"vcmi.lobby.filepath" : "Dateipfad",
 	"vcmi.lobby.creationDate" : "Erstellungsdatum",
 	"vcmi.lobby.scenarioName" : "Szenario-Name",

+ 35 - 0
server/CVCMIServer.cpp

@@ -16,6 +16,7 @@
 #include "processors/PlayerMessageProcessor.h"
 
 #include "../lib/CHeroHandler.h"
+#include "../lib/CPlayerState.h"
 #include "../lib/MetaString.h"
 #include "../lib/registerTypes/RegisterTypesLobbyPacks.h"
 #include "../lib/serializer/CMemorySerializer.h"
@@ -332,6 +333,8 @@ void CVCMIServer::startGameImmediately()
 	setState(EServerState::GAMEPLAY);
 	lastTimerUpdateTime = gameplayStartTime = std::chrono::steady_clock::now();
 	onTimer();
+
+	multiplayerWelcomeMessage();
 }
 
 void CVCMIServer::onDisconnected(const std::shared_ptr<INetworkConnection> & connection, const std::string & errorMessage)
@@ -979,6 +982,38 @@ ui8 CVCMIServer::getIdOfFirstUnallocatedPlayer() const
 	return 0;
 }
 
+void CVCMIServer::multiplayerWelcomeMessage()
+{
+	int humanPlayer = 0;
+	for (auto & pi : si->playerInfos)
+        if(gh->getPlayerState(pi.first)->isHuman())
+			humanPlayer++;
+
+	if(humanPlayer < 2) // Singleplayer
+		return;
+
+	std::vector<std::string> optionIds;
+	if(si->extraOptionsInfo.cheatsAllowed)
+		optionIds.push_back("vcmi.multiplayerWelcomeMessage.cheatsAllowed");
+	if(si->extraOptionsInfo.unlimitedReplay)
+		optionIds.push_back("vcmi.multiplayerWelcomeMessage.unlimitedReplays");
+
+	if(!optionIds.size()) // No settings to publish
+		return;
+
+	MetaString str;
+	str.appendTextID("vcmi.multiplayerWelcomeMessage.additionalSettings");
+	str.appendRawString(": ");
+	for(int i = 0; i < optionIds.size(); i++)
+	{
+		str.appendTextID(optionIds[i]);
+		if(i < optionIds.size() - 1)
+			str.appendRawString(", ");
+	}
+
+	gh->playerMessages->broadcastSystemMessage(str);
+}
+
 INetworkHandler & CVCMIServer::getNetworkHandler()
 {
 	return *networkHandler;

+ 2 - 0
server/CVCMIServer.h

@@ -130,4 +130,6 @@ public:
 	void setCampaignBonus(int bonusId);
 
 	ui8 getIdOfFirstUnallocatedPlayer() const;
+
+	void multiplayerWelcomeMessage();
 };