def network_process(self): Debug.game_manager(f'Game {self.id}: ready to listen game') while True: try: request = self.network.receive() Debug.game_manager(f'Game {self.id}: message {request}') if request['type'] == 'add player' and not self.game_started: Debug.game_manager(f'Game {self.id}: add player') if self.add_real_player(request['name']): self.network.send({'type': 'start game'}) Thread(target=lambda: self.wait_for_end(), name=f'Game {self.id}: wait for end').start() Thread( target=lambda: self.send_players_left(), name=f'Game {self.id}: send players left').start() else: self.network.send({ 'type': 'update players', 'left': self.players_count }) elif request[ 'type'] == 'delete player' and not self.game_started: Debug.game_manager(f'Game {self.id}: delete player') self.delete_player(request['name']) elif request['type'] == 'break': Debug.game_manager(f'Game {self.id}: break game') self.break_game() if self.thread: self.thread.join() self.network.send({'type': 'broken'}) except ValueError: continue except IndexError: continue
def delete_game(self, request: dict): if request['id'] in self.tournaments: del self.tournaments[request['id']] Debug.game_manager('Game manager: successful delete tournament') elif request['id'] in self.quick_games: del self.quick_games[request['id']] Debug.game_manager('Game manager: successful delete quick game') else: Debug.game_manager( f'Game manager: BAD ID FOR DELETING GAME: {request["id"]}')
def infinite(self): Debug.game_manager('Game manager: ready to listen') while True: try: request = self.network.receive() Debug.game_manager(f'Game manager: message {request}') if request['type'] == 'create tournament': Debug.game_manager('Game manager: create tournament') self.create_tournament(request) Debug.game_manager('Game manager: tournament created') elif request['type'] == 'create quick game': Debug.game_manager('Game manager: create quick game') self.create_quick_game(request) Debug.game_manager('Game manager: quick game created') elif request['type'] == 'delete game': Debug.game_manager('Game manager: delete game') self.delete_game(request) Debug.game_manager('Game manager: game deleted') except ValueError: continue except IndexError: continue