def player_move(self, room_name, message):
        log.debug("%s plays move", self.name)

        #parse message (wait, pick, play)
        #format
        """
            "type": "play",
            "card": { rank: 4, suit: 4 }
        """

        room = self.active_room
        
        move_type = convert_move_type(message["type"])
        move = None
        if move_type == MoveType.play:
            card = message["card"]
            move = GameMove(MoveType.play,
                    convert_card(card["rank"], card["suit"]))
            if "suit" in message:
                move.suit = convert_suit(message["suit"])
        else:
            move = GameMove(move_type)
        
        game = room.active_game

        play_response = game.play(self.name, move)

        self.send_event("game:player:response", 
                convert_play_response(play_response))

        if play_response.success:
            for participant in room.active_players.values():
                socket = participant.socket
                if socket == None:
                    continue
                hand = game.player_hand(socket.name)
                socket.send_event("game:state:update", 
                    convert_state_start(game.state, game.players, 
                        game.player_hands,
                        game.current_player, 
                        game.played_cards.top_card, hand))

            for participant in room.participants:
                if participant.name not in room.active_players:
                    participant.send_event("game:state:watch", 
                        convert_state_watch(game.state, game.players, game.player_hands,
                            game.current_player, game.played_cards.top_card))

        if game.state == GameState.FINISHED:
            room.active_game = None
            room.active_players = None
            for participant in room.players.values():
                participant.ready = False
    def player_ready(self, room_name, message):
        log.debug("%s ready to start game", self.name)

        room = self.active_room
        
        player = room.players[self.name]
        player.ready = True

        self.broadcast_event(room.participants, "game:player:ready", self.name)

        all_ready = all([s.ready  
                            for s in room.players.values()])

        player_count = len(room.players)
        enough_players = player_count > 1 and player_count < 5
        if not all_ready or not enough_players:
            return

        room.active_players = room.players.copy()
        #start the game
        #send the game initial state to all players
        players = [s.player for s in room.players.values()]

        game = create_game(players)

        for participant in room.active_players.values():
            socket = participant.socket
            if socket == None:
                #player is currently disconnected, just ignore him he will
                #pick up state on reconnection
                continue
            hand = game.player_hand(socket.name)
            socket.send_event("game:state:start", 
                convert_state_start(game.state, game.players, game.player_hands,
                game.current_player, game.played_cards.top_card, hand))

        for participant in room.participants:
            if participant.name not in room.active_players:
                participant.send_event("game:state:watch", 
                    convert_state_watch(game.state, game.players, game.player_hands,
                        game.current_player, game.played_cards.top_card))


        room.active_game = game

        for participant in room.active_players.values():
            participant.ready = False
    def login(self, room_name, name):
        log.debug("user '%s' logged in to room '%s'", name, room_name)

        room = self.active_room

        self.name = name 

        if name in room.players:
            room.players[name].socket = self
            self.broadcast_event(room.participants, "players:reconnected", self.name)

            game = room.active_game
            if game:
                hand = game.player_hand(name)
                self.send_event("game:state:start", 
                    convert_state_start(game.state, game.players, game.player_hands,
                    game.current_player, game.played_cards.top_card, hand))
        else:
            player = Player(name)
            room_player = RoomPlayer(name, self, player)
            room.players[name] = room_player
            self.broadcast_event(self.active_room.participants, "players:added", name)