From 306d1ab866a3ce820e95f4faf805684cd4122ae4 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 21 Mar 2013 18:48:21 +0200 Subject: [PATCH 1/5] Common mods support Implement "common mods", includeable from {$user,$share}/games/common/$modname by using the game.conf setting common_mods = $modname,$modname2,... --- src/mods.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++-- src/server.cpp | 4 ++-- src/subgame.cpp | 15 +++++++++++--- src/subgame.h | 4 ++++ 4 files changed, 68 insertions(+), 7 deletions(-) diff --git a/src/mods.cpp b/src/mods.cpp index ac2d9b17..6a7ab79a 100644 --- a/src/mods.cpp +++ b/src/mods.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" #include "subgame.h" #include "settings.h" +#include "strfnd.h" std::map getModsInPath(std::string path) { @@ -188,11 +189,58 @@ void ModConfiguration::addMods(std::vector new_mods) } } +// If failed, returned modspec has name=="" +static 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 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 + m_sorted_mods.push_back(spec); + } + } + } + if(!inexistent_common_mods.empty()){ + std::string s = "Required common mods "; + for(u32 i=0; i::const_iterator i = gamespec.addon_mods_paths.begin(); - i != gamespec.addon_mods_paths.end(); ++i) + i != gamespec.addon_mods_paths.end(); ++i) addModsInPathFiltered((*i),exclude_mod_names); } diff --git a/src/server.cpp b/src/server.cpp index d699dc9d..2dcab63b 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -736,10 +736,10 @@ Server::Server( } // complain about mods declared to be loaded, but not found for(std::vector::iterator it = m_mods.begin(); - it != m_mods.end(); ++it) + it != m_mods.end(); ++it) load_mod_names.erase((*it).name); for(std::list::iterator it = unsatisfied_mods.begin(); - it != unsatisfied_mods.end(); ++it) + it != unsatisfied_mods.end(); ++it) load_mod_names.erase((*it).name); if(!load_mod_names.empty()) { diff --git a/src/subgame.cpp b/src/subgame.cpp index 3c8bf53c..8678ae37 100644 --- a/src/subgame.cpp +++ b/src/subgame.cpp @@ -24,12 +24,16 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" #include "util/string.h" -std::string getGameName(const std::string &game_path) +bool getGameConfig(const std::string &game_path, Settings &conf) { std::string conf_path = game_path + DIR_DELIM + "game.conf"; + return conf.readConfigFile(conf_path.c_str()); +} + +std::string getGameName(const std::string &game_path) +{ Settings conf; - bool succeeded = conf.readConfigFile(conf_path.c_str()); - if(!succeeded) + if(!getGameConfig(game_path, conf)) return ""; if(!conf.exists("name")) return ""; @@ -117,6 +121,11 @@ std::set getAvailableGameIds() for(u32 j=0; j #include +class Settings; + #define WORLDNAME_BLACKLISTED_CHARS "/\\" struct SubgameSpec @@ -52,6 +54,8 @@ struct SubgameSpec } }; +bool getGameConfig(const std::string &game_path, Settings &conf); + std::string getGameName(const std::string &game_path); SubgameSpec findSubgame(const std::string &id); From 0747c285cd383925f94268259ef0f0693e2d3439 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 21 Mar 2013 19:43:08 +0200 Subject: [PATCH 2/5] Update README.txt to instruct to get minetest/common too --- README.txt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/README.txt b/README.txt index 20917d77..d2de68d5 100644 --- a/README.txt +++ b/README.txt @@ -9,9 +9,10 @@ and contributors (see source file comments and the version control log) In case you downloaded the source code: --------------------------------------- If you downloaded the Minetest Engine source code in which this file is -contained, you probably want to download the minetest_game project too: +contained, you probably want to download these projects too: + https://github.com/minetest/common/ https://github.com/minetest/minetest_game/ -See the README.txt in it. +See the README.txt in them. Further documentation ---------------------- @@ -87,10 +88,17 @@ $ wget https://github.com/minetest/minetest/tarball/master -O master.tar.gz $ tar xf master.tar.gz $ cd minetest-minetest-286edd4 (or similar) +Download common (needed for minetest_game and some others) +$ cd games/ +$ wget https://github.com/minetest/common/tarball/master -O common.tar.gz +$ tar xf common.tar.gz +$ mv minetest-common-* common +$ cd .. + Download minetest_game (otherwise only the "Minimal development test" game is available) $ cd games/ -$ wget https://github.com/minetest/minetest_game/tarball/master -O master.tar.gz -$ tar xf master.tar.gz +$ wget https://github.com/minetest/minetest_game/tarball/master -O minetest_game.tar.gz +$ tar xf minetest_game.tar.gz $ mv minetest-minetest_game-* minetest_game $ cd .. @@ -111,7 +119,7 @@ $ ./minetest Compiling on Windows: --------------------- - This section is outdated. In addition to what is described here: - - In addition to minetest, you need to download minetest_game. + - In addition to minetest, you need to download common and minetest_game. - If you wish to have sound support, you need libogg, libvorbis and libopenal - You need: From 0a568a6037a6e97ffff747fbb7bcb04d0f9c4b16 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 21 Mar 2013 19:45:13 +0200 Subject: [PATCH 3/5] Update buildwin32.sh to get minetest/common --- util/buildbot/buildwin32.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/util/buildbot/buildwin32.sh b/util/buildbot/buildwin32.sh index fc42db8a..0c0d7cf2 100755 --- a/util/buildbot/buildwin32.sh +++ b/util/buildbot/buildwin32.sh @@ -53,6 +53,9 @@ cd $builddir wget http://github.com/minetest/minetest/zipball/master \ -c -O $packagedir/minetest.zip --tries=3 || (echo "Please download http://github.com/minetest/minetest/zipball/master manually and save it as $packagedir/minetest.zip"; read -s) [ -e $packagedir/minetest.zip ] || (echo "minetest.zip not found"; exit 1) +wget http://github.com/minetest/common/zipball/master \ + -c -O $packagedir/common.zip --tries=3 || (echo "Please download http://github.com/minetest/common/zipball/master manually and save it as $packagedir/common.zip"; read -s) +[ -e $packagedir/common.zip ] || (echo "common.zip not found"; exit 1) wget http://github.com/minetest/minetest_game/zipball/master \ -c -O $packagedir/minetest_game.zip --tries=3 || (echo "Please download http://github.com/minetest/minetest_game/zipball/master manually and save it as $packagedir/minetest_game.zip"; read -s) [ -e $packagedir/minetest_game.zip ] || (echo "minetest_game.zip not found"; exit 1) @@ -66,6 +69,7 @@ wget http://github.com/minetest/minetest_game/zipball/master \ minetestdirname=`unzip -l $packagedir/minetest.zip | head -n 7 | tail -n 1 | sed -e 's/^[^m]*//' -e 's/\/.*$//'` minetestdir=$builddir/$minetestdirname || exit 1 git_hash=`echo $minetestdirname | sed -e 's/minetest-minetest-//'` +commondirname=`unzip -l $packagedir/common.zip | head -n 7 | tail -n 1 | sed -e 's/^[^m]*//' -e 's/\/.*$//'` minetest_gamedirname=`unzip -l $packagedir/minetest_game.zip | head -n 7 | tail -n 1 | sed -e 's/^[^m]*//' -e 's/\/.*$//'` # Extract stuff @@ -86,6 +90,13 @@ unzip -o $packagedir/minetest.zip || exit 1 rm -rf $builddir/minetest ln -s $minetestdir $builddir/minetest +# Extract common +cd $minetestdir/games || exit 1 +rm -rf common || exit 1 +unzip -o $packagedir/common.zip || exit 1 +commondir=$minetestdir/games/$commondirname || exit 1 +mv $commondir $minetestdir/games/common || exit 1 + # Extract minetest_game cd $minetestdir/games || exit 1 rm -rf minetest_game || exit 1 From adc52f3f3c041e5914f665b6f96d07f49bbb6487 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 21 Mar 2013 20:04:00 +0200 Subject: [PATCH 4/5] lua_api.txt: Document paths, games and common mod loading --- doc/lua_api.txt | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 7d8fa149..19fa8147 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -27,6 +27,36 @@ Startup Mods are loaded during server startup from the mod load paths by running the init.lua scripts in a shared environment. +Paths +----- +RUN_IN_PLACE=1: (Windows release, local build) + $path_user: Linux: + Windows: + $path_share: Linux: + Windows: + +RUN_IN_PLACE=0: (Linux release) + $path_share: Linux: /usr/share/minetest + Windows: /minetest-0.4.x + $path_user: Linux: ~/.minetest + Windows: C:/users//AppData/minetest (maybe) + +Games +----- +Games are looked up from: + $path_share/games/gameid/ + $path_user/games/gameid/ +where gameid is unique to each game. + +The game directory contains the file game.conf, which contains these fields: + name = + common_mods = +eg. + name = Minetest + common_mods = bucket, default, doors, fire, stairs + +Common mods are loaded from the pseudo-game "common". + Mod load path ------------- Generic: From c2250d95c4da368d1535794a1c7f2092ce479d7a Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 21 Mar 2013 21:42:23 +0200 Subject: [PATCH 5/5] Support game-specific minetest.conf --- doc/lua_api.txt | 3 +++ src/defaultsettings.cpp | 9 +++++++++ src/defaultsettings.h | 1 + src/server.cpp | 8 ++++++++ src/subgame.cpp | 6 ++++++ src/subgame.h | 3 +++ 6 files changed, 30 insertions(+) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 19fa8147..af8b1cc9 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -57,6 +57,9 @@ eg. Common mods are loaded from the pseudo-game "common". +The game directory can contain the file minetest.conf, which will be used +to set default settings when running the particular game. + Mod load path ------------- Generic: diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index b0ae271c..25edffe3 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -243,3 +243,12 @@ void set_default_settings(Settings *settings) } +void override_default_settings(Settings *settings, Settings *from) +{ + std::vector names = from->getNames(); + for(size_t i=0; isetDefault(name, from->get(name)); + } +} + diff --git a/src/defaultsettings.h b/src/defaultsettings.h index 37e3f717..00aacad8 100644 --- a/src/defaultsettings.h +++ b/src/defaultsettings.h @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., class Settings; void set_default_settings(Settings *settings); +void override_default_settings(Settings *settings, Settings *from); #endif diff --git a/src/server.cpp b/src/server.cpp index 2dcab63b..f77ac6ad 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -58,6 +58,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/mathconstants.h" #include "rollback.h" #include "util/serialize.h" +#include "defaultsettings.h" void * ServerThread::Thread() { @@ -687,6 +688,13 @@ Server::Server( infostream<<"- config: "<