Added GetSteamAccountID function to IPlayerHelpers and native for sp (bug 5548, r=asherkin).
authorKyle Sanderson <kyle.leet@gmail.com>
Sat Mar 16 23:12:40 2013 -0400 (2013-03-16)
changeset 3825ecd2382ca37e
parent 3824 2e6d9effa65e
child 3826 cdb77388037e
Added GetSteamAccountID function to IPlayerHelpers and native for sp (bug 5548, r=asherkin).
core/PlayerManager.cpp
core/PlayerManager.h
core/smn_player.cpp
plugins/include/clients.inc
public/IPlayerHelpers.h
     1.1 --- a/core/PlayerManager.cpp	Sat Mar 16 23:02:36 2013 -0400
     1.2 +++ b/core/PlayerManager.cpp	Sat Mar 16 23:12:40 2013 -0400
     1.3 @@ -923,8 +923,7 @@
     1.4  	const char *networkid_force;
     1.5  	if ((networkid_force = engine->GetClientConVarValue(client, "networkid_force")) && networkid_force[0] != '\0')
     1.6  	{
     1.7 -		unsigned long long *steamId = (unsigned long long *)engine->GetClientSteamID(pEntity);
     1.8 -		unsigned int accountId = steamId ? (*steamId & 0xFFFFFFFF) : 0;
     1.9 +		unsigned int accountId = pPlayer->GetSteamAccountID();
    1.10  		g_Logger.LogMessage("\"%s<%d><STEAM_1:%d:%d><>\" has bad networkid (id \"%s\") (ip \"%s\")",
    1.11  			new_name, pPlayer->GetUserId(), accountId & 1, accountId >> 1, networkid_force, pPlayer->GetIPAddress());
    1.12  
    1.13 @@ -1586,6 +1585,7 @@
    1.14  	m_bIsSourceTV = false;
    1.15  	m_bIsReplay = false;
    1.16  	m_Serial.value = -1;
    1.17 +	m_SteamAccountID = 0;
    1.18  }
    1.19  
    1.20  void CPlayer::Initialize(const char *name, const char *ip, edict_t *pEntity)
    1.21 @@ -1665,6 +1665,7 @@
    1.22  	m_bIsSourceTV = false;
    1.23  	m_bIsReplay = false;
    1.24  	m_Serial.value = -1;
    1.25 +	m_SteamAccountID = 0;
    1.26  }
    1.27  
    1.28  void CPlayer::SetName(const char *name)
    1.29 @@ -1697,6 +1698,35 @@
    1.30  	return m_AuthID.c_str();
    1.31  }
    1.32  
    1.33 +unsigned int CPlayer::GetSteamAccountID(bool validated)
    1.34 +{
    1.35 +	if (IsFakeClient() || (validated && !IsAuthStringValidated()))
    1.36 +	{
    1.37 +		return 0;
    1.38 +	}
    1.39 +
    1.40 +	if (m_SteamAccountID != 0)
    1.41 +	{
    1.42 +		return m_SteamAccountID;
    1.43 +	}
    1.44 +
    1.45 +#if SOURCE_ENGINE < SE_ORANGEBOX
    1.46 +	const char * pAuth = GetAuthString();
    1.47 +	/* STEAM_0:1:123123 | STEAM_ID_LAN | STEAM_ID_PENDING */
    1.48 +	if (pAuth && (strlen(pAuth) > 10) && pAuth[8] != '_')
    1.49 +	{
    1.50 +		m_SteamAccountID = (atoi(&pAuth[8]) | (atoi(&pAuth[10]) << 1));
    1.51 +	}
    1.52 +#else
    1.53 +	unsigned long long *steamId = (unsigned long long *)engine->GetClientSteamID(m_pEdict);
    1.54 +	if (steamId)
    1.55 +	{
    1.56 +		m_SteamAccountID = (*steamId & 0xFFFFFFFF);
    1.57 +	}
    1.58 +#endif
    1.59 +	return m_SteamAccountID;
    1.60 +}
    1.61 +
    1.62  edict_t *CPlayer::GetEdict()
    1.63  {
    1.64  	return m_pEdict;
     2.1 --- a/core/PlayerManager.h	Sat Mar 16 23:02:36 2013 -0400
     2.2 +++ b/core/PlayerManager.h	Sat Mar 16 23:12:40 2013 -0400
     2.3 @@ -70,6 +70,7 @@
     2.4  	const char *GetName();
     2.5  	const char *GetIPAddress();
     2.6  	const char *GetAuthString(bool validated = true);
     2.7 +	unsigned int GetSteamAccountID(bool validated = true);
     2.8  	edict_t *GetEdict();
     2.9  	bool IsInGame();
    2.10  	bool WasCountedAsInGame();
    2.11 @@ -126,6 +127,7 @@
    2.12  	bool m_bIsSourceTV;
    2.13  	bool m_bIsReplay;
    2.14  	serial_t m_Serial;
    2.15 +	unsigned int m_SteamAccountID;
    2.16  };
    2.17  
    2.18  class PlayerManager : 
     3.1 --- a/core/smn_player.cpp	Sat Mar 16 23:02:36 2013 -0400
     3.2 +++ b/core/smn_player.cpp	Sat Mar 16 23:12:40 2013 -0400
     3.3 @@ -174,6 +174,23 @@
     3.4  	return 1;
     3.5  }
     3.6  
     3.7 +static cell_t sm_GetSteamAccountID(IPluginContext *pCtx, const cell_t *params)
     3.8 +{
     3.9 +	int index = params[1];
    3.10 +	if ((index < 1) || (index > g_Players.GetMaxClients()))
    3.11 +	{
    3.12 +		return pCtx->ThrowNativeError("Client index %d is invalid", index);
    3.13 +	}
    3.14 +
    3.15 +	CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
    3.16 +	if (!pPlayer->IsConnected())
    3.17 +	{
    3.18 +		return pCtx->ThrowNativeError("Client %d is not connected", index);
    3.19 +	}
    3.20 +
    3.21 +	return pPlayer->GetSteamAccountID(!!params[2]);
    3.22 +}
    3.23 +
    3.24  static cell_t sm_IsClientConnected(IPluginContext *pCtx, const cell_t *params)
    3.25  {
    3.26  	int index = params[1];
    3.27 @@ -1651,6 +1668,7 @@
    3.28  	{"CanUserTarget",			CanUserTarget},
    3.29  	{"ChangeClientTeam",		ChangeClientTeam},
    3.30  	{"GetClientAuthString",		sm_GetClientAuthStr},
    3.31 +	{"GetSteamAccountID",		sm_GetSteamAccountID},
    3.32  	{"GetClientCount",			sm_GetClientCount},
    3.33  	{"GetClientInfo",			sm_GetClientInfo},
    3.34  	{"GetClientIP",				sm_GetClientIP},
     4.1 --- a/plugins/include/clients.inc	Sat Mar 16 23:02:36 2013 -0400
     4.2 +++ b/plugins/include/clients.inc	Sat Mar 16 23:12:40 2013 -0400
     4.3 @@ -270,6 +270,18 @@
     4.4  native bool:GetClientAuthString(client, String:auth[], maxlen, bool:validate=true);
     4.5  
     4.6  /**
     4.7 + * Returns the client's Steam account ID.
     4.8 + *
     4.9 + * @param client		Client Index.
    4.10 + * @param validate		Check backend validation status.
    4.11 + * 				DO NOT PASS FALSE UNLESS YOU UNDERSTAND THE CONSEQUENCES,
    4.12 + *			        You WILL KNOW if you need to use this, MOST WILL NOT.
    4.13 + * @return				Steam account ID or 0 if not available.
    4.14 + * @error				If the client is not connected or the index is invalid.
    4.15 + */
    4.16 +native GetSteamAccountID(client, bool:validate=true);
    4.17 +
    4.18 +/**
    4.19   * Retrieves a client's user id, which is an index incremented for every client
    4.20   * that joins the server.
    4.21   *
     5.1 --- a/public/IPlayerHelpers.h	Sat Mar 16 23:02:36 2013 -0400
     5.2 +++ b/public/IPlayerHelpers.h	Sat Mar 16 23:12:40 2013 -0400
     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	16
     5.8 +#define SMINTERFACE_PLAYERMANAGER_VERSION	17
     5.9  
    5.10  struct edict_t;
    5.11  class IPlayerInfo;
    5.12 @@ -237,6 +237,15 @@
    5.13  		 * @return		True if the Replay bot, false otherwise.
    5.14  		 */
    5.15  		virtual bool IsReplay() const =0;
    5.16 +		
    5.17 +		/**
    5.18 +		 * @brief Returns the client's Steam account ID.
    5.19 +		 *
    5.20 +		 * @param validated		Check backend validation status.
    5.21 +		 * 
    5.22 +		 * @return			Steam account ID or 0 if not available.
    5.23 +		 */
    5.24 +		virtual unsigned int GetSteamAccountID(bool validated = true) =0;
    5.25  	};
    5.26  
    5.27  	/**