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"
#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
// 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;
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"))
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)
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;
}
}
}
- // 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;
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"));
// 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;
}