From 2d10fa786792a27adb4097abe8c92f36cf47e6ce Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 19 Aug 2022 12:31:36 +0100 Subject: [PATCH] Prevent loading a world with unresolved dependencies (#12542) --- src/client/client.cpp | 3 ++- src/content/mod_configuration.cpp | 21 ++++++++++++++++----- src/content/mod_configuration.h | 2 +- src/server.cpp | 8 ++------ src/server/mods.h | 4 ++-- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index b7d1cbfe0..35634e77b 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -213,9 +213,10 @@ void Client::loadMods() } m_mods = modconf.getMods(); + // complain about mods with unsatisfied dependencies if (!modconf.isConsistent()) { - modconf.printUnsatisfiedModsError(); + errorstream << modconf.getUnsatisfiedModsError() << std::endl; return; } diff --git a/src/content/mod_configuration.cpp b/src/content/mod_configuration.cpp index 504cdaf6f..a2ac959a1 100644 --- a/src/content/mod_configuration.cpp +++ b/src/content/mod_configuration.cpp @@ -21,16 +21,27 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" #include "settings.h" #include "filesys.h" +#include "gettext.h" -void ModConfiguration::printUnsatisfiedModsError() const + +std::string ModConfiguration::getUnsatisfiedModsError() const { + std::ostringstream error; + error << gettext("Some mods have unsatisfied dependencies:") << std::endl; + for (const ModSpec &mod : m_unsatisfied_mods) { - errorstream << "mod \"" << mod.name - << "\" has unsatisfied dependencies: "; + //~ Error when a mod is missing dependencies. Ex: "Mod Title is missing: mod1, mod2, mod3" + error << " - " << fmtgettext("%s is missing:", mod.name.c_str()); for (const std::string &unsatisfied_depend : mod.unsatisfied_depends) - errorstream << " \"" << unsatisfied_depend << "\""; - errorstream << std::endl; + error << " " << unsatisfied_depend; + error << "\n"; } + + error << "\n" + << gettext("Install and enable the required mods, or disable the mods causing errors.") << "\n" + << gettext("Note: this may be caused by a dependency cycle, in which case try updating the mods."); + + return error.str(); } void ModConfiguration::addModsInPath(const std::string &path, const std::string &virtual_path) diff --git a/src/content/mod_configuration.h b/src/content/mod_configuration.h index 1595d1ca3..443530485 100644 --- a/src/content/mod_configuration.h +++ b/src/content/mod_configuration.h @@ -51,7 +51,7 @@ public: */ const std::vector &getMods() const { return m_sorted_mods; } - void printUnsatisfiedModsError() const; + std::string getUnsatisfiedModsError() const; /** * Adds all mods in the given path. used for games, modpacks diff --git a/src/server.cpp b/src/server.cpp index 93767da9d..06e7b9d50 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -425,14 +425,10 @@ void Server::init() m_modmgr = std::make_unique(m_path_world); std::vector unsatisfied_mods = m_modmgr->getUnsatisfiedMods(); - // complain about mods with unsatisfied dependencies if (!m_modmgr->isConsistent()) { - m_modmgr->printUnsatisfiedModsError(); - - warningstream - << "You have unsatisfied dependencies, loading your world anyway. " - << "This will become a fatal error in the future." << std::endl; + std::string error = m_modmgr->getUnsatisfiedModsError(); + throw ServerError(error); } //lock environment diff --git a/src/server/mods.h b/src/server/mods.h index 1d1b42d0f..70edeb2c6 100644 --- a/src/server/mods.h +++ b/src/server/mods.h @@ -57,8 +57,8 @@ public: return configuration.isConsistent(); } - inline void printUnsatisfiedModsError() const { - return configuration.printUnsatisfiedModsError(); + inline std::string getUnsatisfiedModsError() const { + return configuration.getUnsatisfiedModsError(); } /**