diff --git a/builtin/fstk/ui.lua b/builtin/fstk/ui.lua index 6961545c..b7e28653 100644 --- a/builtin/fstk/ui.lua +++ b/builtin/fstk/ui.lua @@ -81,14 +81,26 @@ function ui.update() local formspec = "" local restart_btn - -- handle errors - if gamedata ~= nil and gamedata.errormessage ~= nil and core.settings:get_bool("auto_connect") == true then + -- attempt auto restart + if gamedata ~= nil and gamedata.errormessage ~= nil and + core.settings:get_bool("auto_connect") == true and + tonumber(core.settings:get("connect_time")) < os.time() - 30 --[[and + not string.find(gamedata.errormessage, "Access denied")]] then + if core.settings:get("maintab_LAST") == "local" then + gamedata.singleplayer = true + gamedata.selected_world = + tonumber(core.settings:get("mainmenu_last_selected_world")) + end + core.settings:set("connect_time", os.time()) gamedata.reconnect_requested = false gamedata.errormessage = nil gamedata.do_reconnect = true core.start() return - elseif gamedata ~= nil and gamedata.reconnect_requested then + end + + -- handle errors + if gamedata ~= nil and gamedata.reconnect_requested then formspec = wordwrap_quickhack(gamedata.errormessage or "") formspec = "size[12,5]" .. "label[0.5,0;" .. fgettext("The server has requested a reconnect:") .. @@ -195,6 +207,7 @@ core.button_handler = function(fields) gamedata.selected_world = tonumber(core.settings:get("mainmenu_last_selected_world")) end + core.settings:set("connect_time", os.time()) gamedata.reconnect_requested = false gamedata.errormessage = nil gamedata.do_reconnect = true diff --git a/builtin/mainmenu/tab_local.lua b/builtin/mainmenu/tab_local.lua index 1ee093ae..a45f3ef3 100644 --- a/builtin/mainmenu/tab_local.lua +++ b/builtin/mainmenu/tab_local.lua @@ -106,7 +106,7 @@ local function main_button_handler(this, fields, name, tabdata) if fields["play"] ~= nil or world_doubleclick or fields["key_enter"] then local selected = core.get_textlist_index("sp_worlds") gamedata.selected_world = menudata.worldlist:get_raw_index(selected) - core.settings:set_bool("auto_connect", false) + core.settings:set("maintab_LAST", "local") if core.settings:get_bool("enable_server") then if selected ~= nil and gamedata.selected_world ~= 0 then @@ -115,6 +115,7 @@ local function main_button_handler(this, fields, name, tabdata) gamedata.port = fields["te_serverport"] gamedata.address = "" + core.settings:set_bool("auto_connect", false) core.settings:set("port",gamedata.port) if fields["te_serveraddr"] ~= nil then core.settings:set("bind_address",fields["te_serveraddr"]) @@ -135,6 +136,8 @@ local function main_button_handler(this, fields, name, tabdata) else if selected ~= nil and gamedata.selected_world ~= 0 then gamedata.singleplayer = true + core.settings:set_bool("auto_connect", true) + core.settings:set("connect_time", os.time()) core.start() else gamedata.errormessage = diff --git a/builtin/mainmenu/tab_online.lua b/builtin/mainmenu/tab_online.lua index 57a339e2..7694c879 100644 --- a/builtin/mainmenu/tab_online.lua +++ b/builtin/mainmenu/tab_online.lua @@ -350,6 +350,8 @@ local function main_button_handler(tabview, fields, name, tabdata) end core.settings:set_bool("auto_connect", auto_connect) + core.settings:set("connect_time", os.time()) + core.settings:set("maintab_LAST", "online") core.settings:set("address", fields.te_address) core.settings:set("remote_port", fields.te_port)