+std::vector<WorldSpec> getAvailableWorlds()
+{
+ std::vector<WorldSpec> worlds;
+ std::set<std::string> worldspaths;
+ worldspaths.insert(porting::path_user + 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;
+ // Just allow filling in the gameid always for now
+ bool can_be_legacy = true;
+ std::string gameid = getWorldGameId(fullpath, can_be_legacy);
+ 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 + "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;
+}
+
+bool initializeWorld(const std::string &path, const std::string &gameid)
+{
+ infostream<<"Initializing world at "<<path<<std::endl;
+ // Create world.mt if does not already exist
+ std::string worldmt_path = path + DIR_DELIM + "world.mt";
+ if(!fs::PathExists(worldmt_path)){
+ infostream<<"Creating world.mt ("<<worldmt_path<<")"<<std::endl;
+ fs::CreateAllDirs(path);
+ std::ostringstream ss(std::ios_base::binary);
+ ss<<"gameid = "<<gameid<< "\nbackend = sqlite3\n";
+ fs::safeWriteToFile(worldmt_path, ss.str());
+ }
+ return true;
+}
+
+