+ m_modding_enabled = g_settings->getBool("enable_client_modding");
+ m_script = new ClientScripting(this);
+ m_env.setScript(m_script);
+ m_script->setEnv(&m_env);
+}
+
+void Client::loadMods()
+{
+ // Load builtin
+ scanModIntoMemory(BUILTIN_MOD_NAME, getBuiltinLuaPath());
+
+ // If modding is not enabled, don't load mods, just builtin
+ if (!m_modding_enabled) {
+ return;
+ }
+ ClientModConfiguration modconf(getClientModsLuaPath());
+ m_mods = modconf.getMods();
+ std::vector<ModSpec> unsatisfied_mods = modconf.getUnsatisfiedMods();
+ // 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);
+ }
+}
+
+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;
+ }
+}
+
+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";
+ return builtin_dir;
+}
+
+const std::string &Client::getClientModsLuaPath()
+{
+ static const std::string clientmods_dir = porting::path_share + DIR_DELIM + "clientmods";
+ return clientmods_dir;
+}
+
+const std::vector<ModSpec>& Client::getMods() const
+{
+ static std::vector<ModSpec> client_modspec_temp;
+ return client_modspec_temp;
+}
+
+const ModSpec* Client::getModSpec(const std::string &modname) const
+{
+ return NULL;