1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Merge pull request #2889 from Nordsoft91/mod-compatibility-check

Proper mod compatibility check logic
This commit is contained in:
Nordsoft91
2023-09-26 19:29:46 +02:00
committed by GitHub
29 changed files with 282 additions and 152 deletions

View File

@@ -30,9 +30,9 @@
"vcmi.capitalColors.6" : "褐色", "vcmi.capitalColors.6" : "褐色",
"vcmi.capitalColors.7" : "粉色", "vcmi.capitalColors.7" : "粉色",
"vcmi.server.errors.existingProcess" : "一个VCMI进程已经在运行,启动新进程前请结束它。", "vcmi.server.errors.existingProcess" : "一个VCMI进程已经在运行,启动新进程前请结束它。",
"vcmi.server.errors.modsIncompatibility" : "需要加载的MOD列表:", "vcmi.server.errors.modsToEnable" : "{需要加载的MOD列表}",
"vcmi.server.confirmReconnect" : "您想要重连上一个会话么?", "vcmi.server.confirmReconnect" : "您想要重连上一个会话么?",
"vcmi.settingsMainWindow.generalTab.hover" : "常规", "vcmi.settingsMainWindow.generalTab.hover" : "常规",
"vcmi.settingsMainWindow.generalTab.help" : "切换到“常规”选项卡 - 设置游戏客户端呈现", "vcmi.settingsMainWindow.generalTab.help" : "切换到“常规”选项卡 - 设置游戏客户端呈现",

View File

@@ -48,9 +48,9 @@
"vcmi.lobby.filename" : "Název souboru", "vcmi.lobby.filename" : "Název souboru",
"vcmi.lobby.creationDate" : "Datum vytvoření", "vcmi.lobby.creationDate" : "Datum vytvoření",
"vcmi.server.errors.existingProcess" : "Již běží jiný server VCMI. Prosím, ukončete ho před startem nové hry.", "vcmi.server.errors.existingProcess" : "Již běží jiný server VCMI. Prosím, ukončete ho před startem nové hry.",
"vcmi.server.errors.modsIncompatibility" : "Následující modifikace jsou nutné pro načtení hry:", "vcmi.server.errors.modsToEnable" : "{Následující modifikace jsou nutné pro načtení hry}",
"vcmi.server.confirmReconnect" : "Chcete se připojit k poslední relaci?", "vcmi.server.confirmReconnect" : "Chcete se připojit k poslední relaci?",
"vcmi.settingsMainWindow.generalTab.hover" : "Obecné", "vcmi.settingsMainWindow.generalTab.hover" : "Obecné",
"vcmi.settingsMainWindow.generalTab.help" : "Přepne na kartu obecných nastavení, která obsahuje nastavení související s obecným chováním klienta hry", "vcmi.settingsMainWindow.generalTab.help" : "Přepne na kartu obecných nastavení, která obsahuje nastavení související s obecným chováním klienta hry",

View File

@@ -53,9 +53,10 @@
"vcmi.lobby.filename" : "Filename", "vcmi.lobby.filename" : "Filename",
"vcmi.lobby.creationDate" : "Creation date", "vcmi.lobby.creationDate" : "Creation date",
"vcmi.server.errors.existingProcess" : "Another VCMI server process is running. Please terminate it before starting a new game.", "vcmi.server.errors.existingProcess" : "Another VCMI server process is running. Please terminate it before starting a new game.",
"vcmi.server.errors.modsIncompatibility" : "The following mods are required to load the game:", "vcmi.server.errors.modsToEnable" : "{Following mods are required}",
"vcmi.server.confirmReconnect" : "Do you want to reconnect to the last session?", "vcmi.server.errors.modsToDisable" : "{Following mods must be disabled}",
"vcmi.server.confirmReconnect" : "Do you want to reconnect to the last session?",
"vcmi.settingsMainWindow.generalTab.hover" : "General", "vcmi.settingsMainWindow.generalTab.hover" : "General",
"vcmi.settingsMainWindow.generalTab.help" : "Switches to General Options tab, which contains settings related to general game client behavior.", "vcmi.settingsMainWindow.generalTab.help" : "Switches to General Options tab, which contains settings related to general game client behavior.",

View File

@@ -38,9 +38,9 @@
"vcmi.mainMenu.joinTCP" : "Rejoindre TCP/IP jeu", "vcmi.mainMenu.joinTCP" : "Rejoindre TCP/IP jeu",
"vcmi.mainMenu.playerName" : "Joueur", "vcmi.mainMenu.playerName" : "Joueur",
"vcmi.server.errors.existingProcess" : "Un autre processus de serveur VCMI est en cours d'exécution. Veuillez l'arrêter' avant de démarrer un nouveau jeu.", "vcmi.server.errors.existingProcess" : "Un autre processus de serveur VCMI est en cours d'exécution. Veuillez l'arrêter' avant de démarrer un nouveau jeu.",
"vcmi.server.errors.modsIncompatibility" : "Les mods suivants sont nécessaires pour charger le jeu :", "vcmi.server.errors.modsToEnable" : "{Les mods suivants sont nécessaires pour charger le jeu}",
"vcmi.server.confirmReconnect" : "Voulez-vous vous reconnecter à la dernière session ?", "vcmi.server.confirmReconnect" : "Voulez-vous vous reconnecter à la dernière session ?",
"vcmi.settingsMainWindow.generalTab.hover" : "Général", "vcmi.settingsMainWindow.generalTab.hover" : "Général",
"vcmi.settingsMainWindow.generalTab.help" : "Passe à l'onglet Options générales, qui contient des paramètres liés au comportement général du client de jeu", "vcmi.settingsMainWindow.generalTab.help" : "Passe à l'onglet Options générales, qui contient des paramètres liés au comportement général du client de jeu",

View File

