From 91d7789ee91c00f9fd421ae2f5e7bd480124cd18 Mon Sep 17 00:00:00 2001 From: topoftheyear Date: Sun, 8 Dec 2019 16:09:05 -0600 Subject: [PATCH] Adds broken client checking. --- game/engine.py | 29 +++++++++++++++++++++-------- game/visualizer/game_log_parser.py | 2 +- scrimmage/utilities.py | 4 +--- wrapper/version.py | 2 +- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/game/engine.py b/game/engine.py index 39b112b..4460073 100644 --- a/game/engine.py +++ b/game/engine.py @@ -71,6 +71,9 @@ def boot(): # Skips folders continue + player = Player() + clients.append(player) + try: # Apply import restrictions __original_importer = __builtins__['__import__'] @@ -80,15 +83,25 @@ def boot(): print("Client attempted invalid imports.") print(e) continue + except Exception: + message = f'Client {filename} is having problems.' + player.functional = False + print(message) + shutdown(message, source='Client_error') finally: # Restore original importer for server use __builtins__['__import__'] = __original_importer - obj = im.Client() - player = Player( - code=obj - ) - clients.append(player) + obj = None + try: + obj = im.Client() + except Exception: + message = f'Client {filename} is not functional.' + player.functional = False + print(message) + shutdown(message, source='Client_error') + + player.code = obj debug(f'Clients found: {len(clients)}') # Verify correct number of clients @@ -208,7 +221,7 @@ def post_tick(turn): # Game is over. Create the results file and end the game. -def shutdown(reason=""): +def shutdown(reason="", source='Engine_error'): global clients global current_world global master_controller @@ -222,14 +235,14 @@ def shutdown(reason=""): results_information = master_controller.return_final_results(clients, current_world, turn_number) if reason: - results_information['Engine_error'] = reason + results_information[source] = reason # Write results file write(results_information, RESULTS_FILE) # Exit game if reason: - print("\nGame has ended due to engine error. See results.json.") + print(f"\nGame has ended due to {source}. See results.json.") os._exit(1) else: print("\nGame has successfully ended.") diff --git a/game/visualizer/game_log_parser.py b/game/visualizer/game_log_parser.py index 328c665..d731b30 100644 --- a/game/visualizer/game_log_parser.py +++ b/game/visualizer/game_log_parser.py @@ -21,7 +21,7 @@ def __init__(self, log_dir): # Load all turns into memory def load_turns(self): - files = os.listdir(self.log_dir) + files = sorted(os.listdir(self.log_dir)) for file in files: # skip "other" log files diff --git a/scrimmage/utilities.py b/scrimmage/utilities.py index 74720cd..56a607b 100644 --- a/scrimmage/utilities.py +++ b/scrimmage/utilities.py @@ -1,7 +1,5 @@ -#IP = '134.129.91.220' -#IP = '134.129.91.208' -IP = '127.0.0.1' +IP = '134.129.91.208' PORT = 5007 BUFFER_SIZE = 4096 diff --git a/wrapper/version.py b/wrapper/version.py index 23ec22e..94116bf 100644 --- a/wrapper/version.py +++ b/wrapper/version.py @@ -1 +1 @@ -v = '0.1.0' +v = '0.1.2'