Esempio n. 1
0
def ban_if_blacklisted(rcon: RecordedRcon, 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:
            try:
                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,
                                  by=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")
            except:
                send_to_discord_audit(
                    "Failed to apply ban on blacklisted players, please check the logs and report the error",
                    "ERROR")
Esempio n. 2
0
def ban_if_has_vac_bans(rcon: RecordedRcon, 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, by="VAC BOT")

            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")
Esempio n. 3
0
    def unwatch(self):
        with enter_session() as sess:
            player = get_player(sess, self.steam_id_64)
            if not player:
                raise CommandFailedError(
                    "Can't remove player to wathlist, player not found")
            if player.watchlist:
                player.watchlist.is_watched = False

        return True
Esempio n. 4
0
def _record_stats(map_info):
    stats = TimeWindowStats()

    start = datetime.datetime.utcfromtimestamp(map_info.get('start'))
    end = datetime.datetime.utcfromtimestamp(map_info.get('end'))

    if not start or not end:
        logger.error("Can't record stats, no time info for %s", map_info)
        return

    with enter_session() as sess:
        map = get_or_create_map(sess=sess,
                                start=start,
                                end=end,
                                server_number=os.getenv("SERVER_NUMBER"),
                                map_name=map_info["name"])
        player_stats = stats.get_players_stats_at_time(from_=start, until=end)
        for player, stats in player_stats.items():
            if steam_id_64 := stats.get("steam_id_64"):
                player_record = get_player(sess, steam_id_64=steam_id_64)
                if not player_record:
                    logger.error("Can't find DB record for %s", steam_id_64)
                    continue

                player_stats = dict(
                    playersteamid_id=player_record.id,
                    map_id=map.id,
                    name=stats.get("player"),
                    kills=stats.get("kills"),
                    kills_streak=stats.get("kills_streak"),
                    deaths=stats.get("deaths"),
                    deaths_without_kill_streak=stats.get(
                        "deaths_without_kill_streak"),
                    teamkills=stats.get("teamkills"),
                    teamkills_streak=stats.get("teamkills_streak"),
                    deaths_by_tk=stats.get("deaths_by_tk"),
                    deaths_by_tk_streak=stats.get("deaths_by_tk_streak"),
                    nb_vote_started=stats.get("nb_vote_started"),
                    nb_voted_yes=stats.get("nb_voted_yes"),
                    nb_voted_no=stats.get("nb_voted_no"),
                    time_seconds=stats.get("time_seconds"),
                    kills_per_minute=stats.get("kills_per_minute"),
                    deaths_per_minute=stats.get("deaths_per_minute"),
                    kill_death_ratio=stats.get("kill_death_ratio"),
                    longest_life_secs=stats.get("longest_life_secs"),
                    shortest_life_secs=stats.get("shortest_life_secs"),
                    weapons=stats.get("weapons"),
                    most_killed=stats.get("most_killed"),
                    death_by=stats.get("death_by"))
                logger.debug(f"Saving stats %s", player_stats)
                player_stat_record = PlayerStats(**player_stats)
                sess.add(player_stat_record)
            else:
                logger.error("Stat object does not contain a steam id: %s",
                             stats)
Esempio n. 5
0
 def get_watch(self):
     with enter_session() as sess:
         player = get_player(sess, self.steam_id_64)
         if not player:
             return None
         return player.to_dict()