Fix GetClientCount(false)
This commit is contained in:
		
							parent
							
								
									aa2a71fc67
								
							
						
					
					
						commit
						ec3351a320
					
				@ -213,6 +213,9 @@ void PlayerManager::OnSourceModAllInitialized()
 | 
			
		||||
		SH_ADD_HOOK(ConCommand, Dispatch, pCmd, SH_STATIC(CmdMaxplayersCallback), true);
 | 
			
		||||
		maxplayersCmd = pCmd;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	gameevents->AddListener(this, "player_connect", true);
 | 
			
		||||
	gameevents->AddListener(this, "player_disconnect", true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void PlayerManager::OnSourceModShutdown()
 | 
			
		||||
@ -261,6 +264,8 @@ void PlayerManager::OnSourceModShutdown()
 | 
			
		||||
	{
 | 
			
		||||
		SH_REMOVE_HOOK(ConCommand, Dispatch, maxplayersCmd, SH_STATIC(CmdMaxplayersCallback), true);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	gameevents->RemoveListener(this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ConfigResult PlayerManager::OnSourceModConfigChanged(const char *key, 
 | 
			
		||||
@ -1445,6 +1450,11 @@ int PlayerManager::GetNumPlayers()
 | 
			
		||||
	return m_PlayerCount;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int PlayerManager::GetNumClients()
 | 
			
		||||
{
 | 
			
		||||
	return m_ClientCount;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int PlayerManager::GetClientOfUserId(int userid)
 | 
			
		||||
{
 | 
			
		||||
	if (userid < 0 || userid > USHRT_MAX)
 | 
			
		||||
@ -2045,6 +2055,27 @@ bool PlayerManager::HandleConVarQuery(QueryCvarCookie_t cookie, int client, EQue
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/* IGameEventListener2::FireGameEvent */
 | 
			
		||||
void PlayerManager::FireGameEvent(IGameEvent *pEvent)
 | 
			
		||||
{
 | 
			
		||||
	const char *name = pEvent->GetName();
 | 
			
		||||
 | 
			
		||||
	if (strcmp(name, "player_connect") == 0)
 | 
			
		||||
	{
 | 
			
		||||
		const int client = pEvent->GetInt("index") + 1;
 | 
			
		||||
		const int userid = pEvent->GetInt("userid");
 | 
			
		||||
 | 
			
		||||
		m_ClientCount++;
 | 
			
		||||
	}
 | 
			
		||||
	else if (strcmp(name, "player_disconnect") == 0)
 | 
			
		||||
	{
 | 
			
		||||
		const int userid = pEvent->GetInt("userid");
 | 
			
		||||
		const int client = m_UserIdLookUp[userid];
 | 
			
		||||
 | 
			
		||||
		m_ClientCount--;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*******************
 | 
			
		||||
 *** PLAYER CODE ***
 | 
			
		||||
 | 
			
		||||
@ -159,7 +159,8 @@ private:
 | 
			
		||||
 | 
			
		||||
class PlayerManager : 
 | 
			
		||||
	public SMGlobalClass,
 | 
			
		||||
	public IPlayerManager
 | 
			
		||||
	public IPlayerManager,
 | 
			
		||||
	public IGameEventListener2
 | 
			
		||||
{
 | 
			
		||||
	friend class CPlayer;
 | 
			
		||||
public:
 | 
			
		||||
@ -203,6 +204,7 @@ public: //IPlayerManager
 | 
			
		||||
	IGamePlayer *GetGamePlayer(edict_t *pEdict);
 | 
			
		||||
	int GetMaxClients();
 | 
			
		||||
	int GetNumPlayers();
 | 
			
		||||
	int GetNumClients();
 | 
			
		||||
	int GetClientOfUserId(int userid);
 | 
			
		||||
	bool IsServerActivated();
 | 
			
		||||
	int FilterCommandTarget(IGamePlayer *pAdmin, IGamePlayer *pTarget, int flags);
 | 
			
		||||
@ -213,6 +215,11 @@ public: //IPlayerManager
 | 
			
		||||
	int GetClientFromSerial(unsigned int serial);
 | 
			
		||||
	void ClearAdminId(AdminId id);
 | 
			
		||||
	void RecheckAnyAdmins();
 | 
			
		||||
public: // IGameEventListener2
 | 
			
		||||
	void FireGameEvent(IGameEvent *pEvent);
 | 
			
		||||
#if SOURCE_ENGINE >= SE_ALIENSWARM
 | 
			
		||||
	virtual int	 GetEventDebugID( void ) { return 42; }
 | 
			
		||||
#endif
 | 
			
		||||
public:
 | 
			
		||||
	inline int MaxClients()
 | 
			
		||||
	{
 | 
			
		||||
@ -274,6 +281,7 @@ private:
 | 
			
		||||
	int m_SourceTVUserId;
 | 
			
		||||
	int m_ReplayUserId;
 | 
			
		||||
	bool m_bInCCKVHook;
 | 
			
		||||
	int m_ClientCount;
 | 
			
		||||
private:
 | 
			
		||||
	static const int NETMSG_TYPE_BITS = 5; // SVC_Print overhead for netmsg type
 | 
			
		||||
	static const int SVC_Print_BufferSize = 2048 - 1; // -1 for terminating \0
 | 
			
		||||
 | 
			
		||||
@ -270,18 +270,7 @@ static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params)
 | 
			
		||||
		return playerhelpers->GetNumPlayers();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	int maxplayers = playerhelpers->GetMaxClients();
 | 
			
		||||
	int count = 0;
 | 
			
		||||
	for (int i = 1; i <= maxplayers; ++i)
 | 
			
		||||
	{
 | 
			
		||||
		IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i);
 | 
			
		||||
		if ((pPlayer->IsConnected()) && !(pPlayer->IsInGame()))
 | 
			
		||||
		{
 | 
			
		||||
			count++;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return (playerhelpers->GetNumPlayers() + count);
 | 
			
		||||
	return playerhelpers->GetNumClients();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static cell_t sm_GetMaxClients(IPluginContext *pCtx, const cell_t *params)
 | 
			
		||||
 | 
			
		||||
@ -41,7 +41,7 @@
 | 
			
		||||
#include <IAdminSystem.h>
 | 
			
		||||
 | 
			
		||||
#define SMINTERFACE_PLAYERMANAGER_NAME		"IPlayerManager"
 | 
			
		||||
#define SMINTERFACE_PLAYERMANAGER_VERSION	21
 | 
			
		||||
#define SMINTERFACE_PLAYERMANAGER_VERSION	22
 | 
			
		||||
 | 
			
		||||
struct edict_t;
 | 
			
		||||
class IPlayerInfo;
 | 
			
		||||
@ -543,10 +543,17 @@ namespace SourceMod
 | 
			
		||||
		/**
 | 
			
		||||
		 * @brief Returns the number of players currently connected.
 | 
			
		||||
		 *
 | 
			
		||||
		 * @return				Current number of connected clients.
 | 
			
		||||
		 * @return				Current number of connected players.
 | 
			
		||||
		 */
 | 
			
		||||
		virtual int GetNumPlayers() =0;
 | 
			
		||||
 | 
			
		||||
		/**
 | 
			
		||||
		 * @brief Returns the number of clients currently connected.
 | 
			
		||||
		 *
 | 
			
		||||
		 * @return				Current number of connected clients.
 | 
			
		||||
		 */
 | 
			
		||||
		virtual int GetNumClients() =0;
 | 
			
		||||
 | 
			
		||||
		/**
 | 
			
		||||
		 * @brief Returns the client index by its userid.
 | 
			
		||||
		 *
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user