+
+ // World directory
+ std::string world_path;
+ verbosestream<<_("Determining world path")<<std::endl;
+ bool is_legacy_world = false;
+ // If a world was commanded, use it
+ if(commanded_world != ""){
+ world_path = commanded_world;
+ infostream<<"Using commanded world path ["<<world_path<<"]"
+ <<std::endl;
+ }
+ // No world was specified; try to select it automatically
+ else
+ {
+ // Get information about available worlds
+ std::vector<WorldSpec> worldspecs = getAvailableWorlds();
+ // If a world name was specified, select it
+ if(commanded_worldname != ""){
+ world_path = "";
+ for(u32 i=0; i<worldspecs.size(); i++){
+ std::string name = worldspecs[i].name;
+ if(name == commanded_worldname){
+ world_path = worldspecs[i].path;
+ break;
+ }
+ }
+ if(world_path == ""){
+ dstream<<_("World")<<" '"<<commanded_worldname<<"' "<<_("not "
+ "available. Available worlds:")<<std::endl;
+ print_worldspecs(worldspecs, dstream);
+ return 1;
+ }
+ }
+ // If there is only a single world, use it
+ if(worldspecs.size() == 1){
+ world_path = worldspecs[0].path;
+ dstream<<_("Automatically selecting world at")<<" ["
+ <<world_path<<"]"<<std::endl;
+ // If there are multiple worlds, list them
+ } else if(worldspecs.size() > 1){
+ dstream<<_("Multiple worlds are available.")<<std::endl;
+ dstream<<_("Please select one using --worldname <name>"
+ " or --world <path>")<<std::endl;
+ print_worldspecs(worldspecs, dstream);
+ return 1;
+ // If there are no worlds, automatically create a new one
+ } else {
+ // This is the ultimate default world path
+ world_path = porting::path_user + DIR_DELIM + "worlds" +
+ DIR_DELIM + "world";
+ infostream<<"Creating default world at ["
+ <<world_path<<"]"<<std::endl;
+ }
+ }
+
+ if(world_path == ""){
+ errorstream<<"No world path specified or found."<<std::endl;
+ return 1;
+ }
+ verbosestream<<_("Using world path")<<" ["<<world_path<<"]"<<std::endl;
+
+ // We need a gamespec.
+ SubgameSpec gamespec;
+ verbosestream<<_("Determining gameid/gamespec")<<std::endl;
+ // If world doesn't exist
+ if(!getWorldExists(world_path))
+ {
+ // Try to take gamespec from command line
+ if(commanded_gamespec.isValid()){
+ gamespec = commanded_gamespec;
+ infostream<<"Using commanded gameid ["<<gamespec.id<<"]"<<std::endl;
+ }
+ // Otherwise we will be using "minetest"
+ else{
+ gamespec = findSubgame(g_settings->get("default_game"));
+ infostream<<"Using default gameid ["<<gamespec.id<<"]"<<std::endl;
+ }
+ }
+ // World exists
+ else
+ {
+ std::string world_gameid = getWorldGameId(world_path, is_legacy_world);
+ // If commanded to use a gameid, do so
+ if(commanded_gamespec.isValid()){
+ gamespec = commanded_gamespec;
+ if(commanded_gamespec.id != world_gameid){
+ errorstream<<"WARNING: Using commanded gameid ["
+ <<gamespec.id<<"]"<<" instead of world gameid ["
+ <<world_gameid<<"]"<<std::endl;
+ }
+ } else{
+ // If world contains an embedded game, use it;
+ // Otherwise find world from local system.
+ gamespec = findWorldSubgame(world_path);
+ infostream<<"Using world gameid ["<<gamespec.id<<"]"<<std::endl;
+ }
+ }
+ if(!gamespec.isValid()){
+ errorstream<<"Subgame ["<<gamespec.id<<"] could not be found."
+ <<std::endl;
+ return 1;
+ }
+ verbosestream<<_("Using gameid")<<" ["<<gamespec.id<<"]"<<std::endl;
+