From 8fc689c89a4f306a60fdfed49b90ea3eb6fe3431 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Mon, 11 May 2015 19:31:22 -0400 Subject: [PATCH] Populate MaxClients before OnPluginStart is called. --- core/PlayerManager.cpp | 32 +++++++++++++++++--------------- core/PlayerManager.h | 2 ++ core/sourcemod.cpp | 2 ++ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 84d31e8e..2e8f7cc0 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -138,6 +138,8 @@ PlayerManager::PlayerManager() m_UserIdLookUp = new int[USHRT_MAX+1]; memset(m_UserIdLookUp, 0, sizeof(int) * (USHRT_MAX+1)); + + InitializePlayers(); } PlayerManager::~PlayerManager() @@ -148,6 +150,20 @@ PlayerManager::~PlayerManager() delete [] m_UserIdLookUp; } +void PlayerManager::InitializePlayers() +{ + /* Initialize all players */ + + m_PlayerCount = 0; + m_Players = new CPlayer[SM_MAXPLAYERS + 1]; + m_AuthQueue = new unsigned int[SM_MAXPLAYERS + 1]; + m_FirstPass = true; + + memset(m_AuthQueue, 0, sizeof(unsigned int) * (SM_MAXPLAYERS + 1)); + + g_NumPlayersToAuth = &m_AuthQueue[0]; +} + void PlayerManager::OnSourceModAllInitialized() { SH_ADD_HOOK(IServerGameClients, ClientConnect, serverClients, SH_MEMBER(this, &PlayerManager::OnClientConnect), false); @@ -285,9 +301,6 @@ void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int cl static ConVar *replay_enable = icvar->FindVar("replay_enable"); #endif - // clientMax will not necessarily be correct here (such as on late SourceTV enable) - m_maxClients = gpGlobals->maxClients; - ICommandLine *commandLine = g_HL2.GetValveCommandLine(); m_bIsSourceTVActive = (tv_enable && tv_enable->GetBool() && (!commandLine || commandLine->FindParm("-nohltv") == 0)); m_bIsReplayActive = false; @@ -298,20 +311,9 @@ void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int cl if (!m_FirstPass) { - /* Initialize all players */ - - m_PlayerCount = 0; - m_Players = new CPlayer[SM_MAXPLAYERS + 1]; - m_AuthQueue = new unsigned int[SM_MAXPLAYERS + 1]; - m_FirstPass = true; - - memset(m_AuthQueue, 0, sizeof(unsigned int) * (SM_MAXPLAYERS + 1)); - - g_NumPlayersToAuth = &m_AuthQueue[0]; + InitializePlayers(); } - scripts->SyncMaxClients(m_maxClients); - g_OnMapStarted = true; #if SOURCE_ENGINE == SE_DOTA diff --git a/core/PlayerManager.h b/core/PlayerManager.h index 3f78c9f8..e1fd9efb 100644 --- a/core/PlayerManager.h +++ b/core/PlayerManager.h @@ -233,6 +233,8 @@ private: void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax); #endif void InvalidatePlayer(CPlayer *pPlayer); +private: + void InitializePlayers(); private: List m_hooks; IForward *m_clconnect; diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index 3ed990aa..095e04ef 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -320,6 +320,8 @@ void SourceModBase::StartSourceMod(bool late) static bool g_LevelEndBarrier = false; bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background) { + g_Players.MaxPlayersChanged(); + /* If we're not loaded... */ if (!g_Loaded) {