From 3eed52f97b3e885b4400d284004932c9bec0fb78 Mon Sep 17 00:00:00 2001 From: LordofAgents <52619285+LordofAgents@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:48:09 +0200 Subject: [PATCH] Bugfix: include is_vip and profile in get_detailed_player_info (#715) `get_detailed_player_info` did not override the default `false` for `is_vip` and `null` for `profile` with the correct values. This PR fixes that and removes the workaround in `get_team_view` to not fetch the profiles twice. This also fixes the wrong value `is_vip` in `get_detailed_players`. --- rcon/rcon.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/rcon/rcon.py b/rcon/rcon.py index e3b939c28..9bfdad38f 100644 --- a/rcon/rcon.py +++ b/rcon/rcon.py @@ -16,7 +16,7 @@ from rcon.commands import SUCCESS, CommandFailedError, ServerCtl, VipId from rcon.maps import UNKNOWN_MAP_NAME, Layer, is_server_loading_map, parse_layer from rcon.models import PlayerID, PlayerVIP, enter_session -from rcon.player_history import get_profiles, safe_save_player_action, save_player +from rcon.player_history import get_profiles, safe_save_player_action, save_player, get_player_profile from rcon.settings import SERVER_INFO from rcon.types import ( AdminType, @@ -254,24 +254,8 @@ def get_team_view(self): players_by_id = detailed_players["players"] fail_count = detailed_players["fail_count"] - logger.debug("Getting DB profiles") - steam_profiles = { - profile[PLAYER_ID]: profile - for profile in get_profiles(list(players_by_id.keys())) - } - - logger.debug("Getting VIP list") - try: - vips = set(v[PLAYER_ID] for v in super().get_vip_ids()) - except Exception: - logger.exception("Failed to get VIPs") - vips = set() - for player in players_by_id.values(): player_id = player[PLAYER_ID] - profile = steam_profiles.get(player.get(PLAYER_ID), {}) or {} - player["profile"] = profile - player["is_vip"] = player_id in vips teams.setdefault(player.get("team"), {}).setdefault( player.get("unit_name"), {} @@ -467,8 +451,15 @@ def get_detailed_player_info(self, player_name: str) -> GetDetailedPlayer: Level: 34 """ + # Add VIP Status + player_data = parse_raw_player_info(raw, player_name) + vip_player_ids = set(v[PLAYER_ID] for v in super().get_vip_ids()) + player_data["is_vip"] = player_data["player_id"] in vip_player_ids - return parse_raw_player_info(raw, player_name) + # Add Profile + profile = get_player_profile(player_data["player_id"], 1) + player_data["profile"] = profile + return player_data @ttl_cache(ttl=60 * 10) def get_admin_ids(self) -> list[AdminType]: