Split server/client port setting to avoid port number clashes in mainmenu
authorsapier <Sapier at GMX dot net>
Thu, 28 Nov 2013 20:43:06 +0000 (21:43 +0100)
committersapier <Sapier at GMX dot net>
Thu, 28 Nov 2013 20:43:06 +0000 (21:43 +0100)
builtin/mainmenu.lua
minetest.conf.example
src/defaultsettings.cpp
src/main.cpp

index c09b9cbcd5461be21f2f3665dabba38544f1a235..0032017acc2b932048be1e22b1a1f1b0382ffffd 100644 (file)
@@ -421,37 +421,42 @@ function tabbuilder.handle_multiplayer_buttons(fields)
        if fields["favourites"] ~= nil then
                local event = explode_textlist_event(fields["favourites"])
                if event.typ == "DCL" then
-                       gamedata.address = menu.favorites[event.index].address
-                       gamedata.port = menu.favorites[event.index].port
-                       gamedata.playername             = fields["te_name"]
-                       if fields["te_pwd"] ~= nil then
-                               gamedata.password               = fields["te_pwd"]
-                       end
-                       gamedata.selected_world = 0
-                       
-                       if menu.favorites ~= nil then
-                               gamedata.servername = menu.favorites[event.index].name
-                               gamedata.serverdescription = menu.favorites[event.index].description
-                       end
-                       
-                       if gamedata.address ~= nil and
-                               gamedata.port ~= nil then
+                       if event.index <= #menu.favorites then
+                               gamedata.address = menu.favorites[event.index].address
+                               gamedata.port = menu.favorites[event.index].port
+                               gamedata.playername             = fields["te_name"]
+                               if fields["te_pwd"] ~= nil then
+                                       gamedata.password               = fields["te_pwd"]
+                               end
+                               gamedata.selected_world = 0
+                               
+                               if menu.favorites ~= nil then
+                                       gamedata.servername = menu.favorites[event.index].name
+                                       gamedata.serverdescription = menu.favorites[event.index].description
+                               end
                                
-                               engine.start()
+                               if gamedata.address ~= nil and
+                                       gamedata.port ~= nil then
+                                       engine.setting_set("address",gamedata.address)
+                                       engine.setting_set("remote_port",gamedata.port)
+                                       engine.start()
+                               end
                        end
                end
                
                if event.typ == "CHG" then
-                       local address = menu.favorites[event.index].address
-                       local port = menu.favorites[event.index].port
-                       
-                       if address ~= nil and
-                               port ~= nil then
-                               engine.setting_set("address",address)
-                               engine.setting_set("port",port)
+                       if event.index <= #menu.favorites then
+                               local address = menu.favorites[event.index].address
+                               local port = menu.favorites[event.index].port
+                               
+                               if address ~= nil and
+                                       port ~= nil then
+                                       engine.setting_set("address",address)
+                                       engine.setting_set("remote_port",port)
+                               end
+                               
+                               menu.fav_selected = event.index
                        end
-                       
-                       menu.fav_selected = event.index
                end
                return
        end
@@ -473,7 +478,7 @@ function tabbuilder.handle_multiplayer_buttons(fields)
                if address ~= nil and
                        port ~= nil then
                        engine.setting_set("address",address)
-                       engine.setting_set("port",port)
+                       engine.setting_set("remote_port",port)
                end
                
                menu.fav_selected = fav_idx
@@ -499,13 +504,13 @@ function tabbuilder.handle_multiplayer_buttons(fields)
                menu.fav_selected = nil
                
                engine.setting_set("address","")
-               engine.setting_get("port","")
+               engine.setting_set("remote_port","30000")
                
                return
        end
 
        if fields["btn_mp_connect"] ~= nil or
-               fields["key_enter"] then
+               fields["key_enter"] ~= nil then
                
                gamedata.playername             = fields["te_name"]
                gamedata.password               = fields["te_pwd"]
@@ -516,17 +521,20 @@ function tabbuilder.handle_multiplayer_buttons(fields)
                
                if fav_idx > 0 and fav_idx <= #menu.favorites and
                        menu.favorites[fav_idx].address == fields["te_address"] and
-                       menu.favorites[fav_idx].port == fields["te_port"] then
+                       menu.favorites[fav_idx].port    == fields["te_port"] then
                        
                        gamedata.servername                     = menu.favorites[fav_idx].name
                        gamedata.serverdescription      = menu.favorites[fav_idx].description
                else
