Merge pull request #153 from alliedmodders/auth-fixups
More auth fixups for Steam auth (bug 6243, r=asherkin).
This commit is contained in:
@@ -1056,6 +1056,58 @@ bool AdminCache::GetMethodIndex(const char *name, unsigned int *_index)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts Steam2 id, Steam3 id, or SteamId64 to unified, legacy
|
||||
* admin identity format. (account id part of Steam2 format)
|
||||
*/
|
||||
bool AdminCache::GetUnifiedSteamIdentity(const char *ident, char *out, size_t maxlen)
|
||||
{
|
||||
int len = strlen(ident);
|
||||
/* If the id was a steam id strip off the STEAM_*: part */
|
||||
if (len >= 11 && !strncmp(ident, "STEAM_", 6) && ident[8] != '_')
|
||||
{
|
||||
// non-bot/lan Steam2 Id
|
||||
snprintf(out, maxlen, "%s", ident[8]);
|
||||
return true;
|
||||
}
|
||||
else if (len >= 7 && !strncmp(ident, "[U:", 3) && ident[len-1] == ']')
|
||||
{
|
||||
// Steam3 Id
|
||||
uint32_t accountId = strtoul(&ident[5], nullptr, 10);
|
||||
snprintf(out, maxlen, "%u:%u", accountId & 1, accountId >> 1);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// some constants from steamclientpublic.h
|
||||
static const uint32_t k_EAccountTypeIndividual = 1;
|
||||
static const int k_EUniverseInvalid = 0;
|
||||
static const int k_EUniverseMax = 5;
|
||||
static const unsigned int k_unSteamUserWebInstance = 4;
|
||||
|
||||
uint64_t steamId = strtoull(ident, nullptr, 10);
|
||||
if (steamId > 0)
|
||||
{
|
||||
// Make some attempt at being sure it's a valid id rather than other number,
|
||||
// even though we're only going to use the lower 32 bits.
|
||||
uint32_t accountId = steamId & 0xFFFFFFFF;
|
||||
uint32_t accountType = (steamId >> 52) & 0xF;
|
||||
int universe = steamId >> 56;
|
||||
uint32_t accountInstance = (steamId >> 32) & 0xFFFFF;
|
||||
if (accountId > 0
|
||||
&& universe > k_EUniverseInvalid && universe < k_EUniverseMax
|
||||
&& accountType == k_EAccountTypeIndividual && accountInstance <= k_unSteamUserWebInstance
|
||||
)
|
||||
{
|
||||
snprintf(out, maxlen, "%u:%u", accountId & 1, accountId >> 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AdminCache::BindAdminIdentity(AdminId id, const char *auth, const char *ident)
|
||||
{
|
||||
if (ident[0] == '\0')
|
||||
@@ -1073,10 +1125,14 @@ bool AdminCache::BindAdminIdentity(AdminId id, const char *auth, const char *ide
|
||||
if (!m_AuthTables.retrieve(auth, &method))
|
||||
return false;
|
||||
|
||||
/* If the id was a steam id strip off the STEAM_*: part */
|
||||
if (strcmp(auth, "steam") == 0 && strncmp(ident, "STEAM_", 6) == 0)
|
||||
/* If the auth type is steam, the id could be in a number of formats. Unify it. */
|
||||
char steamIdent[16];
|
||||
if (strcmp(auth, "steam") == 0)
|
||||
{
|
||||
ident += 8;
|
||||
if (!GetUnifiedSteamIdentity(ident, steamIdent, sizeof(steamIdent)))
|
||||
return false;
|
||||
|
||||
ident = steamIdent;
|
||||
}
|
||||
|
||||
if (method->identities.contains(ident))
|
||||
@@ -1097,10 +1153,14 @@ AdminId AdminCache::FindAdminByIdentity(const char *auth, const char *identity)
|
||||
if (!m_AuthTables.retrieve(auth, &method))
|
||||
return INVALID_ADMIN_ID;
|
||||
|
||||
/* If the id was a steam id strip off the STEAM_*: part */
|
||||
if (strcmp(auth, "steam") == 0 && strncmp(identity, "STEAM_", 6) == 0)
|
||||
/* If the auth type is steam, the id could be in a number of formats. Unify it. */
|
||||
char steamIdent[16];
|
||||
if (strcmp(auth, "steam") == 0)
|
||||
{
|
||||
identity += 8;
|
||||
if (!GetUnifiedSteamIdentity(identity, steamIdent, sizeof(steamIdent)))
|
||||
return INVALID_ADMIN_ID;
|
||||
|
||||
identity = steamIdent;
|
||||
}
|
||||
|
||||
AdminId id;
|
||||
|
||||
@@ -198,6 +198,7 @@ private:
|
||||
bool GetMethodIndex(const char *name, unsigned int *_index);
|
||||
const char *GetMethodName(unsigned int index);
|
||||
void NameFlag(const char *str, AdminFlag flag);
|
||||
bool GetUnifiedSteamIdentity(const char *ident, char *out, size_t maxlen);
|
||||
public:
|
||||
typedef StringHashMap<FlagBits> FlagMap;
|
||||
|
||||
|
||||
+22
-57
@@ -352,72 +352,37 @@ static cell_t SteamIdToLocal(IPluginContext *pCtx, int index, AuthIdType authTyp
|
||||
{
|
||||
return pCtx->ThrowNativeError("Client %d is not connected", index);
|
||||
}
|
||||
|
||||
|
||||
const char *authstr;
|
||||
|
||||
switch (authType)
|
||||
{
|
||||
case AuthIdType::Engine:
|
||||
authstr = pPlayer->GetAuthString(validate);
|
||||
if (!authstr || authstr[0] == '\0')
|
||||
{
|
||||
const char *authstr = pPlayer->GetAuthString(validate);
|
||||
if (!authstr || authstr[0] == '\0')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pCtx->StringToLocal(local_addr, bytes, authstr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pCtx->StringToLocal(local_addr, bytes, authstr);
|
||||
break;
|
||||
case AuthIdType::Steam2:
|
||||
case AuthIdType::Steam3:
|
||||
authstr = pPlayer->GetSteam2Id(validate);
|
||||
if (!authstr || authstr[0] == '\0')
|
||||
{
|
||||
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
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
char szAuth[64];
|
||||
unsigned int universe = steamId >> 56;
|
||||
unsigned int accountId = steamId & 0xFFFFFFFF;
|
||||
unsigned int instance = (steamId >> 32) & 0x000FFFFF;
|
||||
if (authType == AuthIdType::Steam2)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
pCtx->StringToLocal(local_addr, bytes, szAuth);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pCtx->StringToLocal(local_addr, bytes, authstr);
|
||||
break;
|
||||
case AuthIdType::Steam3:
|
||||
authstr = pPlayer->GetSteam3Id(validate);
|
||||
if (!authstr || authstr[0] == '\0')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pCtx->StringToLocal(local_addr, bytes, authstr);
|
||||
break;
|
||||
|
||||
case AuthIdType::SteamId64:
|
||||
|
||||
Reference in New Issue
Block a user