diff options
author | Jesusaves <cpntb1@ymail.com> | 2020-12-29 12:54:54 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2020-12-29 12:54:54 -0300 |
commit | 2cb0ad721acf52a60c5d523caa8a1f83a8801a00 (patch) | |
tree | b6d35a2db4aefa687e5f3bd7dc57b58561c463ea | |
parent | e11698e5a95d801bf42515315fc26dfdf3906d12 (diff) | |
download | client-2cb0ad721acf52a60c5d523caa8a1f83a8801a00.tar.gz client-2cb0ad721acf52a60c5d523caa8a1f83a8801a00.tar.bz2 client-2cb0ad721acf52a60c5d523caa8a1f83a8801a00.tar.xz client-2cb0ad721acf52a60c5d523caa8a1f83a8801a00.zip |
Add a complex watcher which will reboot the game if the socket dies.
-rw-r--r-- | game/01_init.rpy | 3 | ||||
-rw-r--r-- | game/04_init.rpy | 18 | ||||
-rw-r--r-- | game/05_init.rpy | 14 | ||||
-rw-r--r-- | game/script.rpy | 1 |
4 files changed, 32 insertions, 4 deletions
diff --git a/game/01_init.rpy b/game/01_init.rpy index 3dc04ff..58069b9 100644 --- a/game/01_init.rpy +++ b/game/01_init.rpy @@ -60,6 +60,8 @@ init -3 python: CERT_NONE=0 INT_MAX=2147483647 debug=copy.copy(config.developer) + TERMINATE=False + CLOSING=False # Error Codes ERR_JSONDECODER=101 @@ -169,7 +171,6 @@ init -3 python: def now(): return int(time.time()) - # Global classes # We need to override standard list method. Original by Triptych (stackoverflow) class dlist(list): diff --git a/game/04_init.rpy b/game/04_init.rpy index 1b96c0d..f021ed1 100644 --- a/game/04_init.rpy +++ b/game/04_init.rpy @@ -77,6 +77,7 @@ init python: send_packet_now("PING") def onerror(self, err): + global TERMINATE if err == "Quit": return @@ -101,6 +102,7 @@ init python: #renpy.quit(relaunch=True, status=1) except: pass + TERMINATE=True # Relay a TERM to overlay return class GameClient(WebSocketClient): @@ -121,10 +123,22 @@ init python: # Be mindful of where/when using this function # Or "onmsg" may accidentally not be cast =/ def send_packet_now(packet, args=""): - global ws, tr_load, tr_val, tr_busy + global ws, tr_load, tr_val, tr_busy, TERMINATE, CLOSING stdout("Sending: %s" % packet) - ws.send(get_token() + ";" + packet + ";" + args) + try: + ws.send(get_token() + ";" + packet + ";" + args) + except: + traceback.print_exc() + stdout("FATAL ERROR, packet was not sent!") + try: + renpy.call_screen("msgbox", + "An unrecoverable error happened.\nPlease close and re-open the app.") + except: + pass + TERMINATE=True + if not CLOSING: + renpy.quit(relaunch=True) return diff --git a/game/05_init.rpy b/game/05_init.rpy index f55a058..c82f27b 100644 --- a/game/05_init.rpy +++ b/game/05_init.rpy @@ -16,7 +16,7 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ######################################################################################## -# Definitions - Prestart +# Definitions - Prestart and post init sequences image TMW2 = "gfx/logo.png" label prestart: @@ -49,3 +49,15 @@ No warranties.{/b}{fast}" """ return +init 2 python: + # Overlay for TERM signals + def TermWatcher(): + global TERMINATE, CLOSING + if TERMINATE and not CLOSING: + stdout("TERM: TERMINATE RECEIVED") + TERMINATE=False + renpy.quit(relaunch=True) + return + + config.overlay_functions.append(TermWatcher) + diff --git a/game/script.rpy b/game/script.rpy index 4b4172b..ddfcfba 100644 --- a/game/script.rpy +++ b/game/script.rpy @@ -206,6 +206,7 @@ label prologue: label quit: $ stdout("Received quit signal!") + $ CLOSING = True python: # If needed, logout try: |