Beispiel #1
0
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);
	}
}
Beispiel #2
0
void Client::initMods()
{
	m_script->loadMod(getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME);

	// If modding is not enabled, don't load mods, just builtin
	if (!m_modding_enabled) {
		return;
	}

	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 characters [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);
	}
}