-                       gamedata.servername = ""
-                       gamedata.serverdescription = ""
+                       gamedata.servername                     = ""
+                       gamedata.serverdescription      = ""
                end
 
                gamedata.selected_world = 0
                
+               engine.setting_set("address",fields["te_address"])
+               engine.setting_set("remote_port",fields["te_port"])
+               
                engine.start()
                return
        end
@@ -574,6 +582,7 @@ function tabbuilder.handle_server_buttons(fields)
                        gamedata.address                = ""
                        gamedata.selected_world = filterlist.get_raw_index(worldlist,selected)
                        
+                       engine.setting_set("port",gamedata.port)
                        menu.update_last_game(gamedata.selected_world)
                        engine.start()
                end
@@ -820,7 +829,7 @@ function tabbuilder.tab_multiplayer()
                "label[1,4.25;".. fgettext("Address/Port") .. "]"..
                "label[9,2.75;".. fgettext("Name/Password") .. "]" ..
                "field[1.25,5.25;5.5,0.5;te_address;;" ..engine.setting_get("address") .."]" ..
-               "field[6.75,5.25;2.25,0.5;te_port;;" ..engine.setting_get("port") .."]" ..
+               "field[6.75,5.25;2.25,0.5;te_port;;" ..engine.setting_get("remote_port") .."]" ..
                "checkbox[1,3.6;cb_public_serverlist;".. fgettext("Public Serverlist") .. ";" ..
                dump(engine.setting_getbool("public_serverlist")) .. "]"
                
@@ -886,7 +895,8 @@ function tabbuilder.tab_server()
                "field[0.8,3.2;3,0.5;te_playername;".. fgettext("Name") .. ";" ..
                engine.setting_get("name") .. "]" ..
                "pwdfield[0.8,4.2;3,0.5;te_passwd;".. fgettext("Password") .. "]" ..
-               "field[0.8,5.2;3,0.5;te_serverport;".. fgettext("Server Port") .. ";30000]" ..
+               "field[0.8,5.2;3,0.5;te_serverport;".. fgettext("Server Port") .. ";" .. 
+               engine.setting_get("port") .."]" ..
                "textlist[4,0.25;7.5,3.7;srv_worlds;" ..
                menu.render_world_list() ..
                ";" .. index .. "]"
index ee22e9f04050990318b5e7c62ef6db27a0287fce..69ed31a64e7bb28c2e858a66cc7809d6f423604e 100644 (file)
@@ -22,8 +22,7 @@
 # Client and server
 #
 
-# Network port (UDP)
-#port = 
+
 # Name of player; on a server this is the main admin
 #name = 
 
@@ -31,6 +30,8 @@
 # Client stuff
 #
 
+# Port to connect to (UDP)
+#remote_port = 
 # Key mappings
 # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
 #keymap_forward = KEY_KEY_W
 #
 # Server stuff
 #
-
+# Network port to listen (UDP)
+#port = 
 # Name of server
 #server_name = Minetest server
 # Description of server
index 9df9b3aa54523fbc52b6b9b6551040f64006847e..df7570b335fd6f45272f444905c5ae46b55dccf8 100644 (file)
@@ -25,11 +25,10 @@ void set_default_settings(Settings *settings)
 {
        // Client and server
 
-       settings->setDefault("port", "");
        settings->setDefault("name", "");
 
        // Client stuff
-
+       settings->setDefault("remote_port", "30000");
        settings->setDefault("keymap_forward", "KEY_KEY_W");
        settings->setDefault("keymap_backward", "KEY_KEY_S");
        settings->setDefault("keymap_left", "KEY_KEY_A");
@@ -157,6 +156,7 @@ void set_default_settings(Settings *settings)
 
        // Server stuff
        // "map-dir" doesn't exist by default.
+       settings->setDefault("port", "30000");
        settings->setDefault("default_game", "minetest");
        settings->setDefault("motd", "");
        settings->setDefault("max_users", "15");
index 9ffab816efd2b1411dbc33e88b9624e0dddd4dea..373e1ca9678bedcca525d0e5e73679812982a689 100644 (file)
@@ -1674,8 +1674,6 @@ int main(int argc, char *argv[])
 
                                // Save settings
                                g_settings->set("name", playername);
-                               g_settings->set("address", address);
-                               g_settings->set("port", itos(port));
 
                                if((menudata.selected_world >= 0) &&
                                                (menudata.selected_world < (int)worldspecs.size()))