From 306d1ab866a3ce820e95f4faf805684cd4122ae4 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 21 Mar 2013 18:48:21 +0200 Subject: [PATCH] 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 ac2d9b17d..6a7ab79aa 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 d699dc9d2..2dcab63b8 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 3c8bf53c5..8678ae37f 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);