Merge pull request #337 from alliedmodders/earlier-maxclients

Populate MaxClients before OnPluginStart is called.
This commit is contained in:
Nicholas Hastings 2015-05-20 06:48:08 -04:00
commit 9f8a40f482
4 changed files with 20 additions and 30 deletions

View File

@ -128,7 +128,7 @@ public:
PlayerManager::PlayerManager() PlayerManager::PlayerManager()
{ {
m_AuthQueue = NULL; m_AuthQueue = NULL;
m_FirstPass = false; m_bServerActivated = false;
m_maxClients = 0; m_maxClients = 0;
m_SourceTVUserId = -1; m_SourceTVUserId = -1;
@ -148,6 +148,19 @@ PlayerManager::~PlayerManager()
delete [] m_UserIdLookUp; delete [] m_UserIdLookUp;
} }
void PlayerManager::OnSourceModStartup(bool late)
{
/* Initialize all players */
m_PlayerCount = 0;
m_Players = new CPlayer[SM_MAXPLAYERS + 1];
m_AuthQueue = new unsigned int[SM_MAXPLAYERS + 1];
memset(m_AuthQueue, 0, sizeof(unsigned int) * (SM_MAXPLAYERS + 1));
g_NumPlayersToAuth = &m_AuthQueue[0];
}
void PlayerManager::OnSourceModAllInitialized() void PlayerManager::OnSourceModAllInitialized()
{ {
SH_ADD_HOOK(IServerGameClients, ClientConnect, serverClients, SH_MEMBER(this, &PlayerManager::OnClientConnect), false); SH_ADD_HOOK(IServerGameClients, ClientConnect, serverClients, SH_MEMBER(this, &PlayerManager::OnClientConnect), false);
@ -285,9 +298,6 @@ void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int cl
static ConVar *replay_enable = icvar->FindVar("replay_enable"); static ConVar *replay_enable = icvar->FindVar("replay_enable");
#endif #endif
// clientMax will not necessarily be correct here (such as on late SourceTV enable)
m_maxClients = gpGlobals->maxClients;
ICommandLine *commandLine = g_HL2.GetValveCommandLine(); ICommandLine *commandLine = g_HL2.GetValveCommandLine();
m_bIsSourceTVActive = (tv_enable && tv_enable->GetBool() && (!commandLine || commandLine->FindParm("-nohltv") == 0)); m_bIsSourceTVActive = (tv_enable && tv_enable->GetBool() && (!commandLine || commandLine->FindParm("-nohltv") == 0));
m_bIsReplayActive = false; m_bIsReplayActive = false;
@ -296,23 +306,8 @@ void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int cl
#endif #endif
m_PlayersSinceActive = 0; m_PlayersSinceActive = 0;
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];
}
scripts->SyncMaxClients(m_maxClients);
g_OnMapStarted = true; g_OnMapStarted = true;
m_bServerActivated = true;
#if SOURCE_ENGINE == SE_DOTA #if SOURCE_ENGINE == SE_DOTA
extsys->CallOnCoreMapStart(gpGlobals->pEdicts, gpGlobals->maxEntities, gpGlobals->maxClients); extsys->CallOnCoreMapStart(gpGlobals->pEdicts, gpGlobals->maxEntities, gpGlobals->maxClients);
@ -344,7 +339,7 @@ void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int cl
bool PlayerManager::IsServerActivated() bool PlayerManager::IsServerActivated()
{ {
return m_FirstPass; return m_bServerActivated;
} }
bool PlayerManager::CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id) bool PlayerManager::CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id)
@ -1826,11 +1821,6 @@ void PlayerManager::OnSourceModMaxPlayersChanged( int newvalue )
void PlayerManager::MaxPlayersChanged( int newvalue /*= -1*/ ) void PlayerManager::MaxPlayersChanged( int newvalue /*= -1*/ )
{ {
if (!m_FirstPass)
{
return;
}
if (newvalue == -1) if (newvalue == -1)
{ {
newvalue = gpGlobals->maxClients; newvalue = gpGlobals->maxClients;

View File

@ -154,6 +154,7 @@ public:
PlayerManager(); PlayerManager();
~PlayerManager(); ~PlayerManager();
public: //SMGlobalClass public: //SMGlobalClass
void OnSourceModStartup(bool late) override;
void OnSourceModAllInitialized(); void OnSourceModAllInitialized();
void OnSourceModShutdown(); void OnSourceModShutdown();
void OnSourceModLevelEnd(); void OnSourceModLevelEnd();
@ -250,7 +251,7 @@ private:
int m_maxClients; int m_maxClients;
int m_PlayerCount; int m_PlayerCount;
int m_PlayersSinceActive; int m_PlayersSinceActive;
bool m_FirstPass; bool m_bServerActivated;
unsigned int *m_AuthQueue; unsigned int *m_AuthQueue;
String m_PassInfoVar; String m_PassInfoVar;
bool m_QueryLang; bool m_QueryLang;

View File

@ -320,6 +320,8 @@ void SourceModBase::StartSourceMod(bool late)
static bool g_LevelEndBarrier = false; static bool g_LevelEndBarrier = false;
bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background) 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 we're not loaded... */
if (!g_Loaded) if (!g_Loaded)
{ {

View File

@ -67,9 +67,6 @@ enum AuthIdType
/** /**
* MAXPLAYERS is not the same as MaxClients. * MAXPLAYERS is not the same as MaxClients.
* MAXPLAYERS is a hardcoded value as an upper limit. MaxClients changes based on the server. * MAXPLAYERS is a hardcoded value as an upper limit. MaxClients changes based on the server.
*
* Both GetMaxClients() and MaxClients are only available once the map is loaded, and should
* not be used in OnPluginStart().
*/ */
#define MAXPLAYERS 65 /**< Maximum number of players SourceMod supports */ #define MAXPLAYERS 65 /**< Maximum number of players SourceMod supports */