Handle failure to connect to proxy by having a message in chat. Also don't crash/hang the game in that case.

This commit is contained in:
IQuant 2024-10-20 12:30:06 +03:00
parent aa8e69fc71
commit 517743a72e
2 changed files with 21 additions and 3 deletions

View file

@ -23,6 +23,7 @@ net._rpc_inner = {
opts = {},
}
net.rpc = {}
net.connect_failed = false
local rpc_inner = net._rpc_inner
@ -177,6 +178,11 @@ function net.init()
while not ready do
reactor:update()
pollnet.sleep_ms(100)
local status = net.sock:status()
if status == "error" or status == "closed" then
net.connect_failed = true
return
end
--print("Waiting for connection...")
end

View file

@ -338,6 +338,14 @@ local function on_world_pre_update_inner()
end
function OnWorldPreUpdate() -- This is called every time the game is about to start updating the world
if net.connect_failed then
if GameGetFrameNum() % 180 == 0 then
GamePrint("Entangled Worlds mod is enabled, but it couldn't connect to proxy!")
GamePrint("You need to start the proxy and join the lobby first.")
GamePrint("If you want to play singleplayer, disable the mod and start a new game.")
end
return
end
util.tpcall(on_world_pre_update_inner)
end
@ -370,6 +378,9 @@ local function on_world_post_update_inner()
end
function OnWorldPostUpdate() -- This is called every time the game has finished updating the world
if net.connect_failed then
return
end
util.tpcall(on_world_post_update_inner)
ctx.events = {}
net.proxy_send("flush", "")
@ -414,9 +425,10 @@ function OnModPreInit()
ctx.init()
net.init()
load_modules()
print("Entangled worlds init ok")
if not net.connect_failed then
load_modules()
print("Entangled worlds init ok")
end
end
function OnModInit()