Improve auto-restart

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

View File

@ -81,14 +81,26 @@ function ui.update()
local formspec = "" local formspec = ""
local restart_btn local restart_btn
-- handle errors -- attempt auto restart
if gamedata ~= nil and gamedata.errormessage ~= nil and core.settings:get_bool("auto_connect") == true then 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.reconnect_requested = false
gamedata.errormessage = nil gamedata.errormessage = nil
gamedata.do_reconnect = true gamedata.do_reconnect = true
core.start() core.start()
return 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 = wordwrap_quickhack(gamedata.errormessage or "")
formspec = "size[12,5]" .. formspec = "size[12,5]" ..
"label[0.5,0;" .. fgettext("The server has requested a reconnect:") .. "label[0.5,0;" .. fgettext("The server has requested a reconnect:") ..
@ -195,6 +207,7 @@ core.button_handler = function(fields)
gamedata.selected_world = gamedata.selected_world =
tonumber(core.settings:get("mainmenu_last_selected_world")) tonumber(core.settings:get("mainmenu_last_selected_world"))
end end
core.settings:set("connect_time", os.time())
gamedata.reconnect_requested = false gamedata.reconnect_requested = false
gamedata.errormessage = nil gamedata.errormessage = nil
gamedata.do_reconnect = true 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 if fields["play"] ~= nil or world_doubleclick or fields["key_enter"] then
local selected = core.get_textlist_index("sp_worlds") local selected = core.get_textlist_index("sp_worlds")
gamedata.selected_world = menudata.worldlist:get_raw_index(selected) 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 core.settings:get_bool("enable_server") then
if selected ~= nil and gamedata.selected_world ~= 0 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.port = fields["te_serverport"]
gamedata.address = "" gamedata.address = ""
core.settings:set_bool("auto_connect", false)
core.settings:set("port",gamedata.port) core.settings:set("port",gamedata.port)
if fields["te_serveraddr"] ~= nil then if fields["te_serveraddr"] ~= nil then
core.settings:set("bind_address",fields["te_serveraddr"]) core.settings:set("bind_address",fields["te_serveraddr"])
@ -135,6 +136,8 @@ local function main_button_handler(this, fields, name, tabdata)
else else
if selected ~= nil and gamedata.selected_world ~= 0 then if selected ~= nil and gamedata.selected_world ~= 0 then
gamedata.singleplayer = true gamedata.singleplayer = true
core.settings:set_bool("auto_connect", true)
core.settings:set("connect_time", os.time())
core.start() core.start()
else else
gamedata.errormessage = gamedata.errormessage =

View File

@ -350,6 +350,8 @@ local function main_button_handler(tabview, fields, name, tabdata)
end end
core.settings:set_bool("auto_connect", auto_connect) 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("address", fields.te_address)
core.settings:set("remote_port", fields.te_port) core.settings:set("remote_port", fields.te_port)