summaryrefslogtreecommitdiff
path: root/src/subgame.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-03-11 20:45:14 +0200
committerPerttu Ahola <celeron55@gmail.com>2012-03-11 20:45:14 +0200
commitd1d83d7e7f5e2e7cbef5272eda9c580129e301a3 (patch)
tree2fc04eeae8cac55e6d17cccceecb9450fddd4f12 /src/subgame.cpp
parentbcaab74f1f4cb8c9fcd65cc8cb8bd290834bf72f (diff)
downloadminetest-d1d83d7e7f5e2e7cbef5272eda9c580129e301a3.tar.gz
minetest-d1d83d7e7f5e2e7cbef5272eda9c580129e301a3.tar.bz2
minetest-d1d83d7e7f5e2e7cbef5272eda9c580129e301a3.zip
World selection box in main menu (and random fixing)
Diffstat (limited to 'src/subgame.cpp')
-rw-r--r--src/subgame.cpp57
1 files changed, 55 insertions, 2 deletions
diff --git a/src/subgame.cpp b/src/subgame.cpp
index ed50d09a4..2fa3b7944 100644
--- a/src/subgame.cpp
+++ b/src/subgame.cpp
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "porting.h"
#include "filesys.h"
#include "settings.h"
+#include "log.h"
SubgameSpec findSubgame(const std::string &id)
{
@@ -68,15 +69,67 @@ std::set<std::string> getAvailableGameIds()
return gameids;
}
-std::string getWorldGameId(const std::string &world_path)
+#define LEGACY_GAMEID "mesetint"
+
+std::string getWorldGameId(const std::string &world_path, bool can_be_legacy)
{
std::string conf_path = world_path + DIR_DELIM + "world.mt";
Settings conf;
bool succeeded = conf.readConfigFile(conf_path.c_str());
- if(!succeeded)
+ if(!succeeded){
+ if(can_be_legacy){
+ // If map_meta.txt exists, it is probably an old minetest world
+ if(fs::PathExists(world_path + DIR_DELIM + "map_meta.txt"))
+ return LEGACY_GAMEID;
+ }
return "";
+ }
if(!conf.exists("gameid"))
return "";
return conf.get("gameid");
}
+std::vector<WorldSpec> getAvailableWorlds()
+{
+ std::vector<WorldSpec> worlds;
+ std::set<std::string> worldspaths;
+ worldspaths.insert(porting::path_user + DIR_DELIM + "server"
+ + DIR_DELIM + "worlds");
+ infostream<<"Searching worlds..."<<std::endl;
+ for(std::set<std::string>::const_iterator i = worldspaths.begin();
+ i != worldspaths.end(); i++){
+ infostream<<" In "<<(*i)<<": "<<std::endl;
+ std::vector<fs::DirListNode> dirvector = fs::GetDirListing(*i);
+ for(u32 j=0; j<dirvector.size(); j++){
+ if(!dirvector[j].dir)
+ continue;
+ std::string fullpath = *i + DIR_DELIM + dirvector[j].name;
+ std::string name = dirvector[j].name;
+ std::string gameid = getWorldGameId(fullpath);
+ WorldSpec spec(fullpath, name, gameid);
+ if(!spec.isValid()){
+ infostream<<"(invalid: "<<name<<") ";
+ } else {
+ infostream<<name<<" ";
+ worlds.push_back(spec);
+ }
+ }
+ infostream<<std::endl;
+ }
+ // Check old world location
+ do{
+ std::string fullpath = porting::path_user + DIR_DELIM + ".."
+ + DIR_DELIM + "world";
+ if(!fs::PathExists(fullpath))
+ break;
+ std::string name = "Old World";
+ std::string gameid = getWorldGameId(fullpath, true);
+ WorldSpec spec(fullpath, name, gameid);
+ infostream<<"Old world found."<<std::endl;
+ worlds.push_back(spec);
+ }while(0);
+ infostream<<worlds.size()<<" found."<<std::endl;
+ return worlds;
+}
+
+