Improve auto-restart

This commit is contained in:
stujones11 2019-05-22 21:35:29 +01:00 committed by MoNTE48
parent cb3f7c67a5
commit d87179db27
3 changed files with 22 additions and 4 deletions

View File

@ -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

View File

@ -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 =

View File

@ -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)