From ff0b29482e6dee008a10c5cfdeb7229491619d70 Mon Sep 17 00:00:00 2001 From: oloturia <5429234+oloturia@users.noreply.github.com> Date: Wed, 3 Nov 2021 13:06:48 +0100 Subject: [PATCH] fixed a bug that happens if the game crashes --- damastodon.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/damastodon.py b/damastodon.py index 981ca2f..ea96be6 100755 --- a/damastodon.py +++ b/damastodon.py @@ -73,6 +73,7 @@ def check_message(notification): start = pickle.load(f) except FileNotFoundError: mastodon.status_post("Hello @"+account+" \n unfortunately, your savegame is corrupted or missing",visibility="direct") #The file has moved or corrupted + print(account+" file not found") return if start != "WAIT": mastodon.status_post("Hello @"+account+" \n your request is not valid",visibility="direct") #The user that challenged us is playing a game with someone else @@ -101,7 +102,12 @@ def check_message(notification): return else: #We are in a game, so movements are parsed and lobby commands are disabled with open(save_position+account,"rb") as f: - start = pickle.load(f) + try: + start = pickle.load(f) + except EOFError: # Something went very wrong, file is corrupt? + mastodon.status_post("Hello @"+account+" \n unfortunately, your savegame is corrupted or missing",visibility="direct") #The file has moved or corrupted + print(account+" file corrupted") + return if start: #The game is started, load other parameters black = pickle.load(f) white = pickle.load(f) @@ -155,7 +161,7 @@ def check_message(notification): if __name__ == "__main__": if api_url[:4] != "http": - print("Invalid address.") + print("Invalid address") quit() mastodon = login.login(api_url) while True: