Esempio n. 1
0
def ban_if_blacklisted(rcon: Rcon, steam_id_64, name):
    with enter_session() as sess:
        player = get_player(sess, steam_id_64)

        if not player:
            logger.error("Can't check blacklist, player not found %s",
                         steam_id_64)
            return

        if player.blacklist and player.blacklist.is_blacklisted:
            logger.info("Player %s was banned due blacklist, reason: %s",
                        str(name), player.blacklist.reason)
            rcon.do_perma_ban(player=name,
                              reason=player.blacklist.reason,
                              admin_name=f"BLACKLIST: {player.blacklist.by}")
            safe_save_player_action(rcon=rcon,
                                    player_name=name,
                                    action_type="PERMABAN",
                                    reason=player.blacklist.reason,
                                    by=f"BLACKLIST: {player.blacklist.by}",
                                    steam_id_64=steam_id_64)
            try:
                send_to_discord_audit(
                    f"`BLACKLIST` -> {dict_to_discord(dict(player=name, reason=player.blacklist.reason))}",
                    "BLACKLIST")
            except:
                logger.error("Unable to send blacklist to audit log")
Esempio n. 2
0
def ban_if_has_vac_bans(rcon: Rcon, steam_id_64, name):
    try:
        max_days_since_ban = int(MAX_DAYS_SINCE_BAN)
        max_game_bans = float('inf') if int(
            MAX_GAME_BAN_THRESHOLD) <= 0 else int(MAX_GAME_BAN_THRESHOLD)
    except ValueError:  # No proper value is given
        logger.error(
            "Invalid value given for environment variable BAN_ON_VAC_HISTORY_DAYS or MAX_GAME_BAN_THRESHOLD"
        )
        return

    if max_days_since_ban <= 0:
        return  # Feature is disabled

    with enter_session() as sess:
        player = get_player(sess, steam_id_64)

        if not player:
            logger.error("Can't check VAC history, player not found %s",
                         steam_id_64)
            return

        bans = get_player_bans(steam_id_64)
        if not bans or not isinstance(bans, dict):
            logger.warning("Can't fetch Bans for player %s, received %s",
                           steam_id_64, bans)
            # Player couldn't be fetched properly (logged by get_player_bans)
            return

        if should_ban(bans, max_game_bans, max_days_since_ban):
            reason = AUTO_BAN_REASON.format(
                DAYS_SINCE_LAST_BAN=bans.get('DaysSinceLastBan'),
                MAX_DAYS_SINCE_BAN=str(max_days_since_ban))
            logger.info(
                "Player %s was banned due VAC history, last ban: %s days ago",
                str(player), bans.get('DaysSinceLastBan'))
            rcon.do_perma_ban(player=name, reason=reason, admin_name="A BOT")
            safe_save_player_action(rcon=rcon,
                                    player_name=name,
                                    action_type="PERMABAN",
                                    reason=reason,
                                    by='AUTOBAN',
                                    steam_id_64=player.steam_id_64)

            try:
                audit_params = dict(
                    player=name,
                    steam_id_64=player.steam_id_64,
                    reason=reason,
                    days_since_last_ban=bans.get('DaysSinceLastBan'),
                    vac_banned=bans.get('VACBanned'),
                    number_of_game_bans=bans.get('NumberOfGameBans'))
                send_to_discord_audit(
                    f"`VAC/GAME BAN` -> {dict_to_discord(audit_params)}",
                    "AUTOBAN")
            except:
                logger.exception("Unable to send vac ban to audit log")