Skip to content

Commit 90808a4

Browse files
authoredMay 20, 2017
Real control fix (#5787)
* Allow enabling and disabling mods. * Re-fix 605599b This breaks some chars like € in chat. Instead verify is char is a non control char -> iswcntrl
1 parent 358074b commit 90808a4

File tree

4 files changed

+62
-68
lines changed

4 files changed

+62
-68
lines changed
 

‎src/guiChatConsole.cpp

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

‎src/mods.cpp

+59-41
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,55 @@ void ModConfiguration::addMods(const std::vector<ModSpec> &new_mods)
214214
}
215215
}
216216

217+
void ModConfiguration::addModsFormConfig(const std::string &settings_path, const std::set<std::string> &mods)
218+
{
219+
Settings conf;
220+
std::set<std::string> load_mod_names;
221+
222+
conf.readConfigFile(settings_path.c_str());
223+
std::vector<std::string> names = conf.getNames();
224+
for (std::vector<std::string>::iterator it = names.begin();
225+
it != names.end(); ++it) {
226+
std::string name = *it;
227+
if (name.compare(0,9,"load_mod_")==0 && conf.getBool(name))
228+
load_mod_names.insert(name.substr(9));
229+
}
230+
231+
std::vector<ModSpec> addon_mods;
232+
for (std::set<std::string>::const_iterator i = mods.begin();
233+
i != mods.end(); ++i) {
234+
std::vector<ModSpec> addon_mods_in_path = flattenMods(getModsInPath(*i));
235+
for (std::vector<ModSpec>::const_iterator it = addon_mods_in_path.begin();
236+
it != addon_mods_in_path.end(); ++it) {
237+
const ModSpec& mod = *it;
238+
if (load_mod_names.count(mod.name) != 0)
239+
addon_mods.push_back(mod);
240+
else
241+
conf.setBool("load_mod_" + mod.name, false);
242+
}
243+
}
244+
conf.updateConfigFile(settings_path.c_str());
245+
246+
addMods(addon_mods);
247+
checkConflictsAndDeps();
248+
249+
// complain about mods declared to be loaded, but not found
250+
for (std::vector<ModSpec>::iterator it = addon_mods.begin();
251+
it != addon_mods.end(); ++it)
252+
load_mod_names.erase((*it).name);
253+
std::vector<ModSpec> UnsatisfiedMods = getUnsatisfiedMods();
254+
for (std::vector<ModSpec>::iterator it = UnsatisfiedMods.begin();
255+
it != UnsatisfiedMods.end(); ++it)
256+
load_mod_names.erase((*it).name);
257+
if (!load_mod_names.empty()) {
258+
errorstream << "The following mods could not be found:";
259+
for (std::set<std::string>::iterator it = load_mod_names.begin();
260+
it != load_mod_names.end(); ++it)
261+
errorstream << " \"" << (*it) << "\"";
262+
errorstream << std::endl;
263+
}
264+
}
265+
217266
void ModConfiguration::checkConflictsAndDeps()
218267
{
219268
// report on name conflicts
@@ -296,53 +345,22 @@ ServerModConfiguration::ServerModConfiguration(const std::string &worldpath):
296345
addModsInPath(gamespec.gamemods_path);
297346
addModsInPath(worldpath + DIR_DELIM + "worldmods");
298347

299-
// check world.mt file for mods explicitely declared to be
300-
// loaded or not by a load_mod_<modname> = ... line.
301-
std::string worldmt = worldpath+DIR_DELIM+"world.mt";
302-
Settings worldmt_settings;
303-
worldmt_settings.readConfigFile(worldmt.c_str());
304-
std::vector<std::string> names = worldmt_settings.getNames();
305-
std::set<std::string> include_mod_names;
306-
for (std::vector<std::string>::const_iterator it = names.begin();
307-
it != names.end(); ++it) {
308-
std::string name = *it;
309-
// for backwards compatibility: exclude only mods which are
310-
// explicitely excluded. if mod is not mentioned at all, it is
311-
// enabled. So by default, all installed mods are enabled.
312-
if (name.compare(0,9,"load_mod_") == 0 &&
313-
worldmt_settings.getBool(name)) {
314-
include_mod_names.insert(name.substr(9));
315-
}
316-
}
317-
318-
// Collect all mods that are also in include_mod_names
319-
std::vector<ModSpec> addon_mods;
320-
for (std::set<std::string>::const_iterator it_path = gamespec.addon_mods_paths.begin();
321-
it_path != gamespec.addon_mods_paths.end(); ++it_path) {
322-
std::vector<ModSpec> addon_mods_in_path = flattenMods(getModsInPath(*it_path));
323-
for (std::vector<ModSpec>::const_iterator it = addon_mods_in_path.begin();
324-
it != addon_mods_in_path.end(); ++it) {
325-
const ModSpec& mod = *it;
326-
if (include_mod_names.count(mod.name) != 0)
327-
addon_mods.push_back(mod);
328-
else
329-
worldmt_settings.setBool("load_mod_" + mod.name, false);
330-
}
331-
}
332-
worldmt_settings.updateConfigFile(worldmt.c_str());
333-
334-
addMods(addon_mods);
335-
336-
checkConflictsAndDeps();
348+
// Load normal mods
349+
std::string worldmt = worldpath + DIR_DELIM + "world.mt";
350+
addModsFormConfig(worldmt, gamespec.addon_mods_paths);
337351
}
338352

