示例#1
0
文件: main.py 项目: mezod/kfchess
def reset(data):
    data = json.loads(data)
    game_id = data['gameId']
    player_key = data['playerKey']
    print 'reset', data

    if game_id not in game_states:
        return

    game_state = game_states[game_id]
    auth_player = get_auth_player(game_state, player_key)

    # only authenticated players can reset game
    if auth_player is not None:
        old_game = game_state.game
        game = Game(old_game.speed, old_game.players)
        for player in game_state.bots:
            game.mark_ready(player)
        game_state.game = game

        emit('resetack', {
            'game': game.to_json_obj(),
        },
             room=game_id,
             json=True)
示例#2
0
def reset(data):
    data = json.loads(data)
    game_id = data['gameId']
    player_key = data['playerKey']
    print 'reset', data

    if game_id not in game_states:
        emit('notfound')
        return

    game_state = game_states[game_id]
    auth_player = get_auth_player(game_state, player_key)

    # can't reset an in-progress multiplayer game
    if game_state.level is None and not game_state.game.finished:
        return

    # only authenticated players can reset game
    if auth_player is not None:
        db_service.remove_active_game(context.SERVER, game_id)

        board = None
        if game_state.level is not None:
            campaign_level = campaign.get_level(game_state.level)
            board = Board.from_str(campaign_level.board)

        old_game = game_state.game
        game = Game(old_game.speed,
                    old_game.players,
                    num_players=old_game.num_players,
                    board=board,
                    is_campaign=old_game.is_campaign,
                    debug=old_game.debug)
        for player in game_state.bots:
            game.mark_ready(player)
        game_state.game = game

        emit('resetack', {
            'game': game.to_json_obj(),
        },
             room=game_id,
             json=True)