Skip to content

Commit

Permalink
Adds broken client checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
topoftheyear committed Dec 8, 2019
1 parent 13f3f97 commit 91d7789
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
29 changes: 21 additions & 8 deletions game/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def boot():
# Skips folders
continue

player = Player()
clients.append(player)

try:
# Apply import restrictions
__original_importer = __builtins__['__import__']
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.")
Expand Down
2 changes: 1 addition & 1 deletion game/visualizer/game_log_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions scrimmage/utilities.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion wrapper/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v = '0.1.0'
v = '0.1.2'

0 comments on commit 91d7789

Please sign in to comment.