339353
#ifndef SERVER
340354
ClientModConfiguration::ClientModConfiguration(const std::string &path):
341355
ModConfiguration(path)
342356
{
343-
addModsInPath(path);
344-
addModsInPath(porting::path_user + DIR_DELIM + "clientmods");
345-
checkConflictsAndDeps();
357+
std::set<std::string> paths;
358+
std::string path_user = porting::path_user + DIR_DELIM + "clientmods";
359+
paths.insert(path);
360+
paths.insert(path_user);
361+
362+
std::string settings_path = path_user + DIR_DELIM + "mods.conf";
363+
addModsFormConfig(settings_path, paths);
346364
}
347365
#endif
348366

‎src/mods.h

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class ModConfiguration
9999
// adds all mods in the set.
100100
void addMods(const std::vector<ModSpec> &new_mods);
101101

102+
void addModsFormConfig(const std::string &settings_path, const std::set<std::string> &mods);
103+
102104
void checkConflictsAndDeps();
103105
private:
104106
// move mods from m_unsatisfied_mods to m_sorted_mods

‎src/server.cpp

-26
Original file line numberDiff line numberDiff line change
@@ -230,32 +230,6 @@ Server::Server(
230230
modconf.printUnsatisfiedModsError();
231231
}
232232

233-
Settings worldmt_settings;
234-
std::string worldmt = m_path_world + DIR_DELIM + "world.mt";
235-
worldmt_settings.readConfigFile(worldmt.c_str());
236-
std::vector<std::string> names = worldmt_settings.getNames();
237-
std::set<std::string> load_mod_names;
238-
for(std::vector<std::string>::iterator it = names.begin();
239-
it != names.end(); ++it) {
240-
std::string name = *it;
241-
if(name.compare(0,9,"load_mod_")==0 && worldmt_settings.getBool(name))
242-
load_mod_names.insert(name.substr(9));
243-
}
244-
// complain about mods declared to be loaded, but not found
245-
for(std::vector<ModSpec>::iterator it = m_mods.begin();
246-
it != m_mods.end(); ++it)
247-
load_mod_names.erase((*it).name);
248-
for(std::vector<ModSpec>::iterator it = unsatisfied_mods.begin();
249-
it != unsatisfied_mods.end(); ++it)
250-
load_mod_names.erase((*it).name);
251-
if(!load_mod_names.empty()) {
252-
errorstream << "The following mods could not be found:";
253-
for(std::set<std::string>::iterator it = load_mod_names.begin();
254-
it != load_mod_names.end(); ++it)
255-
errorstream << " \"" << (*it) << "\"";
256-
errorstream << std::endl;
257-
}
258-
259233
//lock environment
260234
MutexAutoLock envlock(m_env_mutex);
261235

0 commit comments

Comments
 (0)
Please sign in to comment.