MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / GetUnifiedSteamIdentity

Method GetUnifiedSteamIdentity

core/logic/AdminCache.cpp:1081–1134  ·  view source on GitHub ↗

* Converts Steam2 id, Steam3 id, or SteamId64 to unified, legacy * admin identity format. (account id part of Steam2 format) */

Source from the content-addressed store, hash-verified

1079 * admin identity format. (account id part of Steam2 format)
1080 */
1081bool AdminCache::GetUnifiedSteamIdentity(const char *ident, char *out, size_t maxlen)
1082{
1083 int len = strlen(ident);
1084 if (!strcmp(ident, "BOT"))
1085 {
1086 // Bots
1087 strncopy(out, ident, maxlen);
1088 return true;
1089 }
1090 else if (len >= 11 && !strncmp(ident, "STEAM_", 6) && ident[8] != '_')
1091 {
1092 // non-bot/lan Steam2 Id, strip off the STEAM_* part
1093 ke::SafeStrcpy(out, maxlen, &ident[8]);
1094 return true;
1095 }
1096 else if (len >= 7 && !strncmp(ident, "[U:", 3) && ident[len-1] == ']')
1097 {
1098 // Steam3 Id, replicate the Steam2 Post-"STEAM_" part
1099 uint32_t accountId = strtoul(&ident[5], nullptr, 10);
1100 ke::SafeSprintf(out, maxlen, "%u:%u", accountId & 1, accountId >> 1);
1101 return true;
1102 }
1103 else
1104 {
1105 // 64-bit CSteamID, replicate the Steam2 Post-"STEAM_" part
1106
1107 // some constants from steamclientpublic.h
1108 static const uint32_t k_EAccountTypeIndividual = 1;
1109 static const int k_EUniverseInvalid = 0;
1110 static const int k_EUniverseMax = 5;
1111 static const unsigned int k_unSteamUserWebInstance = 4;
1112
1113 uint64_t steamId = strtoull(ident, nullptr, 10);
1114 if (steamId > 0)
1115 {
1116 // Make some attempt at being sure it's a valid id rather than other number,
1117 // even though we're only going to use the lower 32 bits.
1118 uint32_t accountId = steamId & 0xFFFFFFFF;
1119 uint32_t accountType = (steamId >> 52) & 0xF;
1120 int universe = steamId >> 56;
1121 uint32_t accountInstance = (steamId >> 32) & 0xFFFFF;
1122 if (accountId > 0
1123 && universe > k_EUniverseInvalid && universe < k_EUniverseMax
1124 && accountType == k_EAccountTypeIndividual && accountInstance <= k_unSteamUserWebInstance
1125 )
1126 {
1127 ke::SafeSprintf(out, maxlen, "%u:%u", accountId & 1, accountId >> 1);
1128 return true;
1129 }
1130 }
1131 }
1132
1133 return false;
1134}
1135
1136bool AdminCache::BindAdminIdentity(AdminId id, const char *auth, const char *ident)
1137{

Callers

nothing calls this directly

Calls 1

strncopyFunction · 0.70

Tested by

no test coverage detected