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.
26 SubgameSpec findSubgame(const std::string &id)
30 std::string share_server = porting::path_share + DIR_DELIM + "server";
31 std::string user_server = porting::path_user + DIR_DELIM + "server";
32 // Find game directory
33 std::string game_path =
34 user_server + DIR_DELIM + "games" + DIR_DELIM + id;
35 bool user_game = true; // Game is in user's directory
36 if(!fs::PathExists(game_path)){
37 game_path = share_server + DIR_DELIM + "games" + DIR_DELIM + id;
40 if(!fs::PathExists(game_path))
42 // Find addon directories
43 std::set<std::string> addon_paths;
45 addon_paths.insert(share_server + DIR_DELIM + "addons"
47 addon_paths.insert(user_server + DIR_DELIM + "addons"
49 return SubgameSpec(id, game_path, addon_paths);
52 std::set<std::string> getAvailableGameIds()
54 std::set<std::string> gameids;
55 std::set<std::string> gamespaths;
56 gamespaths.insert(porting::path_share + DIR_DELIM + "server"
57 + DIR_DELIM + "games");
58 gamespaths.insert(porting::path_user + DIR_DELIM + "server"
59 + DIR_DELIM + "games");
60 for(std::set<std::string>::const_iterator i = gamespaths.begin();
61 i != gamespaths.end(); i++){
62 std::vector<fs::DirListNode> dirlist = fs::GetDirListing(*i);
63 for(u32 j=0; j<dirlist.size(); j++){
66 gameids.insert(dirlist[j].name);
72 #define LEGACY_GAMEID "mesetint"
74 std::string getWorldGameId(const std::string &world_path, bool can_be_legacy)
76 std::string conf_path = world_path + DIR_DELIM + "world.mt";
78 bool succeeded = conf.readConfigFile(conf_path.c_str());
81 // If map_meta.txt exists, it is probably an old minetest world
82 if(fs::PathExists(world_path + DIR_DELIM + "map_meta.txt"))
87 if(!conf.exists("gameid"))
89 return conf.get("gameid");
92 std::vector<WorldSpec> getAvailableWorlds()
94 std::vector<WorldSpec> worlds;
95 std::set<std::string> worldspaths;
96 worldspaths.insert(porting::path_user + DIR_DELIM + "server"
97 + DIR_DELIM + "worlds");
98 infostream<<"Searching worlds..."<<std::endl;
99 for(std::set<std::string>::const_iterator i = worldspaths.begin();
100 i != worldspaths.end(); i++){
101 infostream<<" In "<<(*i)<<": "<<std::endl;
102 std::vector<fs::DirListNode> dirvector = fs::GetDirListing(*i);
103 for(u32 j=0; j<dirvector.size(); j++){
104 if(!dirvector[j].dir)
106 std::string fullpath = *i + DIR_DELIM + dirvector[j].name;
107 std::string name = dirvector[j].name;
108 std::string gameid = getWorldGameId(fullpath);
109 WorldSpec spec(fullpath, name, gameid);
111 infostream<<"(invalid: "<<name<<") ";
113 infostream<<name<<" ";
114 worlds.push_back(spec);
117 infostream<<std::endl;
119 // Check old world location
121 std::string fullpath = porting::path_user + DIR_DELIM + ".."
122 + DIR_DELIM + "world";
123 if(!fs::PathExists(fullpath))
125 std::string name = "Old World";
126 std::string gameid = getWorldGameId(fullpath, true);
127 WorldSpec spec(fullpath, name, gameid);
128 infostream<<"Old world found."<<std::endl;
129 worlds.push_back(spec);
131 infostream<<worlds.size()<<" found."<<std::endl;