diff --git a/src/game/client/hud/death_notice_panel.cpp b/src/game/client/hud/death_notice_panel.cpp index 49e90d2..ea521a3 100644 --- a/src/game/client/hud/death_notice_panel.cpp +++ b/src/game/client/hud/death_notice_panel.cpp @@ -83,8 +83,8 @@ void CHudDeathNoticePanel::Think() void CHudDeathNoticePanel::AddItem(int killerId, int victimId, const char *killedwith) { Entry e; - CPlayerInfo *killer = (killerId >= 1 && killerId <= MAX_PLAYERS) ? GetPlayerInfo(killerId) : nullptr; - CPlayerInfo *victim = (victimId >= 1 && victimId <= MAX_PLAYERS) ? GetPlayerInfo(victimId) : nullptr; + CPlayerInfo *killer = GetPlayerInfoSafe(killerId); + CPlayerInfo *victim = GetPlayerInfoSafe(victimId); int thisPlayerId = GetThisPlayerInfo()->GetIndex(); // Check for suicide diff --git a/src/game/client/player_info.cpp b/src/game/client/player_info.cpp index ab524c4..df2a978 100644 --- a/src/game/client/player_info.cpp +++ b/src/game/client/player_info.cpp @@ -200,6 +200,18 @@ CPlayerInfo *GetThisPlayerInfo() return s_ThisPlayerInfo; } +CPlayerInfo *GetPlayerInfoSafe(int idx) +{ + if (!(idx >= 1 && idx <= MAX_PLAYERS)) + return nullptr; + + CPlayerInfo *pInfo = GetPlayerInfo(idx); + if (!pInfo->IsConnected()) + return nullptr; + + return pInfo; +} + int CPlayerInfo::GetIndex() { return m_iIndex; diff --git a/src/game/client/player_info.h b/src/game/client/player_info.h index 9a81c1f..173a30b 100644 --- a/src/game/client/player_info.h +++ b/src/game/client/player_info.h @@ -35,6 +35,12 @@ class CPlayerInfo; CPlayerInfo *GetPlayerInfo(int idx); CPlayerInfo *GetThisPlayerInfo(); +//! Gets the player info for player index. Checks that the index +//! is valid and the player is connected. +//! @param idx Player index in the range [1; MAX_PLAYERS]. +//! @returns Player info or nullptr. +CPlayerInfo *GetPlayerInfoSafe(int idx); + class CPlayerInfo { public: