This contains the logic that needs to be cleaned up at the end of a game If there is something that needs to be cleaned up add it in the try catch loop surrounding the catch loop surrounding the call of the function
(game, dockers, args, sock_file, scrimmage=False)
| 67 | |
| 68 | |
| 69 | def run_game(game, dockers, args, sock_file, scrimmage=False): |
| 70 | ''' |
| 71 | This contains the logic that needs to be cleaned up at the end of a game |
| 72 | If there is something that needs to be cleaned up add it in the try catch |
| 73 | loop surrounding the catch loop surrounding the call of the function |
| 74 | ''' |
| 75 | |
| 76 | # Start the unix stream server |
| 77 | main_server = server.start_server(sock_file, game, dockers) |
| 78 | |
| 79 | viewer_server = server.start_viewer_server(PORT, game) |
| 80 | |
| 81 | try: |
| 82 | # Start the docker instances |
| 83 | for player_key in dockers: |
| 84 | docker_inst = dockers[player_key] |
| 85 | docker_inst.start() |
| 86 | for player_ in game.players: |
| 87 | if player_['id'] == player_key: |
| 88 | player = player_['player'] |
| 89 | break |
| 90 | if player.planet == bc.Planet.Earth: |
| 91 | planet = 'earth' |
| 92 | else: |
| 93 | planet = 'mars' |
| 94 | if player.team == bc.Team.Blue: |
| 95 | team = 'blue' |
| 96 | else: |
| 97 | team = 'red' |
| 98 | |
| 99 | name = '[{}:{}]'.format(planet, team) |
| 100 | # 10 MB of logs in scrimmage, unlimited logging otherwise |
| 101 | logger = Logger(name, print=not args['terminal_viewer'], limit=10**7 if scrimmage else 2**63) |
| 102 | docker_inst.stream_logs(line_action=logger) |
| 103 | player_['logger'] = logger |
| 104 | |
| 105 | # Wait until all the code is done then clean up |
| 106 | while not game.game_over: |
| 107 | time.sleep(0.1) |
| 108 | |
| 109 | finally: |
| 110 | main_server.shutdown() |
| 111 | try: |
| 112 | main_server.server_close() |
| 113 | except e: |
| 114 | print(e) |
| 115 | |
| 116 | if viewer_server is not None: |
| 117 | viewer_server.shutdown() |
| 118 | |
| 119 | match_file = {} |
| 120 | match_file['message'] = game.viewer_messages |
| 121 | if not game.disconnected: |
| 122 | if bc.Team.Red == game.manager.winning_team(): |
| 123 | winner = 'player1' |
| 124 | else: |
| 125 | winner = 'player2' |
| 126 | else: |
nothing calls this directly
no test coverage detected