diff --git a/quant.ew/files/core/net.lua b/quant.ew/files/core/net.lua index 83a7fd18..38beddc0 100644 --- a/quant.ew/files/core/net.lua +++ b/quant.ew/files/core/net.lua @@ -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 diff --git a/quant.ew/init.lua b/quant.ew/init.lua index a82affaf..8924e0f0 100755 --- a/quant.ew/init.lua +++ b/quant.ew/init.lua @@ -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()