core/PlayerManager.cpp
changeset 3418 b0e93f5101ef
parent 3413 f1539fcb176c
child 3436 d9ef0c2068d7
     1.1 --- a/core/PlayerManager.cpp	Thu Oct 20 21:35:50 2011 -0400
     1.2 +++ b/core/PlayerManager.cpp	Thu Oct 20 21:39:57 2011 -0400
     1.3 @@ -44,6 +44,7 @@
     1.4  #include "HalfLife2.h"
     1.5  #include <inetchannel.h>
     1.6  #include <iclient.h>
     1.7 +#include <tier0/icommandline.h>
     1.8  #include <IGameConfigs.h>
     1.9  #include "ExtensionSys.h"
    1.10  #include <sourcemod_version.h>
    1.11 @@ -113,6 +114,9 @@
    1.12  	m_FirstPass = false;
    1.13  	m_maxClients = 0;
    1.14  
    1.15 +	m_SourceTVUserId = -1;
    1.16 +	m_ReplayUserId = -1;
    1.17 +
    1.18  	m_UserIdLookUp = new int[USHRT_MAX+1];
    1.19  	memset(m_UserIdLookUp, 0, sizeof(int) * (USHRT_MAX+1));
    1.20  }
    1.21 @@ -232,8 +236,20 @@
    1.22  
    1.23  void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
    1.24  {
    1.25 +	static ConVar *tv_enable = icvar->FindVar("tv_enable");
    1.26 +#if SOURCE_ENGINE == SE_ORANGEBOXVALVE
    1.27 +	static ConVar *replay_enable = icvar->FindVar("replay_enable");
    1.28 +#endif
    1.29 +
    1.30  	// clientMax will not necessarily be correct here (such as on late SourceTV enable)
    1.31  	m_maxClients = gpGlobals->maxClients;
    1.32 +
    1.33 +	m_bIsSourceTVActive = (tv_enable && tv_enable->GetBool() && CommandLine()->FindParm("-nohltv") == 0);
    1.34 +	m_bIsReplayActive = false;
    1.35 +#if SOURCE_ENGINE == SE_ORANGEBOXVALVE
    1.36 +	m_bIsReplayActive = (replay_enable && replay_enable->GetBool());
    1.37 +#endif
    1.38 +	m_PlayersSinceActive = 0;
    1.39  	
    1.40  	if (!m_FirstPass)
    1.41  	{
    1.42 @@ -411,6 +427,7 @@
    1.43  {
    1.44  	int client = IndexOfEdict(pEntity);
    1.45  	CPlayer *pPlayer = &m_Players[client];
    1.46 +	++m_PlayersSinceActive;
    1.47  
    1.48  	pPlayer->Initialize(pszName, pszAddress, pEntity);
    1.49  	
    1.50 @@ -518,6 +535,40 @@
    1.51  		const char *authid = engine->GetPlayerNetworkIDString(pEntity);
    1.52  		pPlayer->Authorize(authid);
    1.53  		pPlayer->m_bFakeClient = true;
    1.54 +
    1.55 +		/*
    1.56 +		 * While we're already filtered to just bots, we'll do other checks to
    1.57 +		 * make sure that the requisite services are enabled and that the bots
    1.58 +		 * have joined at the expected time.
    1.59 +		 *
    1.60 +		 * Checking playerinfo's IsHLTV and IsReplay would be better and less
    1.61 +		 * error-prone but will always show false until later in the frame,
    1.62 +		 * after PutInServer and Activate, and we want it now!
    1.63 +		 */
    1.64 +		
    1.65 +		// This doesn't actually get incremented until OnClientConnect. Fake it to check.
    1.66 +		int newCount = m_PlayersSinceActive + 1;
    1.67 +		int userId = engine->GetPlayerUserId(pEntity);
    1.68 +
    1.69 +#if SOURCE_ENGINE == SE_ORANGEBOXVALVE
    1.70 +		if (m_bIsReplayActive && newCount == 1
    1.71 +			&& (m_ReplayUserId == userId || strcmp(playername, "Replay") == 0))
    1.72 +		{
    1.73 +			pPlayer->m_bIsReplay = true;
    1.74 +			m_ReplayUserId = userId;
    1.75 +		}
    1.76 +#endif
    1.77 +
    1.78 +		if (m_bIsSourceTVActive
    1.79 +			&& ((!m_bIsReplayActive && newCount == 1)
    1.80 +				|| (m_bIsReplayActive && newCount == 2))
    1.81 +			&& (m_SourceTVUserId == userId || strcmp(playername, "SourceTV") == 0)
    1.82 +			)
    1.83 +		{
    1.84 +			pPlayer->m_bIsSourceTV = true;
    1.85 +			m_SourceTVUserId = userId;
    1.86 +		}
    1.87 +
    1.88  		if (!OnClientConnect(pEntity, playername, "127.0.0.1", error, sizeof(error)))
    1.89  		{
    1.90  			/* :TODO: kick the bot if it's rejected */
    1.91 @@ -1452,6 +1503,8 @@
    1.92  	m_LastPassword.clear();
    1.93  	m_LangId = SOURCEMOD_LANGUAGE_ENGLISH;
    1.94  	m_bFakeClient = false;
    1.95 +	m_bIsSourceTV = false;
    1.96 +	m_bIsReplay = false;
    1.97  	m_Serial.value = -1;
    1.98  }
    1.99  
   1.100 @@ -1524,6 +1577,8 @@
   1.101  	m_UserId = -1;
   1.102  	m_bIsInKickQueue = false;
   1.103  	m_bFakeClient = false;
   1.104 +	m_bIsSourceTV = false;
   1.105 +	m_bIsReplay = false;
   1.106  	m_Serial.value = -1;
   1.107  }
   1.108  
   1.109 @@ -1592,6 +1647,16 @@
   1.110  	return m_bFakeClient;
   1.111  }
   1.112  
   1.113 +bool CPlayer::IsSourceTV() const
   1.114 +{
   1.115 +	return m_bIsSourceTV;
   1.116 +}
   1.117 +
   1.118 +bool CPlayer::IsReplay() const
   1.119 +{
   1.120 +	return m_bIsReplay;
   1.121 +}
   1.122 +
   1.123  void CPlayer::SetAdminId(AdminId id, bool temporary)
   1.124  {
   1.125  	if (!m_IsConnected)