From 308bb69eefdfb2ff3b893c124ccf0321d99a1bfd Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Mon, 11 Dec 2017 17:33:44 +0100 Subject: CSM fixes: load mods after flavours & add flavour to block mod loading (#6738) * CSM fixes: load mods after flavours & add flavour to block mod loading * Don't permit to load mods twice * Prepare builtin integrity global algorithm * Add missing doc & use a nicer byteflag for LOAD_CLIENT_MODS flavour * flag typo fix * Invert CSM_FL_LOOKUP_NODES & CSM_FL_LOAD_CLIENT_MODS ids --- src/client.cpp | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'src/client.cpp') diff --git a/src/client.cpp b/src/client.cpp index c04bf055a..6e29607ca 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -113,18 +113,38 @@ Client::Client( m_script->setEnv(&m_env); } -void Client::loadMods() +void Client::loadBuiltin() { // Load builtin scanModIntoMemory(BUILTIN_MOD_NAME, getBuiltinLuaPath()); - // If modding is not enabled, don't load mods, just builtin + m_script->loadModFromMemory(BUILTIN_MOD_NAME); +} + +void Client::loadMods() +{ + // Don't permit to load mods twice + if (m_mods_loaded) { + return; + } + + // If modding is not enabled or flavour disable it, don't load mods, just builtin if (!m_modding_enabled) { + warningstream << "Client side mods are disabled by configuration." << std::endl; return; } + + if (checkCSMFlavourLimit(CSMFlavourLimit::CSM_FL_LOAD_CLIENT_MODS)) { + warningstream << "Client side mods are disabled by server." << std::endl; + // If mods loading is disabled and builtin integrity is wrong, disconnect user. + if (!checkBuiltinIntegrity()) { + // @TODO disconnect user + } + return; + } + ClientModConfiguration modconf(getClientModsLuaPath()); m_mods = modconf.getMods(); - std::vector unsatisfied_mods = modconf.getUnsatisfiedMods(); // complain about mods with unsatisfied dependencies if (!modconf.isConsistent()) { modconf.printUnsatisfiedModsError(); @@ -145,6 +165,18 @@ void Client::loadMods() } scanModIntoMemory(mod.name, mod.path); } + + // Load and run "mod" scripts + for (const ModSpec &mod : m_mods) + m_script->loadModFromMemory(mod.name); + + m_mods_loaded = true; +} + +bool Client::checkBuiltinIntegrity() +{ + // @TODO + return true; } void Client::scanModSubfolder(const std::string &mod_name, const std::string &mod_path, @@ -164,20 +196,6 @@ void Client::scanModSubfolder(const std::string &mod_name, const std::string &mo } } -void Client::initMods() -{ - m_script->loadModFromMemory(BUILTIN_MOD_NAME); - - // If modding is not enabled, don't load mods, just builtin - if (!m_modding_enabled) { - return; - } - - // Load and run "mod" scripts - for (const ModSpec &mod : m_mods) - m_script->loadModFromMemory(mod.name); -} - const std::string &Client::getBuiltinLuaPath() { static const std::string builtin_dir = porting::path_share + DIR_DELIM + "builtin"; -- cgit v1.2.3