add steamid-stocks.inc

This commit is contained in:
rtldg 2021-10-25 12:40:24 +00:00
parent 9571e247b5
commit b364871df5
5 changed files with 88 additions and 35 deletions

View File

@ -324,36 +324,6 @@ stock int IPStringToAddress(const char[] ip)
return iIPAddress;
}
// Retrieves authid from STEAM_X:Y:Z and [U:1:123]
stock int SteamIDToAuth(const char[] sInput)
{
char sSteamID[32];
strcopy(sSteamID, sizeof(sSteamID), sInput);
ReplaceString(sSteamID, 32, "\"", "");
if (StrContains(sSteamID, "STEAM_") != -1)
{
ReplaceString(sSteamID, 32, "STEAM_", "");
char parts[3][11];
ExplodeString(sSteamID, ":", parts, 3, 11);
// Let X, Y and Z constants be defined by the SteamID: STEAM_X:Y:Z.
// Using the formula W=Z*2+Y, a SteamID can be converted:
return StringToInt(parts[2]) * 2 + StringToInt(parts[1]);
}
else if (StrContains(sSteamID, "U:1:") != -1)
{
ReplaceString(sSteamID, 32, "[", "");
ReplaceString(sSteamID, 32, "U:1:", "");
ReplaceString(sSteamID, 32, "]", "");
return StringToInt(sSteamID);
}
return 0;
}
// time formatting!
stock void FormatSeconds(float time, char[] newtime, int newtimesize, bool precise = true, bool nodecimal = false, bool full_hms = false)
{

View File

@ -0,0 +1,79 @@
#if defined _steamid_stocks_included
#endinput
#endif
#define _steamid_stocks_included
static KeyValues kv = null;
// Retrieves accountid from STEAM_X:Y:Z, [U:1:123], and 765xxxxxxxxxxxxxx
stock int SteamIDToAccountID(const char[] sInput)
{
char sSteamID[32];
strcopy(sSteamID, sizeof(sSteamID), sInput);
ReplaceString(sSteamID, 32, "\"", "");
TrimString(sSteamID);
if (StrContains(sSteamID, "STEAM_") != -1)
{
ReplaceString(sSteamID, 32, "STEAM_", "");
char parts[3][11];
ExplodeString(sSteamID, ":", parts, 3, 11);
// Let X, Y and Z constants be defined by the SteamID: STEAM_X:Y:Z.
// Using the formula W=Z*2+Y, a SteamID can be converted:
return StringToInt(parts[2]) * 2 + StringToInt(parts[1]);
}
else if (StrContains(sSteamID, "U:1:") != -1)
{
ReplaceString(sSteamID, 32, "[", "");
ReplaceString(sSteamID, 32, "U:1:", "");
ReplaceString(sSteamID, 32, "]", "");
return StringToInt(sSteamID);
}
else if (StrContains(sSteamID, "765") == 0)
{
return SteamID64ToAccountID(sSteamID);
}
return 0;
}
stock void AccountIDToSteamID64(int accountid, int num[2])
{
num[0] = accountid;
// universe | type | instance
num[1] = (1 << 24) | (1 << 20) | 1; // 0x01100001
}
stock void AccountIDToSteamID2(int accountid, char[] buf, int buflen)
{
FormatEx(buf, buflen, "STEAM_0:%d:%d", accountid&1, (accountid>>1) & 0x7FFFFFFF);
}
stock void AccountIDToSteamID3(int accountid, char[] buf, int buflen)
{
FormatEx(buf, buflen, "[U:1:%d]", accountid);
}
stock void SteamID64ToString(int num[2], char[] buf, int buflen)
{
if (kv == null)
kv = new KeyValues("fuck sourcemod");
kv.SetUInt64(NULL_STRING, num);
kv.GetString(NULL_STRING, buf, buflen);
}
stock int SteamID64ToAccountID(const char[] steamid64)
{
if (kv == null)
kv = new KeyValues("fuck sourcemod");
int num[2];
kv.SetString(NULL_STRING, steamid64);
kv.GetUInt64(NULL_STRING, num);
return num[0]; // & 0x7FFFFFFF;
}

View File

@ -28,6 +28,7 @@
#include <shavit>
#include <shavit/chat>
#include <shavit/chat-colors>
#include <shavit/steamid-stocks>
#undef REQUIRE_PLUGIN
#include <shavit/rankings>
@ -1286,7 +1287,7 @@ public Action Command_CCAdd(int client, int args)
char sArgString[32];
GetCmdArgString(sArgString, 32);
int iSteamID = SteamIDToAuth(sArgString);
int iSteamID = SteamIDToAccountID(sArgString);
if (iSteamID < 1)
{
@ -1322,7 +1323,7 @@ public Action Command_CCDelete(int client, int args)
char sArgString[32];
GetCmdArgString(sArgString, 32);
int iSteamID = SteamIDToAuth(sArgString);
int iSteamID = SteamIDToAccountID(sArgString);
if (iSteamID < 1)
{

View File

@ -40,6 +40,7 @@
#include <shavit/chat-colors>
#include <shavit/anti-sv_cheats.sp>
#include <shavit/steamid-stocks>
#include <shavit/style-settings.sp>
#include <shavit/sql-create-tables-and-migrations.sp>
#include <shavit/physicsuntouch>
@ -935,7 +936,7 @@ public Action Command_WipePlayer(int client, int args)
if(strlen(gS_Verification[client]) == 0 || !StrEqual(sArgString, gS_Verification[client]))
{
gI_WipePlayerID[client] = SteamIDToAuth(sArgString);
gI_WipePlayerID[client] = SteamIDToAccountID(sArgString);
if(gI_WipePlayerID[client] <= 0)
{

View File

@ -29,6 +29,8 @@
#undef REQUIRE_PLUGIN
#include <shavit/rankings>
#include <shavit/steamid-stocks>
#undef REQUIRE_EXTENSIONS
#include <cstrike>
@ -539,7 +541,7 @@ public Action Command_MapsDoneLeft(int client, int args)
char sArgs[64];
GetCmdArgString(sArgs, 64);
iSteamID = SteamIDToAuth(sArgs);
iSteamID = SteamIDToAccountID(sArgs);
if (iSteamID < 1)
{
@ -670,7 +672,7 @@ public Action Command_Profile(int client, int args)
char sArgs[64];
GetCmdArgString(sArgs, 64);
iSteamID = SteamIDToAuth(sArgs);
iSteamID = SteamIDToAccountID(sArgs);
if (iSteamID < 1)
{