3 Copyright (C) 2012 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 SubgameSpec findSubgame(const std::string &id)
29 std::string share_server = porting::path_share + DIR_DELIM + "server";
30 std::string user_server = porting::path_user + DIR_DELIM + "server";
31 // Find game directory
32 std::string game_path =
33 user_server + DIR_DELIM + "games" + DIR_DELIM + id;
34 bool user_game = true; // Game is in user's directory
35 if(!fs::PathExists(game_path)){
36 game_path = share_server + DIR_DELIM + "games" + DIR_DELIM + id;
39 if(!fs::PathExists(game_path))
41 // Find addon directories
42 std::set<std::string> addon_paths;
44 addon_paths.insert(share_server + DIR_DELIM + "addons"
46 addon_paths.insert(user_server + DIR_DELIM + "addons"
48 return SubgameSpec(id, game_path, addon_paths);
51 std::set<std::string> getAvailableGameIds()
53 std::set<std::string> gameids;
54 std::set<std::string> gamespaths;
55 gamespaths.insert(porting::path_share + DIR_DELIM + "server"
56 + DIR_DELIM + "games");
57 gamespaths.insert(porting::path_user + DIR_DELIM + "server"
58 + DIR_DELIM + "games");
59 for(std::set<std::string>::const_iterator i = gamespaths.begin();
60 i != gamespaths.end(); i++){
61 std::vector<fs::DirListNode> dirlist = fs::GetDirListing(*i);
62 for(u32 j=0; j<dirlist.size(); j++){
65 gameids.insert(dirlist[j].name);
71 std::string getWorldGameId(const std::string &world_path)
73 std::string conf_path = world_path + DIR_DELIM + "world.mt";
75 bool succeeded = conf.readConfigFile(conf_path.c_str());
78 if(!conf.exists("gameid"))
80 return conf.get("gameid");