@@ -52,9 +52,9 @@
"vcmi.lobby.filename" : "Dateiname", "vcmi.lobby.filename" : "Dateiname",
"vcmi.lobby.creationDate" : "Erstellungsdatum", "vcmi.lobby.creationDate" : "Erstellungsdatum",
"vcmi.server.errors.existingProcess" : "Es läuft ein weiterer vcmiserver-Prozess, bitte beendet diesen zuerst", "vcmi.server.errors.existingProcess" : "Es läuft ein weiterer vcmiserver-Prozess, bitte beendet diesen zuerst",
"vcmi.server.errors.modsIncompatibility" : "Erforderliche Mods um das Spiel zu laden:", "vcmi.server.errors.modsToEnable" : "{Erforderliche Mods um das Spiel zu laden}",
"vcmi.server.confirmReconnect" : "Mit der letzten Sitzung verbinden?", "vcmi.server.confirmReconnect" : "Mit der letzten Sitzung verbinden?",
"vcmi.settingsMainWindow.generalTab.hover" : "Allgemein", "vcmi.settingsMainWindow.generalTab.hover" : "Allgemein",
"vcmi.settingsMainWindow.generalTab.help" : "Wechselt zur Registerkarte Allgemeine Optionen, die Einstellungen zum allgemeinen Verhalten des Spielclients enthält.", "vcmi.settingsMainWindow.generalTab.help" : "Wechselt zur Registerkarte Allgemeine Optionen, die Einstellungen zum allgemeinen Verhalten des Spielclients enthält.",

View File

@@ -47,9 +47,9 @@
"vcmi.lobby.filename" : "Nazwa pliku", "vcmi.lobby.filename" : "Nazwa pliku",
"vcmi.lobby.creationDate" : "Data utworzenia", "vcmi.lobby.creationDate" : "Data utworzenia",
"vcmi.server.errors.existingProcess" : "Inny proces 'vcmiserver' został już uruchomiony, zakończ go nim przejdziesz dalej", "vcmi.server.errors.existingProcess" : "Inny proces 'vcmiserver' został już uruchomiony, zakończ go nim przejdziesz dalej",
"vcmi.server.errors.modsIncompatibility" : "Następujące mody są wymagane do wczytania gry:", "vcmi.server.errors.modsToEnable" : "{Następujące mody są wymagane do wczytania gry}",
"vcmi.server.confirmReconnect" : "Połączyć ponownie z ostatnią sesją?", "vcmi.server.confirmReconnect" : "Połączyć ponownie z ostatnią sesją?",
"vcmi.settingsMainWindow.generalTab.hover" : "Ogólne", "vcmi.settingsMainWindow.generalTab.hover" : "Ogólne",
"vcmi.settingsMainWindow.generalTab.help" : "Przełącza do zakładki opcji ogólnych, która zawiera ustawienia związane z ogólnym działaniem gry", "vcmi.settingsMainWindow.generalTab.help" : "Przełącza do zakładki opcji ogólnych, która zawiera ustawienia związane z ogólnym działaniem gry",

View File

@@ -21,9 +21,9 @@
"vcmi.adventureMap.moveCostDetails" : "Очки движения - Стоимость: %TURNS ходов + %POINTS очков, Останется: %REMAINING очков", "vcmi.adventureMap.moveCostDetails" : "Очки движения - Стоимость: %TURNS ходов + %POINTS очков, Останется: %REMAINING очков",
"vcmi.adventureMap.moveCostDetailsNoTurns" : "Очки движения - Стоимость: %POINTS очков, Останется: %REMAINING очков", "vcmi.adventureMap.moveCostDetailsNoTurns" : "Очки движения - Стоимость: %POINTS очков, Останется: %REMAINING очков",
"vcmi.server.errors.existingProcess" : "Запущен другой процесс vcmiserver, сначала завершите его.", "vcmi.server.errors.existingProcess" : "Запущен другой процесс vcmiserver, сначала завершите его.",
"vcmi.server.errors.modsIncompatibility" : "Требуемые моды для загрузки игры:", "vcmi.server.errors.modsToEnable" : "{Требуемые моды для загрузки игры}",
"vcmi.server.confirmReconnect" : "Подключиться к предыдущей сессии?", "vcmi.server.confirmReconnect" : "Подключиться к предыдущей сессии?",
"vcmi.settingsMainWindow.generalTab.hover" : "Общее", "vcmi.settingsMainWindow.generalTab.hover" : "Общее",
"vcmi.settingsMainWindow.generalTab.help" : "Переключиться на вкладку \"Общее\", содержащее общие настройки клиента игры", "vcmi.settingsMainWindow.generalTab.help" : "Переключиться на вкладку \"Общее\", содержащее общие настройки клиента игры",

View File

@@ -30,9 +30,9 @@
"vcmi.capitalColors.6" : "Turquesa", "vcmi.capitalColors.6" : "Turquesa",
"vcmi.capitalColors.7" : "Rosa", "vcmi.capitalColors.7" : "Rosa",
"vcmi.server.errors.existingProcess" : "Otro proceso de vcmiserver está en ejecución, por favor termínalo primero", "vcmi.server.errors.existingProcess" : "Otro proceso de vcmiserver está en ejecución, por favor termínalo primero",
"vcmi.server.errors.modsIncompatibility" : "Mods necesarios para cargar el juego:", "vcmi.server.errors.modsToEnable" : "{Mods necesarios para cargar el juego}",
"vcmi.server.confirmReconnect" : "¿Conectar a la última sesión?", "vcmi.server.confirmReconnect" : "¿Conectar a la última sesión?",
"vcmi.settingsMainWindow.generalTab.hover" : "General", "vcmi.settingsMainWindow.generalTab.hover" : "General",
"vcmi.settingsMainWindow.generalTab.help" : "Cambiar a la pestaña de opciones generales, que contiene ajustes relacionados con el comportamiento general del juego", "vcmi.settingsMainWindow.generalTab.help" : "Cambiar a la pestaña de opciones generales, que contiene ajustes relacionados con el comportamiento general del juego",

View File

@@ -48,9 +48,9 @@
"vcmi.lobby.filename" : "Назва файлу", "vcmi.lobby.filename" : "Назва файлу",
"vcmi.lobby.creationDate" : "Дата створення", "vcmi.lobby.creationDate" : "Дата створення",
"vcmi.server.errors.existingProcess" : "Працює інший процес vcmiserver, будь ласка, спочатку завершіть його", "vcmi.server.errors.existingProcess" : "Працює інший процес vcmiserver, будь ласка, спочатку завершіть його",
"vcmi.server.errors.modsIncompatibility" : "Потрібні модифікації для завантаження гри:", "vcmi.server.errors.modsToEnable" : "{Потрібні модифікації для завантаження гри}",
"vcmi.server.confirmReconnect" : "Підключитися до минулої сесії?", "vcmi.server.confirmReconnect" : "Підключитися до минулої сесії?",
"vcmi.settingsMainWindow.generalTab.hover" : "Загальні", "vcmi.settingsMainWindow.generalTab.hover" : "Загальні",
"vcmi.settingsMainWindow.generalTab.help" : "Перемикає на вкладку загальних параметрів, яка містить налаштування, пов'язані із загальною поведінкою ігрового клієнта", "vcmi.settingsMainWindow.generalTab.help" : "Перемикає на вкладку загальних параметрів, яка містить налаштування, пов'язані із загальною поведінкою ігрового клієнта",

