Allow BindIdentity and FindAdminByIdentity to take more SteamID formats for steam auth type
This commit is contained in:
parent
ec46e12c50
commit
892edd9650
@ -218,6 +218,8 @@ class SMConfig(object):
|
||||
'_CRT_NONSTDC_NO_DEPRECATE',
|
||||
'_ITERATOR_DEBUG_LEVEL=0',
|
||||
]
|
||||
if cxx.version < 1800:
|
||||
cxx.defines += 'strtoull=_strtoui64'
|
||||
cxx.cflags += [
|
||||
'/W3',
|
||||
]
|
||||
|
@ -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;
|
||||
|
||||
|
@ -356,7 +356,7 @@ native GetAdminUsername(AdminId:id, String:name[], maxlength);
|
||||
* @param auth Auth method to use, predefined or from RegisterAuthIdentType().
|
||||
* @param ident String containing the arbitrary, unique identity.
|
||||
* @return True on success, false if the auth method was not found,
|
||||
* or ident was already taken.
|
||||
* ident was already taken, or ident invalid for auth method.
|
||||
*/
|
||||
native bool:BindAdminIdentity(AdminId:id, const String:auth[], const String:ident[]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user