From 8c89b72fbc8b31c0794562683df69ea72c3cadc2 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Tue, 2 Sep 2014 14:40:39 -0700 Subject: [PATCH 1/7] Expose explicit client auth string formats --- core/PlayerManager.cpp | 38 +++++--- core/PlayerManager.h | 6 +- core/logic/smn_players.cpp | 117 ++++++++++++++++++++++-- gamedata/core.games/engine.bgt.txt | 5 + gamedata/core.games/engine.css.txt | 5 + gamedata/core.games/engine.darkm.txt | 5 + gamedata/core.games/engine.ep1.txt | 5 + gamedata/core.games/engine.ep2.txt | 8 ++ gamedata/core.games/engine.ep2valve.txt | 5 + gamedata/core.games/engine.eye.txt | 5 + gamedata/core.games/engine.sdk2013.txt | 8 ++ plugins/include/clients.inc | 16 +++- public/IPlayerHelpers.h | 11 ++- 13 files changed, 210 insertions(+), 24 deletions(-) diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 587db7e5..4bdecd8a 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -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() diff --git a/core/PlayerManager.h b/core/PlayerManager.h index 9bb58f0b..ad98090c 100644 --- a/core/PlayerManager.h +++ b/core/PlayerManager.h @@ -43,6 +43,8 @@ #include #include "ConVarManager.h" +#include + 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 diff --git a/core/logic/smn_players.cpp b/core/logic/smn_players.cpp index 47288f0a..7b27c0a1 100644 --- a/core/logic/smn_players.cpp +++ b/core/logic/smn_players.cpp @@ -37,12 +37,21 @@ #include #include #include +#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(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(params[3]), authstr); + } + break; + case AuthStringType::Steam2: + case AuthStringType::Steam3: + { + if (pPlayer->IsFakeClient()) + { + pCtx->StringToLocal(params[2], static_cast(params[3]), "BOT"); + return 1; + } + + uint64_t steamId = pPlayer->GetSteamID64(validate); + if (steamId == 0) + { + if (gamehelpers->IsLANServer()) + { + pCtx->StringToLocal(params[2], static_cast(params[3]), "STEAM_ID_LAN"); + } + else + { + pCtx->StringToLocal(params[2], static_cast(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(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(params[3]), szAuth); + } + break; + } return 1; } diff --git a/gamedata/core.games/engine.bgt.txt b/gamedata/core.games/engine.bgt.txt index 674993e8..c4502dbb 100644 --- a/gamedata/core.games/engine.bgt.txt +++ b/gamedata/core.games/engine.bgt.txt @@ -36,5 +36,10 @@ "windows" "\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xB9\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\x6A" } } + + "Keys" + { + "UseInvalidUniverseInSteam2IDs" "1" + } } } diff --git a/gamedata/core.games/engine.css.txt b/gamedata/core.games/engine.css.txt index cf08b2b0..2ec1cc75 100644 --- a/gamedata/core.games/engine.css.txt +++ b/gamedata/core.games/engine.css.txt @@ -53,5 +53,10 @@ "mac" "@gEntList" } } + + "Keys" + { + "UseInvalidUniverseInSteam2IDs" "1" + } } } diff --git a/gamedata/core.games/engine.darkm.txt b/gamedata/core.games/engine.darkm.txt index d84d54b3..f458d257 100644 --- a/gamedata/core.games/engine.darkm.txt +++ b/gamedata/core.games/engine.darkm.txt @@ -42,5 +42,10 @@ "windows" "\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xB9\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8" } } + + "Keys" + { + "UseInvalidUniverseInSteam2IDs" "1" + } } } diff --git a/gamedata/core.games/engine.ep1.txt b/gamedata/core.games/engine.ep1.txt index de669556..932f92ca 100644 --- a/gamedata/core.games/engine.ep1.txt +++ b/gamedata/core.games/engine.ep1.txt @@ -106,6 +106,11 @@ "windows" "\x56\x8B\x74\x24\x08\x57\x56\x8B\xF9\xE8\x2A\x2A\x2A\x2A\x84\xC0\x0F\x85\xC4\x00\x00\x00\x56\x8D" } } + + "Keys" + { + "UseInvalidUniverseInSteam2IDs" "1" + } } } diff --git a/gamedata/core.games/engine.ep2.txt b/gamedata/core.games/engine.ep2.txt index ba0a3460..d1a4f5bd 100644 --- a/gamedata/core.games/engine.ep2.txt +++ b/gamedata/core.games/engine.ep2.txt @@ -58,4 +58,12 @@ } } } + + "#default" + { + "Keys" + { + "UseInvalidUniverseInSteam2IDs" "1" + } + } } diff --git a/gamedata/core.games/engine.ep2valve.txt b/gamedata/core.games/engine.ep2valve.txt index 55eef306..0dc63e82 100644 --- a/gamedata/core.games/engine.ep2valve.txt +++ b/gamedata/core.games/engine.ep2valve.txt @@ -52,5 +52,10 @@ "mac" "@gEntList" } } + + "Keys" + { + "UseInvalidUniverseInSteam2IDs" "1" + } } } diff --git a/gamedata/core.games/engine.eye.txt b/gamedata/core.games/engine.eye.txt index f99e691d..045f65aa 100644 --- a/gamedata/core.games/engine.eye.txt +++ b/gamedata/core.games/engine.eye.txt @@ -41,5 +41,10 @@ "windows" "\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xB9\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8" } } + + "Keys" + { + "UseInvalidUniverseInSteam2IDs" "1" + } } } diff --git a/gamedata/core.games/engine.sdk2013.txt b/gamedata/core.games/engine.sdk2013.txt index 498fb367..4912944c 100644 --- a/gamedata/core.games/engine.sdk2013.txt +++ b/gamedata/core.games/engine.sdk2013.txt @@ -95,4 +95,12 @@ } } } + + "#default" + { + "Keys" + { + "UseInvalidUniverseInSteam2IDs" "1" + } + } } diff --git a/plugins/include/clients.inc b/plugins/include/clients.inc index 174ca0ad..913d26a3 100644 --- a/plugins/include/clients.inc +++ b/plugins/include/clients.inc @@ -45,6 +45,19 @@ enum NetFlow NetFlow_Both, /**< Both values added together */ }; +/** + * Auth string types. + */ +enum AuthStringType +{ + AuthString_Engine, /**< The game-specific auth string as returned from the engine */ + + // The following are only available on games that support Steam authentication. + AuthString_Steam2, /**< Steam2 rendered format, ex "STEAM_1:1:4153990" */ + AuthString_Steam3, /**< Steam3 rendered format, ex "[U:1:8307981]" */ + AuthString_SteamID64, /**< A SteamID64 (uint64) as a String, ex "76561197968573709" */ +}; + /** * MAXPLAYERS is not the same as MaxClients. * MAXPLAYERS is a hardcoded value as an upper limit. MaxClients changes based on the server. @@ -264,10 +277,11 @@ native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true); * @param validate Check backend validation status. * DO NOT PASS FALSE UNLESS YOU UNDERSTAND THE CONSEQUENCES, * You WILL KNOW if you need to use this, MOST WILL NOT. + * @param authType Auth string type and format to use. * @return True on success, false otherwise. * @error If the client is not connected or the index is invalid. */ -native bool:GetClientAuthString(client, String:auth[], maxlen, bool:validate=true); +native bool:GetClientAuthString(client, String:auth[], maxlen, bool:validate=true, AuthStringType:authType=AuthString_Engine); /** * Returns the client's Steam account ID. diff --git a/public/IPlayerHelpers.h b/public/IPlayerHelpers.h index 8b1d9cd2..72e007e4 100644 --- a/public/IPlayerHelpers.h +++ b/public/IPlayerHelpers.h @@ -41,7 +41,7 @@ #include #define SMINTERFACE_PLAYERMANAGER_NAME "IPlayerManager" -#define SMINTERFACE_PLAYERMANAGER_VERSION 20 +#define SMINTERFACE_PLAYERMANAGER_VERSION 21 struct edict_t; class IPlayerInfo; @@ -267,6 +267,15 @@ namespace SourceMod * @brief Removes admin access from the client. */ virtual void ClearAdmin() =0; + + /** + * @brief Returns the client's Steam ID as a uint64. + * + * @param validated Check backend validation status. + * + * @return Steam ID or 0 if not available. + */ + virtual uint64_t GetSteamID64(bool validated = true) =0; }; /** From e3b87a5ca4b358da7108c38fbdef1823f45fa953 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Tue, 2 Sep 2014 17:38:25 -0700 Subject: [PATCH 2/7] Spin new logic into GetClientAuthString2... and mark GetClientAuthString as deprecated, using 1.6.x GetClientAuthString behavior --- core/logic/smn_players.cpp | 44 ++++++++++++++++++++----------------- plugins/include/clients.inc | 19 ++++++++++++++-- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/core/logic/smn_players.cpp b/core/logic/smn_players.cpp index 7b27c0a1..ba42ecae 100644 --- a/core/logic/smn_players.cpp +++ b/core/logic/smn_players.cpp @@ -340,9 +340,8 @@ enum class AuthStringType SteamID64, }; -static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) +static cell_t SteamIDToLocal(IPluginContext *pCtx, int index, AuthStringType authType, cell_t local_addr, size_t bytes, bool validate) { - int index = params[1]; if ((index < 1) || (index > playerhelpers->GetMaxClients())) { return pCtx->ThrowNativeError("Client index %d is invalid", index); @@ -354,18 +353,6 @@ static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) return pCtx->ThrowNativeError("Client %d is not connected", index); } - bool validate = true; - if (params[0] >= 4) - { - validate = !!params[4]; - } - - AuthStringType authType = AuthStringType::Engine; - if (params[0] >= 5) - { - authType = (AuthStringType)params[5]; - } - switch (authType) { case AuthStringType::Engine: @@ -376,7 +363,7 @@ static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) return 0; } - pCtx->StringToLocal(params[2], static_cast(params[3]), authstr); + pCtx->StringToLocal(local_addr, bytes, authstr); } break; case AuthStringType::Steam2: @@ -384,7 +371,7 @@ static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) { if (pPlayer->IsFakeClient()) { - pCtx->StringToLocal(params[2], static_cast(params[3]), "BOT"); + pCtx->StringToLocal(local_addr, bytes, "BOT"); return 1; } @@ -393,11 +380,11 @@ static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) { if (gamehelpers->IsLANServer()) { - pCtx->StringToLocal(params[2], static_cast(params[3]), "STEAM_ID_LAN"); + pCtx->StringToLocal(local_addr, bytes, "STEAM_ID_LAN"); } else { - pCtx->StringToLocal(params[2], static_cast(params[3]), "STEAM_ID_PENDING"); + pCtx->StringToLocal(local_addr, bytes, "STEAM_ID_PENDING"); } return 1; @@ -425,7 +412,7 @@ static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) snprintf(szAuth, sizeof(szAuth), "[U:%u:%u]", universe, accountId); } - pCtx->StringToLocal(params[2], static_cast(params[3]), szAuth); + pCtx->StringToLocal(local_addr, bytes, szAuth); } break; @@ -445,7 +432,7 @@ static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) char szAuth[64]; snprintf(szAuth, sizeof(szAuth), "%" PRIu64, steamId); - pCtx->StringToLocal(params[2], static_cast(params[3]), szAuth); + pCtx->StringToLocal(local_addr, bytes, szAuth); } break; } @@ -453,6 +440,22 @@ static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) return 1; } +static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) +{ + bool validate = true; + if (params[0] >= 4) + { + validate = !!params[4]; + } + + return SteamIDToLocal(pCtx, params[1], AuthStringType::Steam2, params[2], (size_t)params[3], validate); +} + +static cell_t sm_GetClientAuthStr2(IPluginContext *pCtx, const cell_t *params) +{ + return SteamIDToLocal(pCtx, params[1], (AuthStringType)params[2], params[3], (size_t)params[4], params[5] != 0); +} + static cell_t sm_GetSteamAccountID(IPluginContext *pCtx, const cell_t *params) { int index = params[1]; @@ -1639,6 +1642,7 @@ REGISTER_NATIVES(playernatives) { "CanUserTarget", CanUserTarget }, { "ChangeClientTeam", ChangeClientTeam }, { "GetClientAuthString", sm_GetClientAuthStr }, + { "GetClientAuthString2", sm_GetClientAuthStr2 }, { "GetSteamAccountID", sm_GetSteamAccountID }, { "GetClientCount", sm_GetClientCount }, { "GetClientInfo", sm_GetClientInfo }, diff --git a/plugins/include/clients.inc b/plugins/include/clients.inc index 913d26a3..ef4aa7fa 100644 --- a/plugins/include/clients.inc +++ b/plugins/include/clients.inc @@ -277,11 +277,26 @@ native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true); * @param validate Check backend validation status. * DO NOT PASS FALSE UNLESS YOU UNDERSTAND THE CONSEQUENCES, * You WILL KNOW if you need to use this, MOST WILL NOT. - * @param authType Auth string type and format to use. * @return True on success, false otherwise. * @error If the client is not connected or the index is invalid. */ -native bool:GetClientAuthString(client, String:auth[], maxlen, bool:validate=true, AuthStringType:authType=AuthString_Engine); +#pragma deprecated Use GetClientAuthString2 +native bool:GetClientAuthString(client, String:auth[], maxlen, bool:validate=true); + +/** + * Retrieves a client's authentication string (SteamID). + * + * @param client Player index. + * @param authType Auth string type and format to use. + * @param auth Buffer to store the client's auth string. + * @param maxlen Maximum length of string buffer (includes NULL terminator). + * @param validate Check backend validation status. + * DO NOT PASS FALSE UNLESS YOU UNDERSTAND THE CONSEQUENCES, + * You WILL KNOW if you need to use this, MOST WILL NOT. + * @return True on success, false otherwise. + * @error If the client is not connected or the index is invalid. + */ +native bool:GetClientAuthString2(client, AuthStringType:authType, String:auth[], maxlen, bool:validate=true); /** * Returns the client's Steam account ID. From eafd6626ec1cb3d395e84c7974ea045dd2a52d0c Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Tue, 2 Sep 2014 17:44:11 -0700 Subject: [PATCH 3/7] Fix true return when validation wanted and steam id pending --- core/logic/smn_players.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/logic/smn_players.cpp b/core/logic/smn_players.cpp index ba42ecae..196b5539 100644 --- a/core/logic/smn_players.cpp +++ b/core/logic/smn_players.cpp @@ -381,13 +381,17 @@ static cell_t SteamIDToLocal(IPluginContext *pCtx, int index, AuthStringType aut if (gamehelpers->IsLANServer()) { pCtx->StringToLocal(local_addr, bytes, "STEAM_ID_LAN"); + return 1; } - else + else if (!validate) { pCtx->StringToLocal(local_addr, bytes, "STEAM_ID_PENDING"); + return 1; + } + else + { + return 0; } - - return 1; } char szAuth[64]; From d0c701793c3cd7279c1104c4ea8656620e9081b6 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Tue, 2 Sep 2014 17:47:33 -0700 Subject: [PATCH 4/7] Document possibly-unexpected yet valid auth strings --- plugins/include/clients.inc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/include/clients.inc b/plugins/include/clients.inc index ef4aa7fa..4de44ef9 100644 --- a/plugins/include/clients.inc +++ b/plugins/include/clients.inc @@ -47,6 +47,12 @@ enum NetFlow /** * Auth string types. + * + * Note that for the Steam2 and Steam3 types, the following ids are + * also valid values: + * "STEAM_ID_PENDING" - Authentication is pending. + * "STEAM_ID_LAN" - Authentication is disabled because of being on a LAN server. + * "BOT" - The client is a bot. */ enum AuthStringType { From e11fec9ba1cd24e1bf252ea00452af3d12590f9e Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Tue, 2 Sep 2014 18:11:36 -0700 Subject: [PATCH 5/7] Rename GetClientAuthString2 to GetClientAuthId --- core/logic/smn_players.cpp | 4 ++-- plugins/include/clients.inc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/logic/smn_players.cpp b/core/logic/smn_players.cpp index 196b5539..7a4bf35c 100644 --- a/core/logic/smn_players.cpp +++ b/core/logic/smn_players.cpp @@ -455,7 +455,7 @@ static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) return SteamIDToLocal(pCtx, params[1], AuthStringType::Steam2, params[2], (size_t)params[3], validate); } -static cell_t sm_GetClientAuthStr2(IPluginContext *pCtx, const cell_t *params) +static cell_t sm_GetClientAuthId(IPluginContext *pCtx, const cell_t *params) { return SteamIDToLocal(pCtx, params[1], (AuthStringType)params[2], params[3], (size_t)params[4], params[5] != 0); } @@ -1646,7 +1646,7 @@ REGISTER_NATIVES(playernatives) { "CanUserTarget", CanUserTarget }, { "ChangeClientTeam", ChangeClientTeam }, { "GetClientAuthString", sm_GetClientAuthStr }, - { "GetClientAuthString2", sm_GetClientAuthStr2 }, + { "GetClientAuthId", sm_GetClientAuthId }, { "GetSteamAccountID", sm_GetSteamAccountID }, { "GetClientCount", sm_GetClientCount }, { "GetClientInfo", sm_GetClientInfo }, diff --git a/plugins/include/clients.inc b/plugins/include/clients.inc index 4de44ef9..600bf3fe 100644 --- a/plugins/include/clients.inc +++ b/plugins/include/clients.inc @@ -286,7 +286,7 @@ native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true); * @return True on success, false otherwise. * @error If the client is not connected or the index is invalid. */ -#pragma deprecated Use GetClientAuthString2 +#pragma deprecated Use GetClientAuthId native bool:GetClientAuthString(client, String:auth[], maxlen, bool:validate=true); /** @@ -302,7 +302,7 @@ native bool:GetClientAuthString(client, String:auth[], maxlen, bool:validate=tru * @return True on success, false otherwise. * @error If the client is not connected or the index is invalid. */ -native bool:GetClientAuthString2(client, AuthStringType:authType, String:auth[], maxlen, bool:validate=true); +native bool:GetClientAuthId(client, AuthStringType:authType, String:auth[], maxlen, bool:validate=true); /** * Returns the client's Steam account ID. From 3fba1d2817883f53a9f12784e3be2bc0b456ab74 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Wed, 3 Sep 2014 10:50:11 -0700 Subject: [PATCH 6/7] Fix some nits --- core/logic/smn_players.cpp | 4 ++-- plugins/include/clients.inc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/logic/smn_players.cpp b/core/logic/smn_players.cpp index 7a4bf35c..e4eb7eac 100644 --- a/core/logic/smn_players.cpp +++ b/core/logic/smn_players.cpp @@ -334,7 +334,7 @@ static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params) // Must match clients.inc enum class AuthStringType { - Engine, + Engine = 0, Steam2, Steam3, SteamID64, @@ -405,7 +405,7 @@ static cell_t SteamIDToLocal(IPluginContext *pCtx, int index, AuthStringType aut universe = 0; } - snprintf(szAuth, sizeof(szAuth), "STEAM_%u:%u:%u", universe, accountId % 2, accountId >> 1); + snprintf(szAuth, sizeof(szAuth), "STEAM_%u:%u:%u", universe, accountId & 1, accountId >> 1); } else if (instance != 1) { diff --git a/plugins/include/clients.inc b/plugins/include/clients.inc index 600bf3fe..61045683 100644 --- a/plugins/include/clients.inc +++ b/plugins/include/clients.inc @@ -56,7 +56,7 @@ enum NetFlow */ enum AuthStringType { - AuthString_Engine, /**< The game-specific auth string as returned from the engine */ + AuthString_Engine = 0, /**< The game-specific auth string as returned from the engine */ // The following are only available on games that support Steam authentication. AuthString_Steam2, /**< Steam2 rendered format, ex "STEAM_1:1:4153990" */ From 7f3656215bb0cecf8d0a5830c063e2644ce29e46 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Wed, 3 Sep 2014 15:13:30 -0700 Subject: [PATCH 7/7] Consistency Fixes (ID->Id, AuthString->AuthId) --- core/PlayerManager.cpp | 18 +++++++++--------- core/PlayerManager.h | 6 +++--- core/logic/smn_players.cpp | 24 ++++++++++++------------ plugins/include/clients.inc | 16 ++++++++-------- public/IPlayerHelpers.h | 4 ++-- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 4bdecd8a..c9600edf 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -1914,7 +1914,7 @@ CPlayer::CPlayer() m_bIsSourceTV = false; m_bIsReplay = false; m_Serial.value = -1; - m_SteamID = k_steamIDNil; + 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_SteamID = k_steamIDNil; + m_SteamId = k_steamIDNil; #if SOURCE_ENGINE == SE_CSGO m_LanguageCookie = InvalidQueryCvarCookie; #endif @@ -2033,7 +2033,7 @@ const char *CPlayer::GetAuthString(bool validated) return m_AuthID.c_str(); } -const CSteamID &CPlayer::GetSteamID(bool validated) +const CSteamID &CPlayer::GetSteamId(bool validated) { if (IsFakeClient() || (validated && !IsAuthStringValidated())) { @@ -2041,9 +2041,9 @@ const CSteamID &CPlayer::GetSteamID(bool validated) return invalidId; } - if (m_SteamID.IsValid()) + if (m_SteamId.IsValid()) { - return m_SteamID; + return m_SteamId; } #if SOURCE_ENGINE < SE_ORANGEBOX @@ -2051,7 +2051,7 @@ const CSteamID &CPlayer::GetSteamID(bool validated) /* 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), + m_SteamId = CSteamID(atoi(&pAuth[8]) | (atoi(&pAuth[10]) << 1), k_unSteamUserDesktopInstance, k_EUniversePublic, k_EAccountTypeIndividual); } #else @@ -2064,17 +2064,17 @@ const CSteamID &CPlayer::GetSteamID(bool validated) if (steamId) { - m_SteamID = (*steamId); + m_SteamId = (*steamId); } #endif - return m_SteamID; + return m_SteamId; } unsigned int CPlayer::GetSteamAccountID(bool validated) { if (!IsFakeClient() && (!validated || IsAuthStringValidated())) { - const CSteamID &id = GetSteamID(); + const CSteamID &id = GetSteamId(); if (id.IsValid()) return id.GetAccountID(); } diff --git a/core/PlayerManager.h b/core/PlayerManager.h index ad98090c..cfd57cc0 100644 --- a/core/PlayerManager.h +++ b/core/PlayerManager.h @@ -73,8 +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(); } + const CSteamID &GetSteamId(bool validated = true); + uint64_t GetSteamId64(bool validated = true) { return GetSteamId(validated).ConvertToUint64(); } edict_t *GetEdict(); bool IsInGame(); bool WasCountedAsInGame(); @@ -134,7 +134,7 @@ private: bool m_bIsSourceTV; bool m_bIsReplay; serial_t m_Serial; - CSteamID m_SteamID; + CSteamID m_SteamId; #if SOURCE_ENGINE == SE_CSGO QueryCvarCookie_t m_LanguageCookie; #endif diff --git a/core/logic/smn_players.cpp b/core/logic/smn_players.cpp index e4eb7eac..34b24798 100644 --- a/core/logic/smn_players.cpp +++ b/core/logic/smn_players.cpp @@ -332,15 +332,15 @@ static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params) } // Must match clients.inc -enum class AuthStringType +enum class AuthIdType { Engine = 0, Steam2, Steam3, - SteamID64, + SteamId64, }; -static cell_t SteamIDToLocal(IPluginContext *pCtx, int index, AuthStringType authType, cell_t local_addr, size_t bytes, bool validate) +static cell_t SteamIdToLocal(IPluginContext *pCtx, int index, AuthIdType authType, cell_t local_addr, size_t bytes, bool validate) { if ((index < 1) || (index > playerhelpers->GetMaxClients())) { @@ -355,7 +355,7 @@ static cell_t SteamIDToLocal(IPluginContext *pCtx, int index, AuthStringType aut switch (authType) { - case AuthStringType::Engine: + case AuthIdType::Engine: { const char *authstr = pPlayer->GetAuthString(validate); if (!authstr || authstr[0] == '\0') @@ -366,8 +366,8 @@ static cell_t SteamIDToLocal(IPluginContext *pCtx, int index, AuthStringType aut pCtx->StringToLocal(local_addr, bytes, authstr); } break; - case AuthStringType::Steam2: - case AuthStringType::Steam3: + case AuthIdType::Steam2: + case AuthIdType::Steam3: { if (pPlayer->IsFakeClient()) { @@ -375,7 +375,7 @@ static cell_t SteamIDToLocal(IPluginContext *pCtx, int index, AuthStringType aut return 1; } - uint64_t steamId = pPlayer->GetSteamID64(validate); + uint64_t steamId = pPlayer->GetSteamId64(validate); if (steamId == 0) { if (gamehelpers->IsLANServer()) @@ -398,7 +398,7 @@ static cell_t SteamIDToLocal(IPluginContext *pCtx, int index, AuthStringType aut unsigned int universe = steamId >> 56; unsigned int accountId = steamId & 0xFFFFFFFF; unsigned int instance = (steamId >> 32) & 0x000FFFFF; - if (authType == AuthStringType::Steam2) + if (authType == AuthIdType::Steam2) { if (atoi(g_pGameConf->GetKeyValue("UseInvalidUniverseInSteam2IDs")) == 1) { @@ -420,14 +420,14 @@ static cell_t SteamIDToLocal(IPluginContext *pCtx, int index, AuthStringType aut } break; - case AuthStringType::SteamID64: + case AuthIdType::SteamId64: { if (pPlayer->IsFakeClient() || gamehelpers->IsLANServer()) { return 0; } - uint64_t steamId = pPlayer->GetSteamID64(validate); + uint64_t steamId = pPlayer->GetSteamId64(validate); if (steamId == 0) { return 0; @@ -452,12 +452,12 @@ static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) validate = !!params[4]; } - return SteamIDToLocal(pCtx, params[1], AuthStringType::Steam2, params[2], (size_t)params[3], validate); + return SteamIdToLocal(pCtx, params[1], AuthIdType::Steam2, params[2], (size_t)params[3], validate); } static cell_t sm_GetClientAuthId(IPluginContext *pCtx, const cell_t *params) { - return SteamIDToLocal(pCtx, params[1], (AuthStringType)params[2], params[3], (size_t)params[4], params[5] != 0); + return SteamIdToLocal(pCtx, params[1], (AuthIdType)params[2], params[3], (size_t)params[4], params[5] != 0); } static cell_t sm_GetSteamAccountID(IPluginContext *pCtx, const cell_t *params) diff --git a/plugins/include/clients.inc b/plugins/include/clients.inc index 61045683..b30a3040 100644 --- a/plugins/include/clients.inc +++ b/plugins/include/clients.inc @@ -54,14 +54,14 @@ enum NetFlow * "STEAM_ID_LAN" - Authentication is disabled because of being on a LAN server. * "BOT" - The client is a bot. */ -enum AuthStringType +enum AuthIdType { - AuthString_Engine = 0, /**< The game-specific auth string as returned from the engine */ + AuthId_Engine = 0, /**< The game-specific auth string as returned from the engine */ // The following are only available on games that support Steam authentication. - AuthString_Steam2, /**< Steam2 rendered format, ex "STEAM_1:1:4153990" */ - AuthString_Steam3, /**< Steam3 rendered format, ex "[U:1:8307981]" */ - AuthString_SteamID64, /**< A SteamID64 (uint64) as a String, ex "76561197968573709" */ + AuthId_Steam2, /**< Steam2 rendered format, ex "STEAM_1:1:4153990" */ + AuthId_Steam3, /**< Steam3 rendered format, ex "[U:1:8307981]" */ + AuthId_SteamID64, /**< A SteamID64 (uint64) as a String, ex "76561197968573709" */ }; /** @@ -293,8 +293,8 @@ native bool:GetClientAuthString(client, String:auth[], maxlen, bool:validate=tru * Retrieves a client's authentication string (SteamID). * * @param client Player index. - * @param authType Auth string type and format to use. - * @param auth Buffer to store the client's auth string. + * @param authType Auth id type and format to use. + * @param auth Buffer to store the client's auth id. * @param maxlen Maximum length of string buffer (includes NULL terminator). * @param validate Check backend validation status. * DO NOT PASS FALSE UNLESS YOU UNDERSTAND THE CONSEQUENCES, @@ -302,7 +302,7 @@ native bool:GetClientAuthString(client, String:auth[], maxlen, bool:validate=tru * @return True on success, false otherwise. * @error If the client is not connected or the index is invalid. */ -native bool:GetClientAuthId(client, AuthStringType:authType, String:auth[], maxlen, bool:validate=true); +native bool:GetClientAuthId(client, AuthIdType:authType, String:auth[], maxlen, bool:validate=true); /** * Returns the client's Steam account ID. diff --git a/public/IPlayerHelpers.h b/public/IPlayerHelpers.h index 72e007e4..35a174a7 100644 --- a/public/IPlayerHelpers.h +++ b/public/IPlayerHelpers.h @@ -273,9 +273,9 @@ namespace SourceMod * * @param validated Check backend validation status. * - * @return Steam ID or 0 if not available. + * @return Steam Id or 0 if not available. */ - virtual uint64_t GetSteamID64(bool validated = true) =0; + virtual uint64_t GetSteamId64(bool validated = true) =0; }; /**