X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fmods.cpp;h=1b1bdb07b69ca7a420fed58fd58602adb3b82e60;hb=21079cc8ebae0bf694c1903c07bf3e1517feab99;hp=64c3199928392d0f09b0cec2f97e98fb685918b4;hpb=e0564d5de01dd26f7b4f4d188415f5cf5a47b5d0;p=dragonfireclient.git diff --git a/src/mods.cpp b/src/mods.cpp index 64c319992..1b1bdb07b 100644 --- a/src/mods.cpp +++ b/src/mods.cpp @@ -17,14 +17,17 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include +#include #include "mods.h" #include "filesys.h" -#include "strfnd.h" +#include "util/strfnd.h" #include "log.h" #include "subgame.h" #include "settings.h" -#include "strfnd.h" -#include +#include "util/strfnd.h" +#include "convert_json.h" +#include "exceptions.h" static bool parseDependsLine(std::istream &is, std::string &dep, std::set &symbols) @@ -45,6 +48,11 @@ static bool parseDependsLine(std::istream &is, void parseModContents(ModSpec &spec) { // NOTE: this function works in mutual recursion with getModsInPath + Settings info; + info.readConfigFile((spec.path+DIR_DELIM+"mod.conf").c_str()); + + if (info.exists("name")) + spec.name = info.get("name"); spec.depends.clear(); spec.optdepends.clear(); @@ -75,16 +83,6 @@ void parseModContents(ModSpec &spec) } } } - - // FIXME: optdepends.txt is deprecated - // remove this code at some point in the future - std::ifstream is2((spec.path+DIR_DELIM+"optdepends.txt").c_str()); - while(is2.good()){ - std::string dep; - std::set symbols; - if(parseDependsLine(is2, dep, symbols)) - spec.optdepends.insert(dep); - } } } @@ -112,26 +110,6 @@ std::map getModsInPath(std::string path, bool part_of_modp return result; } -ModSpec findCommonMod(const std::string &modname) -{ - // Try to find in {$user,$share}/games/common/$modname - std::vector find_paths; - find_paths.push_back(porting::path_user + DIR_DELIM + "games" + - DIR_DELIM + "common" + DIR_DELIM + "mods" + DIR_DELIM + modname); - find_paths.push_back(porting::path_share + DIR_DELIM + "games" + - DIR_DELIM + "common" + DIR_DELIM + "mods" + DIR_DELIM + modname); - for(u32 i=0; i flattenModTree(std::map mods) { std::map result; @@ -141,11 +119,11 @@ std::map flattenModTree(std::map mod ModSpec mod = (*it).second; if(mod.is_modpack) { - std::map content = + std::map content = flattenModTree(mod.modpack_content); result.insert(content.begin(),content.end()); result.insert(std::make_pair(mod.name,mod)); - } + } else //not a modpack { result.insert(std::make_pair(mod.name,mod)); @@ -166,8 +144,8 @@ std::vector flattenMods(std::map mods) std::vector content = flattenMods(mod.modpack_content); result.reserve(result.size() + content.size()); result.insert(result.end(),content.begin(),content.end()); - - } + + } else //not a modpack { result.push_back(mod); @@ -180,36 +158,6 @@ ModConfiguration::ModConfiguration(std::string worldpath) { SubgameSpec gamespec = findWorldSubgame(worldpath); - // Add common mods - std::map common_mods; - std::vector inexistent_common_mods; - Settings gameconf; - if(getGameConfig(gamespec.path, gameconf)){ - if(gameconf.exists("common_mods")){ - Strfnd f(gameconf.get("common_mods")); - while(!f.atend()){ - std::string modname = trim(f.next(",")); - if(modname.empty()) - continue; - ModSpec spec = findCommonMod(modname); - if(spec.name.empty()) - inexistent_common_mods.push_back(modname); - else - common_mods.insert(std::make_pair(modname, spec)); - } - } - } - if(!inexistent_common_mods.empty()){ - std::string s = "Required common mods "; - for(u32 i=0; i names = worldmt_settings.getNames(); - std::set exclude_mod_names; - for(std::vector::iterator it = names.begin(); + std::set include_mod_names; + for(std::vector::iterator it = names.begin(); it != names.end(); ++it) - { - std::string name = *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)) + worldmt_settings.getBool(name)) { - exclude_mod_names.insert(name.substr(9)); + include_mod_names.insert(name.substr(9)); } } - // Collect all mods in gamespec.addon_mods_paths, - // excluding those in the set exclude_mod_names + // Collect all mods that are also in include_mod_names std::vector addon_mods; for(std::set::const_iterator it_path = gamespec.addon_mods_paths.begin(); it_path != gamespec.addon_mods_paths.end(); ++it_path) @@ -246,10 +193,13 @@ ModConfiguration::ModConfiguration(std::string worldpath) it != addon_mods_in_path.end(); ++it) { ModSpec& mod = *it; - if(exclude_mod_names.count(mod.name) == 0) + 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); @@ -290,13 +240,13 @@ void ModConfiguration::addMods(std::vector new_mods) // Add all the mods that come from modpacks // Second iteration: // Add all the mods that didn't come from modpacks - + std::set seen_this_iteration; for(std::vector::const_iterator it = new_mods.begin(); it != new_mods.end(); ++it){ const ModSpec &mod = *it; - if(mod.part_of_modpack != want_from_modpack) + if(mod.part_of_modpack != (bool)want_from_modpack) continue; if(existing_mods.count(mod.name) == 0){ // GOOD CASE: completely new mod. @@ -307,7 +257,7 @@ void ModConfiguration::addMods(std::vector new_mods) // BAD CASE: name conflict in different levels. u32 oldindex = existing_mods[mod.name]; const ModSpec &oldmod = m_unsatisfied_mods[oldindex]; - errorstream<<"WARNING: Mod name conflict detected: \"" + warningstream<<"Mod name conflict detected: \"" < new_mods) // VERY BAD CASE: name conflict in the same level. u32 oldindex = existing_mods[mod.name]; const ModSpec &oldmod = m_unsatisfied_mods[oldindex]; - errorstream<<"WARNING: Mod name conflict detected: \"" + warningstream<<"Mod name conflict detected: \"" < extra_headers; + + bool special_http_header = true; + + try { + special_http_header = g_settings->getBool("modstore_disable_special_http_header"); + } catch (SettingNotFoundException) {} + + if (special_http_header) { + extra_headers.push_back("Accept: application/vnd.minetest.mmdb-v1+json"); + } + return fetchJsonValue(url, special_http_header ? &extra_headers : NULL); +} + +#endif