def get_player(request): data = _get_data(request) res = {} try: if s := data.get("steam_id_64"): res = get_player_profile(s, nb_sessions=data.get("nb_sessions", 10)) else:
def auto_kick(_, log): try: config = get_config().get('NAME_KICKS') except KeyError: logger.error("Invalid configuration file, NAME_KICKS key is missing") return for r in config['regexps']: name = log["player"] info = recorded_rcon.get_player_info(name) try: profile = get_player_profile(info["steam_id_64"], 0) for f in config.get("whitelist_flags", []): if player_has_flag(profile, f): logger.debug( "Not checking nickname validity for whitelisted player %s (%s)", name, info["steam_id_64"]) return except: logger.exception("Unable to check player profile") if re.match(r, name): logger.info("%s matched player %s", r, name) recorded_rcon.do_kick(player=name, reason=config["reason"], by="NAME_KICK") try: send_to_discord_audit( f"`{name}` kicked from regexp `{r}`", by="NAME_KICK", webhookurl=config.get("discord_webhook_url")) except Exception: logger.error("Unable to send to audit_log") return
def get_player(request): data = _get_data(request) res = {} try: res = get_player_profile(data['steam_id_64'], nb_sessions=data.get('nb_sessions', 10)) failed = bool(res) except: logger.exception("Unable to get player %s", data) failed = True return JsonResponse({ "result": res, "command": "get_player_profile", "arguments": data, "failed": failed })
def auto_ban_if_tks_right_after_connection(rcon: RecordedRcon, log): config = get_config() config = config.get("BAN_TK_ON_CONNECT") if not config or not config.get("enabled"): return player_name = log["player"] player_steam_id = log["steam_id_64_1"] player_profile = None vips = {} try: player_profile = get_player_profile(player_steam_id, 0) except: logger.exception("Unable to get player profile") try: vips = set(v['steam_id_64'] for v in rcon.get_vip_ids()) except: logger.exception("Unable to get VIPS") last_logs = get_recent_logs(end=500, player_search=player_name, exact_player_match=True) logger.debug("Checking TK from %s", player_name) author = config.get("author_name", "Automation") reason = config.get("message", "No reasons provided") discord_msg = config.get("discord_webhook_message", "No message provided") webhook = config.get("discord_webhook_url") max_time_minute = config.get("max_time_after_connect_minutes", 5) excluded_weapons = [w.lower() for w in config.get("exclude_weapons", [])] ignore_after_kill = config.get("ignore_tk_after_n_kills", 1) ignore_after_death = config.get("ignore_tk_after_n_death", 1) whitelist_players = config.get("whitelist_players", {}) tk_tolerance_count = config.get("teamkill_tolerance_count", 1) if player_profile: if whitelist_players.get('is_vip') and player_steam_id in vips: logger.debug("Not checking player because he's VIP") return if whitelist_players.get('has_at_least_n_sessions') and player_profile[ 'sessions_count'] >= whitelist_players.get( 'has_at_least_n_sessions'): logger.debug("Not checking player because he has %s sessions", player_profile['sessions_count']) return flags = whitelist_players.get('has_flag', []) if not isinstance(flags, list): flags = [flags] for f in flags: if player_has_flag(player_profile, f): logger.debug("Not checking player because he has flag %s", f) return last_action_is_connect = False last_connect_time = None kill_counter = 0 death_counter = 0 tk_counter = 0 for log in reversed(last_logs["logs"]): logger.debug(log) if log["action"] == "CONNECTED": last_action_is_connect = log last_connect_time = log["timestamp_ms"] kill_counter = 0 death_counter = 0 continue if log["action"] == "TEAM KILL" and log[ 'player'] == player_name and last_action_is_connect: if excluded_weapons and log["weapon"].lower() in excluded_weapons: logger.debug( "Not counting TK as offense due to weapon exclusion") continue if log['timestamp_ms'] - last_connect_time > max_time_minute * 60 * 1000: logger.debug( "Not counting TK as offense due to elapsed time exclusion, last connection time %s, tk time %s", datetime.datetime.fromtimestamp(last_connect_time / 1000), datetime.datetime.fromtimestamp(log["timestamp_ms"])) continue logger.info("Banning player %s for TEAMKILL after connect %s", player_name, log) tk_counter += 1 if tk_counter > tk_tolerance_count: rcon.do_perma_ban( player=player_name, reason=reason, by=author, ) send_to_discord_audit(discord_msg.format(player=player_name), by=author, webhookurl=webhook) elif is_player_death(player_name, log): death_counter += 1 if death_counter >= ignore_after_death: last_action_is_connect = False elif is_player_kill(player_name, log): kill_counter += 1 if kill_counter >= ignore_after_kill: last_action_is_connect = False