def _handle_player(player):
    stats = PlayerStats.query.filter_by(
        player=player, server_id=app.config.get('MAIN_SERVER_ID')
    ).first()

    if stats and stats.last_seen > datetime.utcnow() - timedelta(days=1):
        # ignore players that have joined since the job started
        return False

    try:
        actual_username = minecraft_uuid.lookup_latest_username_by_uuid(player.uuid)
    except requests.RequestException as e:
        rollbar.report_message('Exception looking up uuid, skipping group', level='warning', extra_data={
            'exception': unicode(e)
        })
        return False

    if not actual_username:
        rollbar.report_message('Error getting actual username, skipping', level='warning', extra_data={
            'uuid': player.uuid
        })
        return False

    if actual_username != player.username:
        h.avoid_duplicate_username(actual_username, player.uuid)

        player.set_username(actual_username)
        player.save(commit=True)

        return True

    return False
def _handle_player(player):
    stats = PlayerStats.query.filter_by(
        player=player, server_id=app.config.get('MAIN_SERVER_ID')
    ).first()

    if stats and stats.last_seen > datetime.utcnow() - timedelta(days=1):
        # ignore players that have joined since the job started
        return False

    try:
        actual_username = minecraft_uuid.lookup_latest_username_by_uuid(player.uuid)
    except requests.RequestException as e:
        rollbar.report_message('Exception looking up uuid, skipping group', level='warning', extra_data={
            'exception': unicode(e)
        })
        return False

    if not actual_username:
        rollbar.report_message('Error getting actual username, skipping', level='warning', extra_data={
            'uuid': player.uuid
        })
        return False

    if actual_username != player.username:
        h.avoid_duplicate_username(actual_username)

        player.set_username(actual_username)
        player.save(commit=True)

        return True

    return False
Esempio n. 3
0
def avoid_duplicate_username(username, allow_flush=True):
    """catch case if player on the server has renamed to an existing username in the db,
    look up existing player's current username since it must be different now
    """
    from standardweb.models import Player
    existing_username_player = Player.query.filter_by(username=username).first()
    if existing_username_player:
        new_username = minecraft_uuid.lookup_latest_username_by_uuid(existing_username_player.uuid)
        existing_username_player.set_username(new_username)
        existing_username_player.save(commit=False)

        if allow_flush:
            db.session.flush()
def avoid_duplicate_username(username, allow_flush=True):
    """catch case if player on the server has renamed to an existing username in the db,
    look up existing player's current username since it must be different now
    """
    from standardweb.models import Player
    existing_username_player = Player.query.filter_by(username=username).first()
    if existing_username_player:
        new_username = minecraft_uuid.lookup_latest_username_by_uuid(existing_username_player.uuid)
        existing_username_player.set_username(new_username)
        existing_username_player.save(commit=False)

        if allow_flush:
            db.session.flush()