+ // 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();
+ // complain about mods with unsatisfied dependencies
+ if (!modconf.isConsistent()) {
+ modconf.printUnsatisfiedModsError();
+ }
+
+ // Print mods
+ infostream << "Client Loading mods: ";
+ for (const ModSpec &mod : m_mods)
+ infostream << mod.name << " ";
+ infostream << std::endl;
+
+ // Load and run "mod" scripts
+ for (const ModSpec &mod : m_mods) {
+ if (!string_allowed(mod.name, MODNAME_ALLOWED_CHARS)) {
+ throw ModError("Error loading mod \"" + mod.name +
+ "\": Mod name does not follow naming conventions: "
+ "Only characters [a-z0-9_] are allowed.");
+ }
+ 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,
+ std::string mod_subpath)
+{
+ std::string full_path = mod_path + DIR_DELIM + mod_subpath;
+ std::vector<fs::DirListNode> mod = fs::GetDirListing(full_path);
+ for (const fs::DirListNode &j : mod) {
+ std::string filename = j.name;
+ if (j.dir) {
+ scanModSubfolder(mod_name, mod_path, mod_subpath
+ + filename + DIR_DELIM);
+ continue;
+ }
+ std::replace( mod_subpath.begin(), mod_subpath.end(), DIR_DELIM_CHAR, '/');
+ m_mod_files[mod_name + ":" + mod_subpath + filename] = full_path + filename;
+ }
+}
+
+const std::string &Client::getBuiltinLuaPath()
+{
+ static const std::string builtin_dir = porting::path_share + DIR_DELIM + "builtin";
+ return builtin_dir;
+}
+
+const std::string &Client::getClientModsLuaPath()
+{
+ static const std::string clientmods_dir = porting::path_share + DIR_DELIM + "clientmods";
+ return clientmods_dir;