Real control fix (#5787)

* Allow enabling and disabling mods.

* Re-fix 605599b6f1

This breaks some chars like € in chat.

Instead verify is char is a non control char -> iswcntrl
master
Loïc Blot 2017-05-20 22:29:15 +02:00 committed by GitHub
parent 358074b296
commit 90808a4f34
4 changed files with 62 additions and 68 deletions

View File

@ -627,7 +627,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
bool backwards = event.KeyInput.Shift;
prompt.nickCompletion(names, backwards);
return true;
} else if (iswprint(event.KeyInput.Char) && !event.KeyInput.Control) {
} else if (!iswcntrl(event.KeyInput.Char) && !event.KeyInput.Control) {
#if defined(__linux__) && (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9)
wchar_t wc = L'_';
mbtowc( &wc, (char *) &event.KeyInput.Char, sizeof(event.KeyInput.Char) );

View File

@ -214,6 +214,55 @@ void ModConfiguration::addMods(const std::vector<ModSpec> &new_mods)
}
}
void ModConfiguration::addModsFormConfig(const std::string &settings_path, const std::set<std::string> &mods)
{
Settings conf;
std::set<std::string> load_mod_names;
conf.readConfigFile(settings_path.c_str());
std::vector<std::string> names = conf.getNames();
for (std::vector<std::string>::iterator it = names.begin();
it != names.end(); ++it) {
std::string name = *it;
if (name.compare(0,9,"load_mod_")==0 && conf.getBool(name))
load_mod_names.insert(name.substr(9));
}
std::vector<ModSpec> addon_mods;
for (std::set<std::string>::const_iterator i = mods.begin();
i != mods.end(); ++i) {
std::vector<ModSpec> addon_mods_in_path = flattenMods(getModsInPath(*i));
for (std::vector<ModSpec>::const_iterator it = addon_mods_in_path.begin();
it != addon_mods_in_path.end(); ++it) {
const ModSpec& mod = *it;
if (load_mod_names.count(mod.name) != 0)
addon_mods.push_back(mod);
else
conf.setBool("load_mod_" + mod.name, false);
}
}
conf.updateConfigFile(settings_path.c_str());
addMods(addon_mods);
checkConflictsAndDeps();
// complain about mods declared to be loaded, but not found
for (std::vector<ModSpec>::iterator it = addon_mods.begin();
it != addon_mods.end(); ++it)
load_mod_names.erase((*it).name);
std::vector<ModSpec> UnsatisfiedMods = getUnsatisfiedMods();
for (std::vector<ModSpec>::iterator it = UnsatisfiedMods.begin();
it != UnsatisfiedMods.end(); ++it)
load_mod_names.erase((*it).name);
if (!load_mod_names.empty()) {
errorstream << "The following mods could not be found:";
for (std::set<std::string>::iterator it = load_mod_names.begin();
it != load_mod_names.end(); ++it)
errorstream << " \"" << (*it) << "\"";
errorstream << std::endl;
}
}
void ModConfiguration::checkConflictsAndDeps()
{
// report on name conflicts
@ -296,53 +345,22 @@ ServerModConfiguration::ServerModConfiguration(const std::string &worldpath):
addModsInPath(gamespec.gamemods_path);
addModsInPath(worldpath + DIR_DELIM + "worldmods");
// check world.mt file for mods explicitely declared to be
// loaded or not by a load_mod_<modname> = ... line.
std::string worldmt = worldpath+DIR_DELIM+"world.mt";
Settings worldmt_settings;
worldmt_settings.readConfigFile(worldmt.c_str());
std::vector<std::string> names = worldmt_settings.getNames();
std::set<std::string> include_mod_names;
for (std::vector<std::string>::const_iterator it = names.begin();
it != names.end(); ++it) {
std::string name = *it;
// for backwards compatibility: exclude only mods which are
// explicitely excluded. if mod is not mentioned at all, it is
// enabled. So by default, all installed mods are enabled.
if (name.compare(0,9,"load_mod_") == 0 &&
worldmt_settings.getBool(name)) {
include_mod_names.insert(name.substr(9));
}
}
// Collect all mods that are also in include_mod_names
std::vector<ModSpec> addon_mods;
for (std::set<std::string>::const_iterator it_path = gamespec.addon_mods_paths.begin();
it_path != gamespec.addon_mods_paths.end(); ++it_path) {
std::vector<ModSpec> addon_mods_in_path = flattenMods(getModsInPath(*it_path));
for (std::vector<ModSpec>::const_iterator it = addon_mods_in_path.begin();
it != addon_mods_in_path.end(); ++it) {
const ModSpec& mod = *it;
if (include_mod_names.count(mod.name) != 0)
addon_mods.push_back(mod);
else
worldmt_settings.setBool("load_mod_" + mod.name, false);
}
}
worldmt_settings.updateConfigFile(worldmt.c_str());
addMods(addon_mods);
checkConflictsAndDeps();
// Load normal mods
std::string worldmt = worldpath + DIR_DELIM + "world.mt";
addModsFormConfig(worldmt, gamespec.addon_mods_paths);
}
#ifndef SERVER
ClientModConfiguration::ClientModConfiguration(const std::string &path):
ModConfiguration(path)
{
addModsInPath(path);
addModsInPath(porting::path_user + DIR_DELIM + "clientmods");
checkConflictsAndDeps();
std::set<std::string> paths;
std::string path_user = porting::path_user + DIR_DELIM + "clientmods";
paths.insert(path);
paths.insert(path_user);
std::string settings_path = path_user + DIR_DELIM + "mods.conf";
addModsFormConfig(settings_path, paths);
}
#endif

View File

@ -99,6 +99,8 @@ protected:
// adds all mods in the set.
void addMods(const std::vector<ModSpec> &new_mods);
void addModsFormConfig(const std::string &settings_path, const std::set<std::string> &mods);
void checkConflictsAndDeps();
private:
// move mods from m_unsatisfied_mods to m_sorted_mods

View File

@ -230,32 +230,6 @@ Server::Server(
modconf.printUnsatisfiedModsError();
}
Settings worldmt_settings;
std::string worldmt = m_path_world + DIR_DELIM + "world.mt";
worldmt_settings.readConfigFile(worldmt.c_str());
std::vector<std::string> names = worldmt_settings.getNames();
std::set<std::string> load_mod_names;
for(std::vector<std::string>::iterator it = names.begin();
it != names.end(); ++it) {
std::string name = *it;
if(name.compare(0,9,"load_mod_")==0 && worldmt_settings.getBool(name))
load_mod_names.insert(name.substr(9));
}
// complain about mods declared to be loaded, but not found
for(std::vector<ModSpec>::iterator it = m_mods.begin();
it != m_mods.end(); ++it)
load_mod_names.erase((*it).name);
for(std::vector<ModSpec>::iterator it = unsatisfied_mods.begin();
it != unsatisfied_mods.end(); ++it)
load_mod_names.erase((*it).name);
if(!load_mod_names.empty()) {
errorstream << "The following mods could not be found:";
for(std::set<std::string>::iterator it = load_mod_names.begin();
it != load_mod_names.end(); ++it)
errorstream << " \"" << (*it) << "\"";
errorstream << std::endl;
}
//lock environment
MutexAutoLock envlock(m_env_mutex);