Skip to content

Commit

Permalink
Bugfix: include is_vip and profile in get_detailed_player_info (#715)
Browse files Browse the repository at this point in the history
`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`.
  • Loading branch information
LordofAgents authored Oct 16, 2024
1 parent 80ff605 commit 3eed52f
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions rcon/rcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"), {}
Expand Down Expand Up @@ -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]:
Expand Down

0 comments on commit 3eed52f

Please sign in to comment.