From 51c27afcd2244ca681d9620e35241d0d4dfc4f5e Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Thu, 7 Jul 2011 21:31:07 -0400 Subject: [PATCH] Fixed more crashes related to early, nonzero maxclients (bug 5008, r=dvander). --- core/PlayerManager.cpp | 18 ++++++++++++------ core/PlayerManager.h | 2 +- public/IPlayerHelpers.h | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 8c114c5b..79cd0474 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -274,7 +274,7 @@ void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int cl SM_ExecuteAllConfigs(); } -bool PlayerManager::IsServerActivated() +bool PlayerManager::IsServerActivated() const { return m_FirstPass; } @@ -856,7 +856,7 @@ int PlayerManager::GetMaxClients() CPlayer *PlayerManager::GetPlayerByIndex(int client) const { - if (client > gpGlobals->maxClients || client < 1) + if (!IsServerActivated() || client > gpGlobals->maxClients || client < 1) { return NULL; } @@ -937,6 +937,12 @@ IGamePlayer *PlayerManager::GetGamePlayer(int client) void PlayerManager::ClearAdminId(AdminId id) { + // Players may not be inited if server hasn't yet been activated + if (!IsServerActivated()) + { + return; + } + int maxClients = gpGlobals->maxClients; for (int i=1; i<=maxClients; i++) { @@ -949,8 +955,8 @@ void PlayerManager::ClearAdminId(AdminId id) void PlayerManager::ClearAllAdmins() { - // Players may not be inited if server hadn't been activated - if (!m_Players) + // Players may not be inited if server hasn't yet been activated + if (!IsServerActivated()) { return; } @@ -969,8 +975,8 @@ const char *PlayerManager::GetPassInfoVar() void PlayerManager::RecheckAnyAdmins() { - // Players may not be inited if server hadn't been activated - if (!m_Players) + // Players may not be inited if server hasn't yet been activated + if (!IsServerActivated()) { return; } diff --git a/core/PlayerManager.h b/core/PlayerManager.h index 7c88e1a2..1bc6a22d 100644 --- a/core/PlayerManager.h +++ b/core/PlayerManager.h @@ -161,7 +161,7 @@ public: //IPlayerManager int GetMaxClients(); int GetNumPlayers(); int GetClientOfUserId(int userid); - bool IsServerActivated(); + bool IsServerActivated() const; int FilterCommandTarget(IGamePlayer *pAdmin, IGamePlayer *pTarget, int flags); int InternalFilterCommandTarget(CPlayer *pAdmin, CPlayer *pTarget, int flags); void RegisterCommandTargetProcessor(ICommandTargetProcessor *pHandler); diff --git a/public/IPlayerHelpers.h b/public/IPlayerHelpers.h index 54855899..bb7a1c9c 100644 --- a/public/IPlayerHelpers.h +++ b/public/IPlayerHelpers.h @@ -41,7 +41,7 @@ #include #define SMINTERFACE_PLAYERMANAGER_NAME "IPlayerManager" -#define SMINTERFACE_PLAYERMANAGER_VERSION 14 +#define SMINTERFACE_PLAYERMANAGER_VERSION 15 struct edict_t; class IPlayerInfo; @@ -489,7 +489,7 @@ namespace SourceMod * @return True if ServerActivate() has been called * at least once, false otherwise. */ - virtual bool IsServerActivated() =0; + virtual bool IsServerActivated() const =0; /** * @brief Gets SourceMod's reply source.