Exemplo n.º 1
0
 def send(self, message, player):
     try:
         self._player_list[player].conn.sendall(message)
         ack = OnlineMessage()
         ack.decode(self.get(player))
         if ack.get_header() != 'ACK':
             raise ValueError
     except ConnectionResetError:
         print("Connection terminated")
         for player in self._player_list.keys():
             self.close_connection(player)
         exit()
     except ConnectionAbortedError:
         print("Connection terminated")
         for player in self._player_list.keys():
             self.close_connection(player)
         exit()
Exemplo n.º 2
0
    def ask_game(self):
        players = self.get_player_list()

        message = OnlineMessage()
        type_game = None
        while type_game not in self.GAME_LIST:
            message = OnlineMessage(self.MESSAGES_TO_USER['AskGame'])
            self.send(message.encode(), players[0])
            message.decode(self.get(players[0]))
            type_game = message.get_header()

            if type_game not in self.GAME_LIST:
                message.set_header(self.MESSAGES_TO_USER['WrongGame'])
                self.send(message.encode(), players[0])

        message.set_header(self.MESSAGES_TO_USER['CorrectGame'])
        message.set_body(type_game)
        self.send(message.encode(), players[0])

        self._server_FSM.handle_event(self.GAME_LIST[type_game])