Added a client verification serial API (bug 3616, r=dvander)
authorMatt Woodrow <pred@alliedmods.net>
Thu Feb 19 19:19:44 2009 +1300 (2009-02-19)
changeset 259115213de19689
parent 2590 ab9d418dc8b2
child 2592 e69a1297edbc
Added a client verification serial API (bug 3616, r=dvander)
core/PlayerManager.cpp
core/PlayerManager.h
core/smn_player.cpp
plugins/include/clients.inc
public/IPlayerHelpers.h
     1.1 --- a/core/PlayerManager.cpp	Thu Feb 19 14:23:36 2009 +1300
     1.2 +++ b/core/PlayerManager.cpp	Thu Feb 19 19:19:44 2009 +1300
     1.3 @@ -81,6 +81,8 @@
     1.4  
     1.5  ConCommand *maxplayersCmd = NULL;
     1.6  
     1.7 +unsigned int g_PlayerSerialCount = 0;
     1.8 +
     1.9  class KickPlayerTimer : public ITimedEvent
    1.10  {
    1.11  public:
    1.12 @@ -1356,6 +1358,28 @@
    1.13  	}
    1.14  }
    1.15  
    1.16 +int PlayerManager::GetClientFromSerial(unsigned int serial)
    1.17 +{
    1.18 +	serial_t s;
    1.19 +	s.value = serial;
    1.20 +
    1.21 +	int client = s.bits.index;
    1.22 +
    1.23 +	IGamePlayer *pPlayer = GetGamePlayer(client);
    1.24 +
    1.25 +	if (!pPlayer)
    1.26 +	{
    1.27 +		return 0;
    1.28 +	}
    1.29 +
    1.30 +	if (serial == pPlayer->GetSerial())
    1.31 +	{
    1.32 +		return client;
    1.33 +	}
    1.34 +
    1.35 +	return 0;
    1.36 +}
    1.37 +
    1.38  #if SOURCE_ENGINE >= SE_ORANGEBOX
    1.39  void CmdMaxplayersCallback(const CCommand &command)
    1.40  {
    1.41 @@ -1397,6 +1421,9 @@
    1.42  	m_iIndex = IndexOfEdict(pEntity);
    1.43  	m_LangId = g_Translator.GetServerLanguage();
    1.44  
    1.45 +	m_Serial.bits.index = m_iIndex;
    1.46 +	m_Serial.bits.serial = g_PlayerSerialCount++;
    1.47 +
    1.48  	char ip2[24], *ptr;
    1.49  	strncopy(ip2, ip, sizeof(ip2));
    1.50  	if ((ptr = strchr(ip2, ':')) != NULL)
    1.51 @@ -1760,3 +1787,8 @@
    1.52  		return PLAYER_LIFE_DEAD;
    1.53  	}
    1.54  }
    1.55 +
    1.56 +unsigned int CPlayer::GetSerial()
    1.57 +{
    1.58 +	return m_Serial.value;
    1.59 +}
    1.60 \ No newline at end of file
     2.1 --- a/core/PlayerManager.h	Thu Feb 19 14:23:36 2009 +1300
     2.2 +++ b/core/PlayerManager.h	Thu Feb 19 19:19:44 2009 +1300
     2.3 @@ -51,6 +51,16 @@
     2.4  
     2.5  #define MIN_API_FOR_ADMINCALLS		7
     2.6  
     2.7 +union serial_t
     2.8 +{
     2.9 +	uint32_t   value;
    2.10 +	struct
    2.11 +	{
    2.12 +		uint8_t  index;
    2.13 +		uint32_t serial : 24;
    2.14 +	} bits;
    2.15 +};
    2.16 +
    2.17  class CPlayer : public IGamePlayer
    2.18  {
    2.19  	friend class PlayerManager;
    2.20 @@ -74,6 +84,7 @@
    2.21  	int GetUserId();
    2.22  	bool RunAdminCacheChecks();
    2.23  	void NotifyPostAdminChecks();
    2.24 +	unsigned int GetSerial();
    2.25  public:
    2.26  	void DoBasicAdminChecks();
    2.27  	bool IsInKickQueue();
    2.28 @@ -107,6 +118,7 @@
    2.29  	unsigned int m_LangId;
    2.30  	int m_UserId;
    2.31  	bool m_bFakeClient;
    2.32 +	serial_t m_Serial;
    2.33  };
    2.34  
    2.35  class PlayerManager : 
    2.36 @@ -156,6 +168,7 @@
    2.37  	void RegisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
    2.38  	void UnregisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
    2.39  	void ProcessCommandTarget(cmd_target_info_t *info);
    2.40 +	int GetClientFromSerial(unsigned int serial);
    2.41  public: // IConVarChangeListener
    2.42  	void OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue);
    2.43  public:
     3.1 --- a/core/smn_player.cpp	Thu Feb 19 14:23:36 2009 +1300
     3.2 +++ b/core/smn_player.cpp	Thu Feb 19 19:19:44 2009 +1300
     3.3 @@ -1551,6 +1551,24 @@
     3.4  	return bShowActivity ? 1 : 0;
     3.5  }
     3.6  
     3.7 +static cell_t sm_GetClientSerial(IPluginContext *pContext, const cell_t *params)
     3.8 +{
     3.9 +	int client = params[1];
    3.10 +
    3.11 +	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
    3.12 +	if (!pPlayer)
    3.13 +	{
    3.14 +		return pContext->ThrowNativeError("Client index %d is invalid", client);
    3.15 +	}
    3.16 +
    3.17 +	return pPlayer->GetSerial();
    3.18 +}
    3.19 +
    3.20 +static cell_t sm_GetClientFromSerial(IPluginContext *pContext, const cell_t *params)
    3.21 +{
    3.22 +	return g_Players.GetClientFromSerial(params[1]);
    3.23 +}
    3.24 +
    3.25  REGISTER_NATIVES(playernatives)
    3.26  {
    3.27  	{"AddUserFlags",			AddUserFlags},
    3.28 @@ -1604,6 +1622,8 @@
    3.29  	{"IsClientInKickQueue",		IsClientInKickQueue},
    3.30  	{"ProcessTargetString",		ProcessTargetString},
    3.31  	{"FormatActivitySource",	FormatActivitySource},
    3.32 +	{"GetClientSerial",			sm_GetClientSerial},
    3.33 +	{"GetClientFromSerial",		sm_GetClientFromSerial},
    3.34  	{NULL,						NULL}
    3.35  };
    3.36  
     4.1 --- a/plugins/include/clients.inc	Thu Feb 19 14:23:36 2009 +1300
     4.2 +++ b/plugins/include/clients.inc	Thu Feb 19 19:19:44 2009 +1300
     4.3 @@ -708,3 +708,17 @@
     4.4   */
     4.5  native ChangeClientTeam(client, team);
     4.6  
     4.7 +/**
     4.8 + * Returns the clients unique serial identifier.
     4.9 + *
    4.10 + * @return	Serial number.
    4.11 + */
    4.12 +native GetClientSerial(client);
    4.13 +
    4.14 +/**
    4.15 + * Returns the client index by its serial number.
    4.16 + *
    4.17 + * @return				Client index, or 0 for invalid serial.
    4.18 + */
    4.19 +native GetClientFromSerial(serial);
    4.20 +
     5.1 --- a/public/IPlayerHelpers.h	Thu Feb 19 14:23:36 2009 +1300
     5.2 +++ b/public/IPlayerHelpers.h	Thu Feb 19 19:19:44 2009 +1300
     5.3 @@ -41,7 +41,7 @@
     5.4  #include <IAdminSystem.h>
     5.5  
     5.6  #define SMINTERFACE_PLAYERMANAGER_NAME		"IPlayerManager"
     5.7 -#define SMINTERFACE_PLAYERMANAGER_VERSION	8
     5.8 +#define SMINTERFACE_PLAYERMANAGER_VERSION	9
     5.9  
    5.10  struct edict_t;
    5.11  class IPlayerInfo;
    5.12 @@ -183,6 +183,13 @@
    5.13  		 * call it at various times).
    5.14  		 */
    5.15  		virtual void NotifyPostAdminChecks() =0;
    5.16 +
    5.17 +		/**
    5.18 +		 * @brief Returns the clients unique serial identifier.
    5.19 +		 *
    5.20 +		 * @return	Serial number.
    5.21 +		 */
    5.22 +		virtual unsigned int GetSerial() =0;
    5.23  	};
    5.24  
    5.25  	/**
    5.26 @@ -481,6 +488,13 @@
    5.27  		 * @param pHandler		Pointer to an ICommandTargetProcessor instance.
    5.28  		 */
    5.29  		virtual void UnregisterCommandTargetProcessor(ICommandTargetProcessor *pHandler) =0;
    5.30 +
    5.31 +		/**
    5.32 +		 * @brief Returns the client index by its serial number.
    5.33 +		 *
    5.34 +		 * @return				Client index, or 0 for invalid serial.
    5.35 +		 */
    5.36 +		virtual int GetClientFromSerial(unsigned int serial) =0;
    5.37  	};
    5.38  }
    5.39