View File

@@ -537,6 +537,8 @@ void CServerHandler::sendGuiAction(ui8 action) const
void CServerHandler::sendRestartGame() const void CServerHandler::sendRestartGame() const
{ {
GH.windows().createAndPushWindow<CLoadingScreen>();
LobbyEndGame endGame; LobbyEndGame endGame;
endGame.closeConnection = false; endGame.closeConnection = false;
endGame.restart = true; endGame.restart = true;
@@ -552,10 +554,17 @@ bool CServerHandler::validateGameStart(bool allowOnlyAI) const
catch(ModIncompatibility & e) catch(ModIncompatibility & e)
{ {
logGlobal->warn("Incompatibility exception during start scenario: %s", e.what()); logGlobal->warn("Incompatibility exception during start scenario: %s", e.what());
std::string errorMsg;
auto errorMsg = CGI->generaltexth->translate("vcmi.server.errors.modsIncompatibility") + '\n'; if(!e.whatMissing().empty())
errorMsg += e.what(); {
errorMsg += VLC->generaltexth->translate("vcmi.server.errors.modsToEnable") + '\n';
errorMsg += e.whatMissing();
}
if(!e.whatExcessive().empty())
{
errorMsg += VLC->generaltexth->translate("vcmi.server.errors.modsToDisable") + '\n';
errorMsg += e.whatExcessive();
}
showServerError(errorMsg); showServerError(errorMsg);
return false; return false;
} }
@@ -572,7 +581,8 @@ bool CServerHandler::validateGameStart(bool allowOnlyAI) const
void CServerHandler::sendStartGame(bool allowOnlyAI) const void CServerHandler::sendStartGame(bool allowOnlyAI) const
{ {
verifyStateBeforeStart(allowOnlyAI ? true : settings["session"]["onlyai"].Bool()); verifyStateBeforeStart(allowOnlyAI ? true : settings["session"]["onlyai"].Bool());
GH.windows().createAndPushWindow<CLoadingScreen>();
LobbyStartGame lsg; LobbyStartGame lsg;
if(client) if(client)
{ {
@@ -711,6 +721,9 @@ void CServerHandler::startCampaignScenario(std::shared_ptr<CampaignState> cs)
void CServerHandler::showServerError(const std::string & txt) const void CServerHandler::showServerError(const std::string & txt) const
{ {
if(auto w = GH.windows().topWindow<CLoadingScreen>())
GH.windows().popWindow(w);
CInfoWindow::showInfoDialog(txt, {}); CInfoWindow::showInfoDialog(txt, {});
} }

View File

@@ -149,8 +149,6 @@ void ApplyOnLobbyScreenNetPackVisitor::visitLobbyLoadProgress(LobbyLoadProgress
w->tick(0); w->tick(0);
w->redraw(); w->redraw();
} }
else
GH.windows().createAndPushWindow<CLoadingScreen>();
} }
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyUpdateState(LobbyUpdateState & pack) void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyUpdateState(LobbyUpdateState & pack)

View File

@@ -29,7 +29,6 @@
#include "../../lib/CGeneralTextHandler.h" #include "../../lib/CGeneralTextHandler.h"
#include "../../lib/campaign/CampaignHandler.h" #include "../../lib/campaign/CampaignHandler.h"
#include "../../lib/mapping/CMapInfo.h" #include "../../lib/mapping/CMapInfo.h"
#include "../../lib/modding/ModIncompatibility.h"
#include "../../lib/rmg/CMapGenOptions.h" #include "../../lib/rmg/CMapGenOptions.h"
CLobbyScreen::CLobbyScreen(ESelectionScreen screenType) CLobbyScreen::CLobbyScreen(ESelectionScreen screenType)

View File

@@ -74,12 +74,12 @@ void LobbyInfo::verifyStateBeforeStart(bool ignoreNoHuman) const
throw std::domain_error(VLC->generaltexth->translate("core.genrltxt.529")); throw std::domain_error(VLC->generaltexth->translate("core.genrltxt.529"));
auto missingMods = CMapService::verifyMapHeaderMods(*mi->mapHeader); auto missingMods = CMapService::verifyMapHeaderMods(*mi->mapHeader);
ModIncompatibility::ModList modList; ModIncompatibility::ModListWithVersion modList;
for(const auto & m : missingMods) for(const auto & m : missingMods)
modList.push_back({m.first, m.second.toString()}); modList.push_back({m.second.name, m.second.version.toString()});
if(!modList.empty()) if(!modList.empty())
throw ModIncompatibility(std::move(modList)); throw ModIncompatibility(modList);
//there must be at least one human player before game can be started //there must be at least one human player before game can be started
std::map<PlayerColor, PlayerSettings>::const_iterator i; std::map<PlayerColor, PlayerSettings>::const_iterator i;

View File

@@ -10,7 +10,7 @@
#pragma once #pragma once
#include "../modding/CModVersion.h" #include "../modding/CModInfo.h"
#include "../LogicalExpression.h" #include "../LogicalExpression.h"
#include "../int3.h" #include "../int3.h"
#include "../MetaString.h" #include "../MetaString.h"
@@ -19,7 +19,7 @@ VCMI_LIB_NAMESPACE_BEGIN
class CGObjectInstance; class CGObjectInstance;
enum class EMapFormat : uint8_t; enum class EMapFormat : uint8_t;
using ModCompatibilityInfo = std::map<std::string, CModVersion>; using ModCompatibilityInfo = std::map<std::string, CModInfo::VerificationInfo>;
/// The hero name struct consists of the hero id and the hero name. /// The hero name struct consists of the hero id and the hero name.
struct DLL_LINKAGE SHeroName struct DLL_LINKAGE SHeroName
@@ -249,8 +249,7 @@ public:
void serialize(Handler & h, const int Version) void serialize(Handler & h, const int Version)
{ {
h & version; h & version;
if(Version >= 821) h & mods;
h & mods;
h & name; h & name;
h & description; h & description;
h & width; h & width;

View File

@@ -92,20 +92,29 @@ void CMapService::saveMap(const std::unique_ptr<CMap> & map, boost::filesystem::
ModCompatibilityInfo CMapService::verifyMapHeaderMods(const CMapHeader & map) ModCompatibilityInfo CMapService::verifyMapHeaderMods(const CMapHeader & map)
{ {
ModCompatibilityInfo modCompatibilityInfo;
const auto & activeMods = VLC->modh->getActiveMods(); const auto & activeMods = VLC->modh->getActiveMods();
ModCompatibilityInfo missingMods, missingModsFiltered;
for(const auto & mapMod : map.mods) for(const auto & mapMod : map.mods)
{ {
if(vstd::contains(activeMods, mapMod.first)) if(vstd::contains(activeMods, mapMod.first))
{ {
const auto & modInfo = VLC->modh->getModInfo(mapMod.first); const auto & modInfo = VLC->modh->getModInfo(mapMod.first);
if(modInfo.version.compatible(mapMod.second)) if(modInfo.getVerificationInfo().version.compatible(mapMod.second.version))
continue; continue;
} }
missingMods[mapMod.first] = mapMod.second;
modCompatibilityInfo[mapMod.first] = mapMod.second; }
}
return modCompatibilityInfo; //filter child mods
for(const auto & mapMod : missingMods)
{
if(!mapMod.second.parent.empty() && missingMods.count(mapMod.second.parent))
continue;
missingModsFiltered.insert(mapMod);
}
return missingModsFiltered;
} }
std::unique_ptr<CInputStream> CMapService::getStreamFromFS(const ResourcePath & name) std::unique_ptr<CInputStream> CMapService::getStreamFromFS(const ResourcePath & name)

View File

@@ -10,6 +10,8 @@
#pragma once #pragma once
#include "../modding/CModInfo.h"
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
class ResourcePath; class ResourcePath;
@@ -17,12 +19,11 @@ class ResourcePath;
class CMap; class CMap;
class CMapHeader; class CMapHeader;
class CInputStream; class CInputStream;
struct CModVersion;
class IMapLoader; class IMapLoader;
class IMapPatcher; class IMapPatcher;
using ModCompatibilityInfo = std::map<std::string, CModVersion>; using ModCompatibilityInfo = std::map<std::string, CModInfo::VerificationInfo>;
/** /**
* The map service provides loading of VCMI/H3 map files. It can * The map service provides loading of VCMI/H3 map files. It can

View File

@@ -342,7 +342,7 @@ namespace TerrainDetail
///CMapFormatJson ///CMapFormatJson
const int CMapFormatJson::VERSION_MAJOR = 1; const int CMapFormatJson::VERSION_MAJOR = 1;
const int CMapFormatJson::VERSION_MINOR = 2; const int CMapFormatJson::VERSION_MINOR = 3;
const std::string CMapFormatJson::HEADER_FILE_NAME = "header.json"; const std::string CMapFormatJson::HEADER_FILE_NAME = "header.json";
const std::string CMapFormatJson::OBJECTS_FILE_NAME = "objects.json"; const std::string CMapFormatJson::OBJECTS_FILE_NAME = "objects.json";
@@ -958,7 +958,19 @@ void CMapLoaderJson::readHeader(const bool complete)
if(!header["mods"].isNull()) if(!header["mods"].isNull())
{ {
for(auto & mod : header["mods"].Vector()) for(auto & mod : header["mods"].Vector())
mapHeader->mods[mod["name"].String()] = CModVersion::fromString(mod["version"].String()); {
CModInfo::VerificationInfo info;
info.version = CModVersion::fromString(mod["version"].String());
info.checksum = mod["checksum"].Integer();
info.name = mod["name"].String();
info.parent = mod["parent"].String();
info.impactsGameplay = true;
if(!mod["modId"].isNull())
mapHeader->mods[mod["modId"].String()] = info;
else
mapHeader->mods[mod["name"].String()] = info;
}
} }
//todo: multilevel map load support //todo: multilevel map load support
@@ -1299,8 +1311,11 @@ void CMapSaverJson::writeHeader()
for(const auto & mod : mapHeader->mods) for(const auto & mod : mapHeader->mods)
{ {
JsonNode modWriter; JsonNode modWriter;
modWriter["name"].String() = mod.first; modWriter["modId"].String() = mod.first;
modWriter["version"].String() = mod.second.toString(); modWriter["name"].String() = mod.second.name;
modWriter["parent"].String() = mod.second.parent;
modWriter["version"].String() = mod.second.version.toString();
modWriter["checksum"].Integer() = mod.second.checksum;
mods.Vector().push_back(modWriter); mods.Vector().push_back(modWriter);
} }

View File

@@ -56,7 +56,7 @@ bool CModHandler::hasCircularDependency(const TModID & modID, std::set<TModID> c
if (vstd::contains(currentList, modID)) if (vstd::contains(currentList, modID))
{ {
logMod->error("Error: Circular dependency detected! Printing dependency list:"); logMod->error("Error: Circular dependency detected! Printing dependency list:");
logMod->error("\t%s -> ", mod.name); logMod->error("\t%s -> ", mod.getVerificationInfo().name);
return true; return true;
} }
@@ -67,7 +67,7 @@ bool CModHandler::hasCircularDependency(const TModID & modID, std::set<TModID> c
{ {
if (hasCircularDependency(dependency, currentList)) if (hasCircularDependency(dependency, currentList))
{ {
logMod->error("\t%s ->\n", mod.name); // conflict detected, print dependency list logMod->error("\t%s ->\n", mod.getVerificationInfo().name); // conflict detected, print dependency list
return true; return true;
} }
} }
@@ -129,7 +129,7 @@ std::vector <TModID> CModHandler::validateAndSortDependencies(std::vector <TModI
for(const TModID & dependency : brokenMod.dependencies) for(const TModID & dependency : brokenMod.dependencies)
{ {
if(!vstd::contains(resolvedModIDs, dependency)) if(!vstd::contains(resolvedModIDs, dependency))
logMod->error("Mod '%s' will not work: it depends on mod '%s', which is not installed.", brokenMod.name, dependency); logMod->error("Mod '%s' will not work: it depends on mod '%s', which is not installed.", brokenMod.getVerificationInfo().name, dependency);
} }
} }
return sortedValidMods; return sortedValidMods;
@@ -212,7 +212,6 @@ void CModHandler::loadMods(bool onlyEssential)
} }
coreMod = std::make_unique<CModInfo>(ModScope::scopeBuiltin(), modConfig[ModScope::scopeBuiltin()], JsonNode(JsonPath::builtin("config/gameConfig.json"))); coreMod = std::make_unique<CModInfo>(ModScope::scopeBuiltin(), modConfig[ModScope::scopeBuiltin()], JsonNode(JsonPath::builtin("config/gameConfig.json")));
coreMod->name = "Original game files";
} }
std::vector<std::string> CModHandler::getAllMods() std::vector<std::string> CModHandler::getAllMods()
@@ -352,7 +351,7 @@ void CModHandler::initializeConfig()
CModVersion CModHandler::getModVersion(TModID modName) const CModVersion CModHandler::getModVersion(TModID modName) const
{ {
if (allMods.count(modName)) if (allMods.count(modName))
return allMods.at(modName).version; return allMods.at(modName).getVerificationInfo().version;
return {}; return {};
} }
@@ -462,6 +461,7 @@ void CModHandler::afterLoad(bool onlyEssential)
modSettings["activeMods"].resolvePointer(pointer) = modEntry.second.saveLocalData(); modSettings["activeMods"].resolvePointer(pointer) = modEntry.second.saveLocalData();
} }
modSettings[ModScope::scopeBuiltin()] = coreMod->saveLocalData(); modSettings[ModScope::scopeBuiltin()] = coreMod->saveLocalData();
modSettings[ModScope::scopeBuiltin()]["name"].String() = "Original game files";
if(!onlyEssential) if(!onlyEssential)
{ {
@@ -471,49 +471,85 @@ void CModHandler::afterLoad(bool onlyEssential)
} }
void CModHandler::trySetActiveMods(std::vector<TModID> saveActiveMods, const std::map<TModID, CModVersion> & modList) void CModHandler::trySetActiveMods(const std::vector<std::pair<TModID, CModInfo::VerificationInfo>> & modList)
{ {
std::vector<TModID> newActiveMods; auto searchVerificationInfo = [&modList](const TModID & m) -> const CModInfo::VerificationInfo*
{
ModIncompatibility::ModList missingMods; for(auto & i : modList)
if(i.first == m)
return &i.second;
return nullptr;
};
std::vector<TModID> missingMods, excessiveMods;
ModIncompatibility::ModListWithVersion missingModsResult;
ModIncompatibility::ModList excessiveModsResult;
for(const auto & m : activeMods) for(const auto & m : activeMods)
{ {
if (vstd::contains(saveActiveMods, m)) if(searchVerificationInfo(m))
continue; continue;
auto & modInfo = allMods.at(m); //TODO: support actual disabling of these mods
if(modInfo.checkModGameplayAffecting()) if(getModInfo(m).checkModGameplayAffecting())
missingMods.emplace_back(m, modInfo.version.toString()); excessiveMods.push_back(m);
} }
for(const auto & m : saveActiveMods) for(const auto & infoPair : modList)
{ {
const CModVersion & mver = modList.at(m); auto & remoteModId = infoPair.first;
auto & remoteModInfo = infoPair.second;
if (allMods.count(m) == 0)
bool modAffectsGameplay = remoteModInfo.impactsGameplay;
//parent mod affects gameplay if child affects too
for(const auto & subInfoPair : modList)
modAffectsGameplay |= (subInfoPair.second.impactsGameplay && subInfoPair.second.parent == remoteModId);
if(!allMods.count(remoteModId))
{ {
missingMods.emplace_back(m, mver.toString()); if(modAffectsGameplay)
missingMods.push_back(remoteModId); //mod is not installed
continue; continue;
} }
auto & modInfo = allMods.at(m); auto & localModInfo = getModInfo(remoteModId).getVerificationInfo();
modAffectsGameplay |= getModInfo(remoteModId).checkModGameplayAffecting();
bool modAffectsGameplay = modInfo.checkModGameplayAffecting(); bool modVersionCompatible = localModInfo.version.isNull()
bool modVersionCompatible = modInfo.version.isNull() || mver.isNull() || modInfo.version.compatible(mver); || remoteModInfo.version.isNull()
bool modEnabledLocally = vstd::contains(activeMods, m); || localModInfo.version.compatible(remoteModInfo.version);
bool modCanBeEnabled = modEnabledLocally && modVersionCompatible; bool modLocalyEnabled = vstd::contains(activeMods, remoteModId);
allMods[m].setEnabled(modCanBeEnabled); if(modVersionCompatible && modAffectsGameplay && modLocalyEnabled)
continue;
if (modCanBeEnabled)
newActiveMods.push_back(m); if(modAffectsGameplay)
missingMods.push_back(remoteModId); //incompatible mod impacts gameplay
if (!modCanBeEnabled && modAffectsGameplay)
missingMods.emplace_back(m, mver.toString());
} }
std::swap(activeMods, newActiveMods); //filter mods
for(auto & m : missingMods)
{
if(auto * vInfo = searchVerificationInfo(m))
{
assert(vInfo->parent != m);
if(!vInfo->parent.empty() && vstd::contains(missingMods, vInfo->parent))
continue;
missingModsResult.push_back({vInfo->name, vInfo->version.toString()});
}
}
for(auto & m : excessiveMods)
{
auto & vInfo = getModInfo(m).getVerificationInfo();
assert(vInfo.parent != m);
if(!vInfo.parent.empty() && vstd::contains(excessiveMods, vInfo.parent))
continue;
excessiveModsResult.push_back(vInfo.name);
}
if(!missingModsResult.empty() || !excessiveModsResult.empty())
throw ModIncompatibility(missingModsResult, excessiveModsResult);
//TODO: support actual enabling of required mods
} }
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@@ -9,13 +9,12 @@
*/ */
#pragma once #pragma once
#include "CModVersion.h" #include "CModInfo.h"
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
class CModHandler; class CModHandler;
class CModIndentifier; class CModIndentifier;
class CModInfo;
class JsonNode; class JsonNode;
class IHandlerBase; class IHandlerBase;
class CIdentifierStorage; class CIdentifierStorage;
@@ -52,7 +51,7 @@ class DLL_LINKAGE CModHandler : boost::noncopyable
CModVersion getModVersion(TModID modName) const; CModVersion getModVersion(TModID modName) const;
/// Attempt to set active mods according to provided list of mods from save, throws on failure /// Attempt to set active mods according to provided list of mods from save, throws on failure
void trySetActiveMods(std::vector<TModID> saveActiveMods, const std::map<TModID, CModVersion> & modList); void trySetActiveMods(const std::vector<std::pair<TModID, CModInfo::VerificationInfo>> & modList);
public: public:
std::shared_ptr<CContentHandler> content; //(!)Do not serialize FIXME: make private std::shared_ptr<CContentHandler> content; //(!)Do not serialize FIXME: make private
@@ -88,22 +87,22 @@ public:
{ {
h & activeMods; h & activeMods;
for(const auto & m : activeMods) for(const auto & m : activeMods)
{ h & getModInfo(m).getVerificationInfo();
CModVersion version = getModVersion(m);
h & version;
}
} }
else else
{ {
loadMods(); loadMods();
std::vector<TModID> saveActiveMods; std::vector<TModID> saveActiveMods;
std::map<TModID, CModVersion> modVersions;
h & saveActiveMods; h & saveActiveMods;
std::vector<std::pair<TModID, CModInfo::VerificationInfo>> saveModInfos(saveActiveMods.size());
for(int i = 0; i < saveActiveMods.size(); ++i)
{
saveModInfos[i].first = saveActiveMods[i];
h & saveModInfos[i].second;
}
for(const auto & m : saveActiveMods) trySetActiveMods(saveModInfos);
h & modVersions[m];
trySetActiveMods(saveActiveMods, modVersions);
} }
} }
}; };

View File

@@ -23,7 +23,6 @@ static JsonNode addMeta(JsonNode config, const std::string & meta)
} }
CModInfo::CModInfo(): CModInfo::CModInfo():
checksum(0),
explicitlyEnabled(false), explicitlyEnabled(false),
implicitlyEnabled(true), implicitlyEnabled(true),
validation(PENDING) validation(PENDING)
@@ -33,17 +32,20 @@ CModInfo::CModInfo():
CModInfo::CModInfo(const std::string & identifier, const JsonNode & local, const JsonNode & config): CModInfo::CModInfo(const std::string & identifier, const JsonNode & local, const JsonNode & config):
identifier(identifier), identifier(identifier),
name(config["name"].String()),
description(config["description"].String()), description(config["description"].String()),
dependencies(config["depends"].convertTo<std::set<std::string>>()), dependencies(config["depends"].convertTo<std::set<std::string>>()),
conflicts(config["conflicts"].convertTo<std::set<std::string>>()), conflicts(config["conflicts"].convertTo<std::set<std::string>>()),
checksum(0),
explicitlyEnabled(false), explicitlyEnabled(false),
implicitlyEnabled(true), implicitlyEnabled(true),
validation(PENDING), validation(PENDING),
config(addMeta(config, identifier)) config(addMeta(config, identifier))
{ {
version = CModVersion::fromString(config["version"].String()); verificationInfo.name = config["name"].String();
verificationInfo.version = CModVersion::fromString(config["version"].String());
verificationInfo.parent = identifier.substr(0, identifier.find_last_of('.'));
if(verificationInfo.parent == identifier)
verificationInfo.parent.clear();
if(!config["compatibility"].isNull()) if(!config["compatibility"].isNull())
{ {
vcmiCompatibleMin = CModVersion::fromString(config["compatibility"]["min"].String()); vcmiCompatibleMin = CModVersion::fromString(config["compatibility"]["min"].String());
@@ -61,7 +63,7 @@ CModInfo::CModInfo(const std::string & identifier, const JsonNode & local, const
JsonNode CModInfo::saveLocalData() const JsonNode CModInfo::saveLocalData() const
{ {
std::ostringstream stream; std::ostringstream stream;
stream << std::noshowbase << std::hex << std::setw(8) << std::setfill('0') << checksum; stream << std::noshowbase << std::hex << std::setw(8) << std::setfill('0') << verificationInfo.checksum;
JsonNode conf; JsonNode conf;
conf["active"].Bool() = explicitlyEnabled; conf["active"].Bool() = explicitlyEnabled;
@@ -83,9 +85,9 @@ JsonPath CModInfo::getModFile(const std::string & name)
void CModInfo::updateChecksum(ui32 newChecksum) void CModInfo::updateChecksum(ui32 newChecksum)
{ {
// comment-out next line to force validation of all mods ignoring checksum // comment-out next line to force validation of all mods ignoring checksum
if (newChecksum != checksum) if (newChecksum != verificationInfo.checksum)
{ {
checksum = newChecksum; verificationInfo.checksum = newChecksum;
validation = PENDING; validation = PENDING;
} }
} }
@@ -95,7 +97,7 @@ void CModInfo::loadLocalData(const JsonNode & data)
bool validated = false; bool validated = false;
implicitlyEnabled = true; implicitlyEnabled = true;
explicitlyEnabled = !config["keepDisabled"].Bool(); explicitlyEnabled = !config["keepDisabled"].Bool();
checksum = 0; verificationInfo.checksum = 0;
if (data.getType() == JsonNode::JsonType::DATA_BOOL) if (data.getType() == JsonNode::JsonType::DATA_BOOL)
{ {
explicitlyEnabled = data.Bool(); explicitlyEnabled = data.Bool();
@@ -104,7 +106,7 @@ void CModInfo::loadLocalData(const JsonNode & data)
{ {
explicitlyEnabled = data["active"].Bool(); explicitlyEnabled = data["active"].Bool();
validated = data["validated"].Bool(); validated = data["validated"].Bool();
checksum = strtol(data["checksum"].String().c_str(), nullptr, 16); updateChecksum(strtol(data["checksum"].String().c_str(), nullptr, 16));
} }
//check compatibility //check compatibility
@@ -112,13 +114,13 @@ void CModInfo::loadLocalData(const JsonNode & data)
implicitlyEnabled &= (vcmiCompatibleMax.isNull() || vcmiCompatibleMax.compatible(CModVersion::GameVersion(), true, true)); implicitlyEnabled &= (vcmiCompatibleMax.isNull() || vcmiCompatibleMax.compatible(CModVersion::GameVersion(), true, true));
if(!implicitlyEnabled) if(!implicitlyEnabled)
logGlobal->warn("Mod %s is incompatible with current version of VCMI and cannot be enabled", name); logGlobal->warn("Mod %s is incompatible with current version of VCMI and cannot be enabled", verificationInfo.name);
if (boost::iequals(config["modType"].String(), "translation")) // compatibility code - mods use "Translation" type at the moment if (boost::iequals(config["modType"].String(), "translation")) // compatibility code - mods use "Translation" type at the moment
{ {
if (baseLanguage != VLC->generaltexth->getPreferredLanguage()) if (baseLanguage != VLC->generaltexth->getPreferredLanguage())
{ {
logGlobal->warn("Translation mod %s was not loaded: language mismatch!", name); logGlobal->warn("Translation mod %s was not loaded: language mismatch!", verificationInfo.name);
implicitlyEnabled = false; implicitlyEnabled = false;
} }
} }
@@ -127,6 +129,8 @@ void CModInfo::loadLocalData(const JsonNode & data)
validation = validated ? PASSED : PENDING; validation = validated ? PASSED : PENDING;
else else
validation = validated ? PASSED : FAILED; validation = validated ? PASSED : FAILED;
verificationInfo.impactsGameplay = checkModGameplayAffecting();
} }
bool CModInfo::checkModGameplayAffecting() const bool CModInfo::checkModGameplayAffecting() const
@@ -171,6 +175,11 @@ bool CModInfo::checkModGameplayAffecting() const
return *modGameplayAffecting; return *modGameplayAffecting;
} }
const CModInfo::VerificationInfo & CModInfo::getVerificationInfo() const
{
return verificationInfo;
}
bool CModInfo::isEnabled() const bool CModInfo::isEnabled() const
{ {
return implicitlyEnabled && explicitlyEnabled; return implicitlyEnabled && explicitlyEnabled;

View File

@@ -29,17 +29,41 @@ public:
FAILED, FAILED,
PASSED PASSED
}; };
struct VerificationInfo
{
/// human-readable mod name
std::string name;
/// version of the mod
CModVersion version;
/// CRC-32 checksum of the mod
ui32 checksum = 0;
/// parent mod ID, empty if root-level mod
TModID parent;
/// for serialization purposes
bool impactsGameplay = true;
template <typename Handler>
void serialize(Handler & h, const int v)
{
h & name;
h & version;
h & checksum;
h & parent;
h & impactsGameplay;
}
};
/// identifier, identical to name of folder with mod /// identifier, identical to name of folder with mod
std::string identifier; std::string identifier;
/// human-readable strings /// detailed mod description
std::string name;
std::string description; std::string description;
/// version of the mod
CModVersion version;
/// Base language of mod, all mod strings are assumed to be in this language /// Base language of mod, all mod strings are assumed to be in this language
std::string baseLanguage; std::string baseLanguage;
@@ -52,9 +76,6 @@ public:
/// list of mods that can't be used in the same time as this one /// list of mods that can't be used in the same time as this one
std::set <TModID> conflicts; std::set <TModID> conflicts;
/// CRC-32 checksum of the mod
ui32 checksum;
EValidationStatus validation; EValidationStatus validation;
JsonNode config; JsonNode config;
@@ -73,6 +94,8 @@ public:
/// return true if this mod can affect gameplay, e.g. adds or modifies any game objects /// return true if this mod can affect gameplay, e.g. adds or modifies any game objects
bool checkModGameplayAffecting() const; bool checkModGameplayAffecting() const;
const VerificationInfo & getVerificationInfo() const;
private: private:
/// true if mod is enabled by user, e.g. in Launcher UI /// true if mod is enabled by user, e.g. in Launcher UI
@@ -80,6 +103,8 @@ private:
/// true if mod can be loaded - compatible and has no missing deps /// true if mod can be loaded - compatible and has no missing deps
bool implicitlyEnabled; bool implicitlyEnabled;
VerificationInfo verificationInfo;
void loadLocalData(const JsonNode & data); void loadLocalData(const JsonNode & data);
}; };

View File

@@ -212,7 +212,8 @@ void CContentHandler::preloadData(CModInfo & mod)
bool validate = (mod.validation != CModInfo::PASSED); bool validate = (mod.validation != CModInfo::PASSED);
// print message in format [<8-symbols checksum>] <modname> // print message in format [<8-symbols checksum>] <modname>
logMod->info("\t\t[%08x]%s", mod.checksum, mod.name); auto & info = mod.getVerificationInfo();
logMod->info("\t\t[%08x]%s", info.checksum, info.name);
if (validate && mod.identifier != ModScope::scopeBuiltin()) if (validate && mod.identifier != ModScope::scopeBuiltin())
{ {
@@ -233,12 +234,12 @@ void CContentHandler::load(CModInfo & mod)
if (validate) if (validate)
{ {
if (mod.validation != CModInfo::FAILED) if (mod.validation != CModInfo::FAILED)
logMod->info("\t\t[DONE] %s", mod.name); logMod->info("\t\t[DONE] %s", mod.getVerificationInfo().name);
else else
logMod->error("\t\t[FAIL] %s", mod.name); logMod->error("\t\t[FAIL] %s", mod.getVerificationInfo().name);
} }
else else
logMod->info("\t\t[SKIP] %s", mod.name); logMod->info("\t\t[SKIP] %s", mod.getVerificationInfo().name);
} }
const ContentTypeHandler & CContentHandler::operator[](const std::string & name) const const ContentTypeHandler & CContentHandler::operator[](const std::string & name) const

View File

@@ -14,29 +14,44 @@ VCMI_LIB_NAMESPACE_BEGIN
class DLL_LINKAGE ModIncompatibility: public std::exception class DLL_LINKAGE ModIncompatibility: public std::exception
{ {
public: public:
using StringPair = std::pair<const std::string, const std::string>; using ModListWithVersion = std::vector<std::pair<const std::string, const std::string>>;
using ModList = std::list<StringPair>; using ModList = std::vector<std::string>;
ModIncompatibility(ModList && _missingMods): ModIncompatibility(const ModListWithVersion & _missingMods)
missingMods(std::move(_missingMods))
{ {
std::ostringstream _ss; std::ostringstream _ss;
for(const auto & m : missingMods) for(const auto & m : _missingMods)
_ss << m.first << ' ' << m.second << std::endl; _ss << m.first << ' ' << m.second << std::endl;
message = _ss.str(); messageMissingMods = _ss.str();
} }
ModIncompatibility(const ModListWithVersion & _missingMods, ModList & _excessiveMods)
: ModIncompatibility(_missingMods)
{
std::ostringstream _ss;
for(const auto & m : _excessiveMods)
_ss << m << std::endl;
messageExcessiveMods = _ss.str();
}
const char * what() const noexcept override const char * what() const noexcept override
{ {
return message.c_str(); static const std::string w("Mod incompatibility exception");
return w.c_str();
}
const std::string & whatMissing() const noexcept
{
return messageMissingMods;
}
const std::string & whatExcessive() const noexcept
{
return messageExcessiveMods;
} }
private: private:
//list of mods required to load the game std::string messageMissingMods, messageExcessiveMods;
// first: mod name
// second: mod version
const ModList missingMods;
std::string message;
}; };
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@@ -336,19 +336,20 @@ bool MainWindow::openMap(const QString & filenameSelect)
if(auto header = mapService.loadMapHeader(resId)) if(auto header = mapService.loadMapHeader(resId))
{ {
auto missingMods = CMapService::verifyMapHeaderMods(*header); auto missingMods = CMapService::verifyMapHeaderMods(*header);
ModIncompatibility::ModList modList; ModIncompatibility::ModListWithVersion modList;
for(const auto & m : missingMods) for(const auto & m : missingMods)
modList.push_back({m.first, m.second.toString()}); modList.push_back({m.second.name, m.second.version.toString()});
if(!modList.empty()) if(!modList.empty())
throw ModIncompatibility(std::move(modList)); throw ModIncompatibility(modList);
controller.setMap(mapService.loadMap(resId)); controller.setMap(mapService.loadMap(resId));
} }
} }
catch(const ModIncompatibility & e) catch(const ModIncompatibility & e)
{ {
QMessageBox::warning(this, "Mods requiered", e.what()); assert(e.whatExcessive().empty());
QMessageBox::warning(this, "Mods are requiered", QString::fromStdString(e.whatMissing()));
return false; return false;
} }
catch(const std::exception & e) catch(const std::exception & e)

View File

@@ -588,7 +588,7 @@ ModCompatibilityInfo MapController::modAssessmentAll()
auto handler = VLC->objtypeh->getHandlerFor(primaryID, secondaryID); auto handler = VLC->objtypeh->getHandlerFor(primaryID, secondaryID);
auto modName = QString::fromStdString(handler->getJsonKey()).split(":").at(0).toStdString(); auto modName = QString::fromStdString(handler->getJsonKey()).split(":").at(0).toStdString();
if(modName != "core") if(modName != "core")
result[modName] = VLC->modh->getModInfo(modName).version; result[modName] = VLC->modh->getModInfo(modName).getVerificationInfo();
} }
} }
return result; return result;
@@ -605,7 +605,7 @@ ModCompatibilityInfo MapController::modAssessmentMap(const CMap & map)
auto handler = VLC->objtypeh->getHandlerFor(obj->ID, obj->subID); auto handler = VLC->objtypeh->getHandlerFor(obj->ID, obj->subID);
auto modName = QString::fromStdString(handler->getJsonKey()).split(":").at(0).toStdString(); auto modName = QString::fromStdString(handler->getJsonKey()).split(":").at(0).toStdString();
if(modName != "core") if(modName != "core")
result[modName] = VLC->modh->getModInfo(modName).version; result[modName] = VLC->modh->getModInfo(modName).getVerificationInfo();
} }
//TODO: terrains? //TODO: terrains?
return result; return result;

