diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-05-20 22:29:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-20 22:29:15 +0200 |
commit | 90808a4f34dca379e872074bdfd472faf1c48cf3 (patch) | |
tree | c98e0264a2d18f8106d6fde77c49ddb46e467dbf /src | |
parent | 358074b2960b369dfd248bd31e08db93e114a4aa (diff) | |
download | minetest-90808a4f34dca379e872074bdfd472faf1c48cf3.tar.gz minetest-90808a4f34dca379e872074bdfd472faf1c48cf3.tar.bz2 minetest-90808a4f34dca379e872074bdfd472faf1c48cf3.zip |
Real control fix (#5787)
* Allow enabling and disabling mods.
* Re-fix 605599b6f150b89ba6539c4d088231b326adcb48
This breaks some chars like € in chat.
Instead verify is char is a non control char -> iswcntrl
Diffstat (limited to 'src')
-rw-r--r-- | src/guiChatConsole.cpp | 2 | ||||
-rw-r--r-- | src/mods.cpp | 100 | ||||
-rw-r--r-- | src/mods.h | 2 | ||||
-rw-r--r-- | src/server.cpp | 26 |
4 files changed, 62 insertions, 68 deletions
diff --git a/src/guiChatConsole.cpp b/src/guiChatConsole.cpp index 8281da861..5bb80bbbe 100644 --- a/src/guiChatConsole.cpp +++ b/src/guiChatConsole.cpp @@ -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) ); diff --git a/src/mods.cpp b/src/mods.cpp index 6fce8e93d..0e583b2db 100644 --- a/src/mods.cpp +++ b/src/mods.cpp @@ -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 diff --git a/src/mods.h b/src/mods.h index 1e62db54d..7455a51ea 100644 --- a/src/mods.h +++ b/src/mods.h @@ -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 diff --git a/src/server.cpp b/src/server.cpp index 6889451d9..1e8e6a5d2 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -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); |