From 62167b8faf8187baa4ec2c5fc2a87910712a8ed3 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Fri, 18 Dec 2020 23:24:52 -0300 Subject: When facing a connection error, do not hang eternally - try again. --- game/04_init.rpy | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'game') diff --git a/game/04_init.rpy b/game/04_init.rpy index 74e0a97..f7c0478 100644 --- a/game/04_init.rpy +++ b/game/04_init.rpy @@ -170,13 +170,30 @@ init python: def supervisor(use_ssl): global ws stdout(_("Opening new socket...")) - if use_ssl: - ws = GameClient("wss://"+HOST+":61000") - else: - ws = GameClient("ws://"+HOST+":61000") - ws.connect() - renpy.invoke_in_thread(ws.run_forever) # May be problematic - stdout("Connection established!") - # The supervisor module is now uneeded as thread was cast + done=False + while not done: + try: + if use_ssl: + ws = GameClient("wss://"+HOST+":61000") + else: + ws = GameClient("ws://"+HOST+":61000") + ws.connect() + # May be problematic. + # Specially if exception is uncaught + renpy.invoke_in_thread(ws.run_forever) + done=True + stdout("Connection established!") + except: + traceback.print_exc() + stdout("CONNECTION FAILED, PLEASE TRY AGAIN") + display_msgbox("Connection Error. Please check internet connection.") + sdelay(10.0) # It will keep trying again, ever and ever. + # FIXME: sdelay(), with fixed time is a bad idea. + # We should allow user to retry (no hard pause) + # And we should scale up the time between attempts + # Just in case server is flooded, we do not want to DoS it =/ + # (And incur in firewall's wrath while at that!) + + # The supervisor module is now uneeded as thread was cast, so return return -- cgit v1.2.3-70-g09d2