Move Steam2/3 id rendering logic to CPlayer

This commit is contained in:
Nicholas Hastings 2014-09-04 15:27:44 -07:00
parent 892edd9650
commit f1dc24c089
4 changed files with 113 additions and 43 deletions

View File

@ -2070,6 +2070,83 @@ const CSteamID &CPlayer::GetSteamId(bool validated)
return m_SteamId;
}
bool CPlayer::GetSteam2Id(char *out, size_t maxlen, bool validate)
{
if (IsFakeClient())
{
snprintf(out, maxlen, "BOT");
return true;
}
auto steamId = GetSteamId(validate);
if (!steamId.IsValid())
{
if (g_HL2.IsLANServer())
{
snprintf(out, maxlen, "STEAM_ID_LAN");
return true;
}
else if (!validate)
{
snprintf(out, maxlen, "STEAM_ID_PENDING");
return true;
}
else
{
return false;
}
}
EUniverse universe = steamId.GetEUniverse();
if (atoi(g_pGameConf->GetKeyValue("UseInvalidUniverseInSteam2IDs")) == 1)
{
universe = k_EUniverseInvalid;
}
snprintf(out, maxlen, "STEAM_%u:%u:%u", universe, steamId.GetAccountID() & 1, steamId.GetAccountID() >> 1);
return true;
}
bool CPlayer::GetSteam3Id(char *out, size_t maxlen, bool validate)
{
if (IsFakeClient())
{
snprintf(out, maxlen, "BOT");
return true;
}
auto steamId = GetSteamId(validate);
if (!steamId.IsValid())
{
if (g_HL2.IsLANServer())
{
snprintf(out, maxlen, "STEAM_ID_LAN");
return true;
}
else if (!validate)
{
snprintf(out, maxlen, "STEAM_ID_PENDING");
return true;
}
else
{
return false;
}
}
// TODO: make sure all hl2sdks' steamclientpublic.h have k_unSteamUserDesktopInstance.
if (steamId.GetUnAccountInstance() == 1 /* k_unSteamUserDesktopInstance */)
{
snprintf(out, maxlen, "[U:%u:%u]", steamId.GetEUniverse(), steamId.GetAccountID());
}
else
{
snprintf(out, maxlen, "[U:%u:%u:%u]", steamId.GetEUniverse(), steamId.GetAccountID(), steamId.GetUnAccountInstance());
}
return true;
}
unsigned int CPlayer::GetSteamAccountID(bool validated)
{
if (!IsFakeClient() && (!validated || IsAuthStringValidated()))

View File

@ -75,6 +75,8 @@ public:
unsigned int GetSteamAccountID(bool validated = true);
const CSteamID &GetSteamId(bool validated = true);
uint64_t GetSteamId64(bool validated = true) { return GetSteamId(validated).ConvertToUint64(); }
bool GetSteam2Id(char *out, size_t maxlen, bool validated = true);
bool GetSteam3Id(char *out, size_t maxlen, bool validated = true);
edict_t *GetEdict();
bool IsInGame();
bool WasCountedAsInGame();

View File

@ -367,53 +367,22 @@ static cell_t SteamIdToLocal(IPluginContext *pCtx, int index, AuthIdType authTyp
}
break;
case AuthIdType::Steam2:
case AuthIdType::Steam3:
{
if (pPlayer->IsFakeClient())
{
pCtx->StringToLocal(local_addr, bytes, "BOT");
return 1;
}
uint64_t steamId = pPlayer->GetSteamId64(validate);
if (steamId == 0)
{
if (gamehelpers->IsLANServer())
{
pCtx->StringToLocal(local_addr, bytes, "STEAM_ID_LAN");
return 1;
}
else if (!validate)
{
pCtx->StringToLocal(local_addr, bytes, "STEAM_ID_PENDING");
return 1;
}
else
char szAuth[64];
if (!pPlayer->GetSteam2Id(szAuth, sizeof(szAuth), validate))
{
return 0;
}
}
pCtx->StringToLocal(local_addr, bytes, szAuth);
}
break;
case AuthIdType::Steam3:
{
char szAuth[64];
unsigned int universe = steamId >> 56;
unsigned int accountId = steamId & 0xFFFFFFFF;
unsigned int instance = (steamId >> 32) & 0x000FFFFF;
if (authType == AuthIdType::Steam2)
if (!pPlayer->GetSteam2Id(szAuth, sizeof(szAuth), validate))
{
if (atoi(g_pGameConf->GetKeyValue("UseInvalidUniverseInSteam2IDs")) == 1)
{
universe = 0;
}
snprintf(szAuth, sizeof(szAuth), "STEAM_%u:%u:%u", universe, accountId & 1, 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);
return 0;
}
pCtx->StringToLocal(local_addr, bytes, szAuth);

View File

@ -276,6 +276,28 @@ namespace SourceMod
* @return Steam Id or 0 if not available.
*/
virtual uint64_t GetSteamId64(bool validated = true) =0;
/**
* @brief Returns the client's Steam ID rendered in Steam2 format.
*
* @param out Buffer in which to output the id.
* @param maxlen Maximum length of the output buffer in bytes.
* @param validated Check backend validation status.
*
* @return True on success or false if not available.
*/
virtual bool GetSteam2Id(char *out, size_t maxlen, bool validated = true) =0;
/**
* @brief Returns the client's Steam ID rendered in Steam3 format.
*
* @param out Buffer in which to output the id.
* @param maxlen Maximum length of the output buffer in bytes.
* @param validated Check backend validation status.
*
* @return True on success or false if not available.
*/
virtual bool GetSteam3Id(char *out, size_t maxlen, bool validated = true) =0;
};
/**