View File

@@ -13,10 +13,10 @@
#include "maphandler.h" #include "maphandler.h"
#include "mapview.h" #include "mapview.h"
#include "../lib/modding/CModVersion.h" #include "../lib/modding/CModInfo.h"
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
using ModCompatibilityInfo = std::map<std::string, CModVersion>; using ModCompatibilityInfo = std::map<std::string, CModInfo::VerificationInfo>;
class EditorObstaclePlacer; class EditorObstaclePlacer;
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@@ -47,7 +47,7 @@ void ModSettings::initialize(MapController & c)
auto createModTreeWidgetItem = [&](QTreeWidgetItem * parent, const CModInfo & modInfo) auto createModTreeWidgetItem = [&](QTreeWidgetItem * parent, const CModInfo & modInfo)
{ {
auto item = new QTreeWidgetItem(parent, {QString::fromStdString(modInfo.name), QString::fromStdString(modInfo.version.toString())}); auto item = new QTreeWidgetItem(parent, {QString::fromStdString(modInfo.getVerificationInfo().name), QString::fromStdString(modInfo.getVerificationInfo().version.toString())});
item->setData(0, Qt::UserRole, QVariant(QString::fromStdString(modInfo.identifier))); item->setData(0, Qt::UserRole, QVariant(QString::fromStdString(modInfo.identifier)));
item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(0, controller->map()->mods.count(modInfo.identifier) ? Qt::Checked : Qt::Unchecked); item->setCheckState(0, controller->map()->mods.count(modInfo.identifier) ? Qt::Checked : Qt::Unchecked);
@@ -104,7 +104,7 @@ void ModSettings::update()
if(item->checkState(0) == Qt::Checked) if(item->checkState(0) == Qt::Checked)
{ {
auto modName = item->data(0, Qt::UserRole).toString().toStdString(); auto modName = item->data(0, Qt::UserRole).toString().toStdString();
controller->map()->mods[modName] = VLC->modh->getModInfo(modName).version; controller->map()->mods[modName] = VLC->modh->getModInfo(modName).getVerificationInfo();
} }
}; };

