Expose explicit client auth string formats
This commit is contained in:
+26
-12
@@ -1914,7 +1914,7 @@ CPlayer::CPlayer()
|
||||
m_bIsSourceTV = false;
|
||||
m_bIsReplay = false;
|
||||
m_Serial.value = -1;
|
||||
m_SteamAccountID = 0;
|
||||
m_SteamID = k_steamIDNil;
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
m_LanguageCookie = InvalidQueryCvarCookie;
|
||||
#endif
|
||||
@@ -1997,7 +1997,7 @@ void CPlayer::Disconnect()
|
||||
m_bIsSourceTV = false;
|
||||
m_bIsReplay = false;
|
||||
m_Serial.value = -1;
|
||||
m_SteamAccountID = 0;
|
||||
m_SteamID = k_steamIDNil;
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
m_LanguageCookie = InvalidQueryCvarCookie;
|
||||
#endif
|
||||
@@ -2033,16 +2033,17 @@ const char *CPlayer::GetAuthString(bool validated)
|
||||
return m_AuthID.c_str();
|
||||
}
|
||||
|
||||
unsigned int CPlayer::GetSteamAccountID(bool validated)
|
||||
const CSteamID &CPlayer::GetSteamID(bool validated)
|
||||
{
|
||||
if (IsFakeClient() || (validated && !IsAuthStringValidated()))
|
||||
{
|
||||
return 0;
|
||||
static const CSteamID invalidId = k_steamIDNil;
|
||||
return invalidId;
|
||||
}
|
||||
|
||||
if (m_SteamAccountID != 0)
|
||||
if (m_SteamID.IsValid())
|
||||
{
|
||||
return m_SteamAccountID;
|
||||
return m_SteamID;
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE < SE_ORANGEBOX
|
||||
@@ -2050,22 +2051,35 @@ unsigned int CPlayer::GetSteamAccountID(bool validated)
|
||||
/* STEAM_0:1:123123 | STEAM_ID_LAN | STEAM_ID_PENDING */
|
||||
if (pAuth && (strlen(pAuth) > 10) && pAuth[8] != '_')
|
||||
{
|
||||
m_SteamAccountID = (atoi(&pAuth[8]) | (atoi(&pAuth[10]) << 1));
|
||||
m_SteamID = CSteamID(atoi(&pAuth[8]) | (atoi(&pAuth[10]) << 1),
|
||||
k_unSteamUserDesktopInstance, k_EUniversePublic, k_EAccountTypeIndividual);
|
||||
}
|
||||
#else
|
||||
unsigned long long *steamId;
|
||||
const CSteamID *steamId;
|
||||
#if SOURCE_ENGINE == SE_DOTA
|
||||
steamId = (unsigned long long *)engine->GetClientSteamID(m_iIndex);
|
||||
steamId = engine->GetClientSteamID(m_iIndex);
|
||||
#else
|
||||
steamId = (unsigned long long *)engine->GetClientSteamID(m_pEdict);
|
||||
steamId = engine->GetClientSteamID(m_pEdict);
|
||||
#endif
|
||||
|
||||
if (steamId)
|
||||
{
|
||||
m_SteamAccountID = (*steamId & 0xFFFFFFFF);
|
||||
m_SteamID = (*steamId);
|
||||
}
|
||||
#endif
|
||||
return m_SteamAccountID;
|
||||
return m_SteamID;
|
||||
}
|
||||
|
||||
unsigned int CPlayer::GetSteamAccountID(bool validated)
|
||||
{
|
||||
if (!IsFakeClient() && (!validated || IsAuthStringValidated()))
|
||||
{
|
||||
const CSteamID &id = GetSteamID();
|
||||
if (id.IsValid())
|
||||
return id.GetAccountID();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
edict_t *CPlayer::GetEdict()
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
#include <sh_vector.h>
|
||||
#include "ConVarManager.h"
|
||||
|
||||
#include <steam/steamclientpublic.h>
|
||||
|
||||
using namespace SourceHook;
|
||||
|
||||
#define PLAYER_LIFE_UNKNOWN 0
|
||||
@@ -71,6 +73,8 @@ public:
|
||||
const char *GetIPAddress();
|
||||
const char *GetAuthString(bool validated = true);
|
||||
unsigned int GetSteamAccountID(bool validated = true);
|
||||
const CSteamID &GetSteamID(bool validated = true);
|
||||
uint64_t GetSteamID64(bool validated = true) { return GetSteamID(validated).ConvertToUint64(); }
|
||||
edict_t *GetEdict();
|
||||
bool IsInGame();
|
||||
bool WasCountedAsInGame();
|
||||
@@ -130,7 +134,7 @@ private:
|
||||
bool m_bIsSourceTV;
|
||||
bool m_bIsReplay;
|
||||
serial_t m_Serial;
|
||||
unsigned int m_SteamAccountID;
|
||||
CSteamID m_SteamID;
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
QueryCvarCookie_t m_LanguageCookie;
|
||||
#endif
|
||||
|
||||
+108
-9
@@ -37,12 +37,21 @@
|
||||
#include <ITranslator.h>
|
||||
#include <sh_string.h>
|
||||
#include <sh_list.h>
|
||||
#include "GameConfigs.h"
|
||||
#include "CellArray.h"
|
||||
#include "AutoHandleRooter.h"
|
||||
|
||||
using namespace SourceHook;
|
||||
using namespace SourceMod;
|
||||
|
||||
#ifndef PRIu64
|
||||
#ifdef _WIN32
|
||||
#define PRIu64 "I64u"
|
||||
#else
|
||||
#define PRIu64 "llu"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static const int kActivityNone = 0;
|
||||
static const int kActivityNonAdmins = 1; // Show admin activity to non-admins anonymously.
|
||||
static const int kActivityNonAdminsNames = 2; // If 1 is specified, admin names will be shown.
|
||||
@@ -322,6 +331,15 @@ static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Must match clients.inc
|
||||
enum class AuthStringType
|
||||
{
|
||||
Engine,
|
||||
Steam2,
|
||||
Steam3,
|
||||
SteamID64,
|
||||
};
|
||||
|
||||
static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
int index = params[1];
|
||||
@@ -337,19 +355,100 @@ static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params)
|
||||
}
|
||||
|
||||
bool validate = true;
|
||||
if (params[0] > 3)
|
||||
if (params[0] >= 4)
|
||||
{
|
||||
validate = !!params[4];
|
||||
}
|
||||
|
||||
const char *authstr = pPlayer->GetAuthString(validate);
|
||||
|
||||
if (!authstr || authstr[0] == '\0')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
AuthStringType authType = AuthStringType::Engine;
|
||||
if (params[0] >= 5)
|
||||
{
|
||||
authType = (AuthStringType)params[5];
|
||||
}
|
||||
|
||||
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), authstr);
|
||||
switch (authType)
|
||||
{
|
||||
case AuthStringType::Engine:
|
||||
{
|
||||
const char *authstr = pPlayer->GetAuthString(validate);
|
||||
if (!authstr || authstr[0] == '\0')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), authstr);
|
||||
}
|
||||
break;
|
||||
case AuthStringType::Steam2:
|
||||
case AuthStringType::Steam3:
|
||||
{
|
||||
if (pPlayer->IsFakeClient())
|
||||
{
|
||||
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), "BOT");
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint64_t steamId = pPlayer->GetSteamID64(validate);
|
||||
if (steamId == 0)
|
||||
{
|
||||
if (gamehelpers->IsLANServer())
|
||||
{
|
||||
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), "STEAM_ID_LAN");
|
||||
}
|
||||
else
|
||||
{
|
||||
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), "STEAM_ID_PENDING");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
char szAuth[64];
|
||||
unsigned int universe = steamId >> 56;
|
||||
unsigned int accountId = steamId & 0xFFFFFFFF;
|
||||
unsigned int instance = (steamId >> 32) & 0x000FFFFF;
|
||||
if (authType == AuthStringType::Steam2)
|
||||
{
|
||||
if (atoi(g_pGameConf->GetKeyValue("UseInvalidUniverseInSteam2IDs")) == 1)
|
||||
{
|
||||
universe = 0;
|
||||
}
|
||||
|
||||
snprintf(szAuth, sizeof(szAuth), "STEAM_%u:%u:%u", universe, accountId % 2, accountId >> 1);
|
||||
}
|
||||
else if (instance != 1)
|
||||
{
|
||||
snprintf(szAuth, sizeof(szAuth), "[U:%u:%u:%u]", universe, accountId, instance);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(szAuth, sizeof(szAuth), "[U:%u:%u]", universe, accountId);
|
||||
}
|
||||
|
||||
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), szAuth);
|
||||
}
|
||||
break;
|
||||
|
||||
case AuthStringType::SteamID64:
|
||||
{
|
||||
if (pPlayer->IsFakeClient() || gamehelpers->IsLANServer())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t steamId = pPlayer->GetSteamID64(validate);
|
||||
if (steamId == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
char szAuth[64];
|
||||
snprintf(szAuth, sizeof(szAuth), "%" PRIu64, steamId);
|
||||
|
||||
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), szAuth);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user