From 111c95fea64391b9e48a2435a7ebb60955eba735 Mon Sep 17 00:00:00 2001 From: Kyle Sanderson Date: Fri, 14 Oct 2016 12:46:10 -0700 Subject: [PATCH] Check multiple engine sources for updated AuthIDs. (#552) --- core/PlayerManager.cpp | 90 ++++++++++++++++++++++-------------------- core/PlayerManager.h | 2 + 2 files changed, 50 insertions(+), 42 deletions(-) diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 7b6357eea..87f8b6471 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -2008,49 +2008,8 @@ void CPlayer::Connect() void CPlayer::UpdateAuthIds() { - if (m_IsAuthorized) - { + if (m_IsAuthorized || (!SetEngineString() && !SetCSteamID())) return; - } - - // First cache engine networkid - const char *authstr = engine->GetPlayerNetworkIDString(m_pEdict); - if (!authstr) - { - // engine doesn't have the client's auth string just yet, we can't do anything - return; - } - - if (m_AuthID.compare(authstr) == 0) - { - return; - } - - m_AuthID = authstr; - - // Then, cache SteamId - if (IsFakeClient()) - { - m_SteamId = k_steamIDNil; - } - else - { -#if SOURCE_ENGINE < SE_ORANGEBOX - const char * pAuth = GetAuthString(); - /* STEAM_0:1:123123 | STEAM_ID_LAN | STEAM_ID_PENDING */ - if (pAuth && (strlen(pAuth) > 10) && pAuth[8] != '_') - { - m_SteamId = CSteamID(atoi(&pAuth[8]) | (atoi(&pAuth[10]) << 1), - k_unSteamUserDesktopInstance, k_EUniversePublic, k_EAccountTypeIndividual); - } -#else - const CSteamID *steamId = engine->GetClientSteamID(m_pEdict); - if (steamId) - { - m_SteamId = (*steamId); - } -#endif - } // Now cache Steam2/3 rendered ids if (IsFakeClient()) @@ -2102,6 +2061,53 @@ void CPlayer::UpdateAuthIds() m_Steam3Id = szAuthBuffer; } +bool CPlayer::SetEngineString() +{ + const char *authstr = engine->GetPlayerNetworkIDString(m_pEdict); + if (!authstr || m_AuthID.compare(authstr) == 0) + return false; + + m_AuthID = authstr; + SetCSteamID(); + return true; +} + +bool CPlayer::SetCSteamID() +{ + if (IsFakeClient()) + { + m_SteamId = k_steamIDNil; + return true; /* This is the default value. There's a bug-out branch in the caller function. */ + } + +#if SOURCE_ENGINE < SE_ORANGEBOX + const char *pAuth = GetAuthString(); + /* STEAM_0:1:123123 | STEAM_ID_LAN | STEAM_ID_PENDING */ + if (pAuth && (strlen(pAuth) > 10) && pAuth[8] != '_') + { + CSteamID sid = CSteamID(atoi(&pAuth[8]) | (atoi(&pAuth[10]) << 1), + k_unSteamUserDesktopInstance, k_EUniversePublic, k_EAccountTypeIndividual); + + if (m_SteamId != sid) + { + m_SteamId = sid; + return true; + } + } +#else + const CSteamID *steamId = engine->GetClientSteamID(m_pEdict); + if (steamId) + { + if (m_SteamId != (*steamId)) + { + m_SteamId = (*steamId); + return true; + } + } +#endif + return false; +} + // Ensure a valid AuthString is set before calling. void CPlayer::Authorize() { diff --git a/core/PlayerManager.h b/core/PlayerManager.h index 76df8b152..5e88f066b 100644 --- a/core/PlayerManager.h +++ b/core/PlayerManager.h @@ -120,6 +120,8 @@ private: void Authorize_Post(); void DoPostConnectAuthorization(); bool IsAuthStringValidated(); + bool SetEngineString(); + bool SetCSteamID(); private: bool m_IsConnected; bool m_IsInGame;