summaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-01-27 07:41:10 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-03-13 23:56:05 +0100
commit92b45b2a189b703fc7cfc8ddbc09a7ad563a13bc (patch)
tree146edaf44e3cbeca55c34e6d30b375dd053877b4 /src/client.cpp
parentc42c53fccf87a3819ca78de52f8f20c47c4fbb9f (diff)
downloadminetest-92b45b2a189b703fc7cfc8ddbc09a7ad563a13bc.tar.gz
minetest-92b45b2a189b703fc7cfc8ddbc09a7ad563a13bc.tar.bz2
minetest-92b45b2a189b703fc7cfc8ddbc09a7ad563a13bc.zip
[CSM] implement client side mod loading (#5123)
* client side mods are located in clientmods/ * move builtin/preview.lua to clientmods/preview/init.lua as a preview mod * refactor ModConfiguration class to work properly with client and server using child objects * move some Server constructor mod load code to ModConfiguration to reduce code duplication between client and server * remove mods.{cpp,h} unused functions * use UNORDERED_SET instead of std::set in some modspec storages
Diffstat (limited to 'src/client.cpp')
-rw-r--r--src/client.cpp44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 3b8074252..4bb63fef1 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -268,14 +268,50 @@ Client::Client(
void Client::initMods()
{
- std::string script_path = getBuiltinLuaPath() + DIR_DELIM "init.lua";
+ m_script->loadMod(getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME);
+
+ ClientModConfiguration modconf(getClientModsLuaPath());
+ std::vector<ModSpec> 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 (std::vector<ModSpec>::const_iterator i = mods.begin();
+ i != mods.end(); ++i) {
+ infostream << (*i).name << " ";
+ }
+
+ infostream << std::endl;
+ // Load and run "mod" scripts
+ for (std::vector<ModSpec>::const_iterator it = mods.begin();
+ it != mods.end(); ++it) {
+ const ModSpec &mod = *it;
+ if (!string_allowed(mod.name, MODNAME_ALLOWED_CHARS)) {
+ throw ModError("Error loading mod \"" + mod.name +
+ "\": Mod name does not follow naming conventions: "
+ "Only chararacters [a-z0-9_] are allowed.");
+ }
+ std::string script_path = mod.path + DIR_DELIM + "init.lua";
+ infostream << " [" << padStringRight(mod.name, 12) << "] [\""
+ << script_path << "\"]" << std::endl;
+ m_script->loadMod(script_path, mod.name);
+ }
+}
- m_script->loadMod(script_path, BUILTIN_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::getBuiltinLuaPath()
+const std::string &Client::getClientModsLuaPath()
{
- return porting::path_share + DIR_DELIM + "builtin";
+ static const std::string clientmods_dir = porting::path_share + DIR_DELIM + "clientmods";
+ return clientmods_dir;
}
const std::vector<ModSpec>& Client::getMods() const