]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/content/subgames.cpp
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / src / content / subgames.cpp
index 695ba431f9f89b3df98a4123d2b59fed097b0c6a..d0de926ef367e1fdc059bf4a3af82d4901dbbd6a 100644 (file)
@@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
+#include <common/c_internal.h>
 #include "content/subgames.h"
 #include "porting.h"
 #include "filesys.h"
@@ -24,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "log.h"
 #include "util/strfnd.h"
 #include "defaultsettings.h" // for set_default_settings
-#include "mapgen/mapgen.h"   // for MapgenParams
+#include "map_settings_manager.h"
 #include "util/string.h"
 
 #ifndef SERVER
@@ -34,12 +35,36 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 // The maximum number of identical world names allowed
 #define MAX_WORLD_NAMES 100
 
+namespace
+{
+
 bool getGameMinetestConfig(const std::string &game_path, Settings &conf)
 {
        std::string conf_path = game_path + DIR_DELIM + "minetest.conf";
        return conf.readConfigFile(conf_path.c_str());
 }
 
+}
+
+
+void SubgameSpec::checkAndLog() const
+{
+       // Log deprecation messages
+       auto handling_mode = get_deprecated_handling_mode();
+       if (!deprecation_msgs.empty() && handling_mode != DeprecatedHandlingMode::Ignore) {
+               std::ostringstream os;
+               os << "Game " << title << " at " << path << ":" << std::endl;
+               for (auto msg : deprecation_msgs)
+                       os << "\t" << msg << std::endl;
+
+               if (handling_mode == DeprecatedHandlingMode::Error)
+                       throw ModError(os.str());
+               else
+                       warningstream << os.str();
+       }
+}
+
+
 struct GameFindPath
 {
        std::string path;
@@ -102,22 +127,27 @@ SubgameSpec findSubgame(const std::string &id)
        std::string gamemod_path = game_path + DIR_DELIM + "mods";
 
        // Find mod directories
-       std::set<std::string> mods_paths;
-       if (!user_game)
-               mods_paths.insert(share + DIR_DELIM + "mods");
-       if (user != share || user_game)
-               mods_paths.insert(user + DIR_DELIM + "mods");
+       std::unordered_map<std::string, std::string> mods_paths;
+       mods_paths["mods"] = user + DIR_DELIM + "mods";
+       if (!user_game && user != share)
+               mods_paths["share"] = share + DIR_DELIM + "mods";
+
+       for (const std::string &mod_path : getEnvModPaths()) {
+               mods_paths[fs::AbsolutePath(mod_path)] = mod_path;
+       }
 
        // Get meta
        std::string conf_path = game_path + DIR_DELIM + "game.conf";
        Settings conf;
        conf.readConfigFile(conf_path.c_str());
 
-       std::string game_name;
-       if (conf.exists("name"))
-               game_name = conf.get("name");
+       std::string game_title;
+       if (conf.exists("title"))
+               game_title = conf.get("title");
+       else if (conf.exists("name"))
+               game_title = conf.get("name");
        else
-               game_name = id;
+               game_title = id;
 
        std::string game_author;
        if (conf.exists("author"))
@@ -132,8 +162,14 @@ SubgameSpec findSubgame(const std::string &id)
        menuicon_path = getImagePath(
                        game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png");
 #endif
-       return SubgameSpec(id, game_path, gamemod_path, mods_paths, game_name,
+
+       SubgameSpec spec(id, game_path, gamemod_path, mods_paths, game_title,
                        menuicon_path, game_author, game_release);
+
+       if (conf.exists("name") && !conf.exists("title"))
+               spec.deprecation_msgs.push_back("\"name\" setting in game.conf is deprecated, please use \"title\" instead");
+
+       return spec;
 }
 
 SubgameSpec findWorldSubgame(const std::string &world_path)
@@ -151,10 +187,12 @@ SubgameSpec findWorldSubgame(const std::string &world_path)
                std::string conf_path = world_gamepath + DIR_DELIM + "game.conf";
                conf.readConfigFile(conf_path.c_str());
 
-               if (conf.exists("name"))
-                       gamespec.name = conf.get("name");
+               if (conf.exists("title"))
+                       gamespec.title = conf.get("title");
+               else if (conf.exists("name"))
+                       gamespec.title = conf.get("name");
                else
-                       gamespec.name = world_gameid;
+                       gamespec.title = world_gameid;
 
                return gamespec;
        }
@@ -324,15 +362,16 @@ void loadGameConfAndInitWorld(const std::string &path, const std::string &name,
                }
        }
 
-       // Override defaults with those provided by the game.
-       // We clear and reload the defaults because the defaults
-       // might have been overridden by other subgame config
-       // files that were loaded before.
-       g_settings->clearDefaults();
-       set_default_settings(g_settings);
-       Settings game_defaults;
-       getGameMinetestConfig(gamespec.path, game_defaults);
-       g_settings->overrideDefaults(&game_defaults);
+       Settings *game_settings = Settings::getLayer(SL_GAME);
+       const bool new_game_settings = (game_settings == nullptr);
+       if (new_game_settings) {
+               // Called by main-menu without a Server instance running
+               // -> create and free manually
+               game_settings = Settings::createLayer(SL_GAME);
+       }
+
+       getGameMinetestConfig(gamespec.path, *game_settings);
+       game_settings->removeSecureSettings();
 
        infostream << "Initializing world at " << final_path << std::endl;
 
@@ -348,6 +387,7 @@ void loadGameConfAndInitWorld(const std::string &path, const std::string &name,
                conf.set("backend", "sqlite3");
                conf.set("player_backend", "sqlite3");
                conf.set("auth_backend", "sqlite3");
+               conf.set("mod_storage_backend", "sqlite3");
                conf.setBool("creative_mode", g_settings->getBool("creative_mode"));
                conf.setBool("enable_damage", g_settings->getBool("enable_damage"));
 
@@ -359,18 +399,25 @@ void loadGameConfAndInitWorld(const std::string &path, const std::string &name,
        // Create map_meta.txt if does not already exist
        std::string map_meta_path = final_path + DIR_DELIM + "map_meta.txt";
        if (!fs::PathExists(map_meta_path)) {
-               verbosestream << "Creating map_meta.txt (" << map_meta_path << ")"
-                             << std::endl;
-               std::ostringstream oss(std::ios_base::binary);
-
-               Settings conf;
-               MapgenParams params;
+               MapSettingsManager mgr(map_meta_path);
 
-               params.readParams(g_settings);
-               params.writeParams(&conf);
-               conf.writeLines(oss);
-               oss << "[end_of_params]\n";
+               mgr.setMapSetting("seed", g_settings->get("fixed_map_seed"));
 
-               fs::safeWriteToFile(map_meta_path, oss.str());
+               mgr.makeMapgenParams();
+               mgr.saveMapMeta();
        }
+
+       // The Settings object is no longer needed for created worlds
+       if (new_game_settings)
+               delete game_settings;
+}
+
+std::vector<std::string> getEnvModPaths()
+{
+       const char *c_mod_path = getenv("MINETEST_MOD_PATH");
+       std::vector<std::string> paths;
+       Strfnd search_paths(c_mod_path ? c_mod_path : "");
+       while (!search_paths.at_end())
+               paths.push_back(search_paths.next(PATH_DELIM));
+       return paths;
 }