world.mt: Only accept true/false/nil values (#8055)
authorSmallJoker <SmallJoker@users.noreply.github.com>
Sun, 13 Jan 2019 15:22:32 +0000 (16:22 +0100)
committerGitHub <noreply@github.com>
Sun, 13 Jan 2019 15:22:32 +0000 (16:22 +0100)
This patch will make distinguishable mods in modpacks possible in the future
`nil` checks are required to provide backwards-compatibility for fresh configured worlds

builtin/mainmenu/dlg_config_world.lua
builtin/mainmenu/pkgmgr.lua
src/content/mods.cpp

index 1a1107c24a4d1d06ef57c8bd0996a455e9d05995..3e766aa78798ac77e54860ec0990177defac6991 100644 (file)
@@ -138,7 +138,7 @@ local function handle_buttons(this, fields)
                                        not mod.is_game_content then
                                if modname_valid(mod.name) then
                                        worldfile:set("load_mod_" .. mod.name,
-                                                       tostring(mod.enabled))
+                                               mod.enabled and "true" or "false")
                                elseif mod.enabled then
                                        gamedata.errormessage = fgettext_ne("Failed to enable mo" ..
                                                        "d \"$1\" as it contains disallowed characters. " ..
index cea373c9f5e7858d3eb2ab7f446417b9d70c05d6..171ba54ea251f8a7834f77081c92b7813816c952 100644 (file)
@@ -391,7 +391,10 @@ function pkgmgr.get_worldconfig(worldpath)
                if key == "gameid" then
                        worldconfig.id = value
                elseif key:sub(0, 9) == "load_mod_" then
-                       worldconfig.global_mods[key] = core.is_yes(value)
+                       -- Compatibility: Check against "nil" which was erroneously used
+                       -- as value for fresh configured worlds
+                       worldconfig.global_mods[key] = value ~= "false" and value ~= "nil"
+                               and value
                else
                        worldconfig[key] = value
                end
@@ -595,7 +598,7 @@ function pkgmgr.preparemodlist(data)
                                end
                        end
                        if element ~= nil then
-                               element.enabled = core.is_yes(value)
+                               element.enabled = value ~= "false" and value ~= "nil" and value
                        else
                                core.log("info", "Mod: " .. key .. " " .. dump(value) .. " but not found")
                        end
index 3cb168e1914e06bc1d2eb10cc5209c33bb059948..676666f78a6254a78dbbdb9e2fab2ac4db9ac1d7 100644 (file)
@@ -274,7 +274,8 @@ void ModConfiguration::addModsFromConfig(
        conf.readConfigFile(settings_path.c_str());
        std::vector<std::string> names = conf.getNames();
        for (const std::string &name : names) {
-               if (name.compare(0, 9, "load_mod_") == 0 && conf.getBool(name))
+               if (name.compare(0, 9, "load_mod_") == 0 && conf.get(name) != "false" &&
+                               conf.get(name) != "nil")
                        load_mod_names.insert(name.substr(9));
        }