Allow using --worldname for local game too
authorPerttu Ahola <celeron55@gmail.com>
Sun, 20 May 2012 14:41:40 +0000 (17:41 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 20 May 2012 14:41:40 +0000 (17:41 +0300)
src/main.cpp

index ec305d4bf4b9209208201860641ce26f5432eee1..a990032dfdec83c46eafad7d14d2998298d720b4 100644 (file)
@@ -1037,6 +1037,31 @@ int main(int argc, char *argv[])
                }
        }
        
+       // If a world name was specified, convert it to a path
+       if(commanded_worldname != ""){
+               // Get information about available worlds
+               std::vector<WorldSpec> worldspecs = getAvailableWorlds();
+               bool found = false;
+               for(u32 i=0; i<worldspecs.size(); i++){
+                       std::string name = worldspecs[i].name;
+                       if(name == commanded_worldname){
+                               if(commanded_world != ""){
+                                       dstream<<"--worldname takes precedence over previously "
+                                                       <<"selected world."<<std::endl;
+                               }
+                               commanded_world = worldspecs[i].path;
+                               found = true;
+                               break;
+                       }
+               }
+               if(!found){
+                       dstream<<"World '"<<commanded_worldname<<"' not "
+                                       <<"available. Available worlds:"<<std::endl;
+                       print_worldspecs(worldspecs, dstream);
+                       return 1;
+               }
+       }
+
        // Gamespec
        SubgameSpec commanded_gamespec;
        if(cmd_args.exists("gameid")){
@@ -1074,25 +1099,6 @@ int main(int argc, char *argv[])
                        infostream<<"Using commanded world path ["<<world_path<<"]"
                                        <<std::endl;
                }
-               // If a world name was specified, select it
-               else if(commanded_worldname != ""){
-                       // Get information about available worlds
-                       std::vector<WorldSpec> worldspecs = getAvailableWorlds();
-                       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;
-                       }
-               }
                // No world was specified; try to select it automatically
                else
                {
@@ -1207,8 +1213,6 @@ int main(int argc, char *argv[])
                address = "";
        else if(cmd_args.exists("address"))
                address = cmd_args.get("address");
-       else if(cmd_args.exists("world"))
-               address = "";
        
        std::string playername = g_settings->get("name");
        if(cmd_args.exists("name"))