View File

@@ -174,7 +174,7 @@ std::list<Validator::Issue> Validator::validate(const CMap * map)
{ {
if(!map->mods.count(mod.first)) if(!map->mods.count(mod.first))
{ {
issues.emplace_back(QString(tr("Map contains object from mod \"%1\", but doesn't require it")).arg(QString::fromStdString(VLC->modh->getModInfo(mod.first).name)), true); issues.emplace_back(QString(tr("Map contains object from mod \"%1\", but doesn't require it")).arg(QString::fromStdString(VLC->modh->getModInfo(mod.first).getVerificationInfo().name)), true);
} }
} }
} }

View File

@@ -1768,8 +1768,17 @@ bool CGameHandler::load(const std::string & filename)
catch(const ModIncompatibility & e) catch(const ModIncompatibility & e)
{ {
logGlobal->error("Failed to load game: %s", e.what()); logGlobal->error("Failed to load game: %s", e.what());
auto errorMsg = VLC->generaltexth->translate("vcmi.server.errors.modsIncompatibility") + '\n'; std::string errorMsg;
errorMsg += e.what(); if(!e.whatMissing().empty())
{
errorMsg += VLC->generaltexth->translate("vcmi.server.errors.modsToEnable") + '\n';
errorMsg += e.whatMissing();
}
if(!e.whatExcessive().empty())
{
errorMsg += VLC->generaltexth->translate("vcmi.server.errors.modsToDisable") + '\n';
errorMsg += e.whatExcessive();
}
lobby->announceMessage(errorMsg); lobby->announceMessage(errorMsg);
return false; return false;
} }