]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mods.cpp
Move get_schematic and read_schematic to l_mapgen.cpp
[dragonfireclient.git] / src / mods.cpp
index 64c3199928392d0f09b0cec2f97e98fb685918b4..7d6b4f5f7686f64389e7d2c49f216e3d9329afc2 100644 (file)
@@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 #include "mods.h"
+#include "main.h"
 #include "filesys.h"
 #include "strfnd.h"
 #include "log.h"
@@ -25,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "settings.h"
 #include "strfnd.h"
 #include <cctype>
+#include "convert_json.h"
 
 static bool parseDependsLine(std::istream &is,
                std::string &dep, std::set<char> &symbols)
@@ -75,16 +77,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<char> symbols;
-                       if(parseDependsLine(is2, dep, symbols))
-                               spec.optdepends.insert(dep);
-               }
        }
 }
 
@@ -112,26 +104,6 @@ std::map<std::string, ModSpec> 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<std::string> 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<find_paths.size(); i++){
-               const std::string &try_path = find_paths[i];
-               if(fs::PathExists(try_path)){
-                       ModSpec spec(modname, try_path);
-                       parseModContents(spec);
-                       return spec;
-               }
-       }
-       // Failed to find mod
-       return ModSpec();
-}
-
 std::map<std::string, ModSpec> flattenModTree(std::map<std::string, ModSpec> mods)
 {
        std::map<std::string, ModSpec> result;
@@ -141,11 +113,11 @@ std::map<std::string, ModSpec> flattenModTree(std::map<std::string, ModSpec> mod
                ModSpec mod = (*it).second;
                if(mod.is_modpack)
                {
-                       std::map<std::string, ModSpec> content = 
+                       std::map<std::string, ModSpec> 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 +138,8 @@ std::vector<ModSpec> flattenMods(std::map<std::string, ModSpec> mods)
                        std::vector<ModSpec> 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 +152,6 @@ ModConfiguration::ModConfiguration(std::string worldpath)
 {
        SubgameSpec gamespec = findWorldSubgame(worldpath);
 
-       // Add common mods
-       std::map<std::string, ModSpec> common_mods;
-       std::vector<std::string> 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<inexistent_common_mods.size(); i++){
-                       if(i != 0) s += ", ";
-                       s += std::string("\"") + inexistent_common_mods[i] + "\"";
-               }
-               s += " could not be found.";
-               throw ModError(s);
-       }
-       addMods(flattenMods(common_mods));
-
        // Add all game mods and all world mods
        addModsInPath(gamespec.gamemods_path);
        addModsInPath(worldpath + DIR_DELIM + "worldmods");
@@ -220,23 +162,22 @@ ModConfiguration::ModConfiguration(std::string worldpath)
        Settings worldmt_settings;
        worldmt_settings.readConfigFile(worldmt.c_str());
        std::vector<std::string> names = worldmt_settings.getNames();
-       std::set<std::string> exclude_mod_names;
-       for(std::vector<std::string>::iterator it = names.begin(); 
+       std::set<std::string> include_mod_names;
+       for(std::vector<std::string>::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<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)
@@ -246,10 +187,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,7 +234,7 @@ void ModConfiguration::addMods(std::vector<ModSpec> new_mods)
                // Add all the mods that come from modpacks
                // Second iteration:
                // Add all the mods that didn't come from modpacks
-               
+
                std::set<std::string> seen_this_iteration;
 
                for(std::vector<ModSpec>::const_iterator it = new_mods.begin();
@@ -307,7 +251,7 @@ void ModConfiguration::addMods(std::vector<ModSpec> 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: \""
+                               actionstream<<"WARNING: Mod name conflict detected: \""
                                        <<mod.name<<"\""<<std::endl
                                        <<"Will not load: "<<oldmod.path<<std::endl
                                        <<"Overridden by: "<<mod.path<<std::endl;
@@ -381,9 +325,28 @@ void ModConfiguration::resolveDependencies()
                        else{
                                ++it;
                        }
-               }       
+               }
        }
 
        // Step 4: write back list of unsatisfied mods
        m_unsatisfied_mods.assign(unsatisfied.begin(), unsatisfied.end());
 }
+
+#if USE_CURL
+Json::Value getModstoreUrl(std::string url)
+{
+       std::vector<std::string> 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