diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index 8992ad24..3a90bfc6 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -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) { diff --git a/addons/sourcemod/scripting/include/shavit/steamid-stocks.inc b/addons/sourcemod/scripting/include/shavit/steamid-stocks.inc new file mode 100644 index 00000000..6d38c61c --- /dev/null +++ b/addons/sourcemod/scripting/include/shavit/steamid-stocks.inc @@ -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; +} diff --git a/addons/sourcemod/scripting/shavit-chat.sp b/addons/sourcemod/scripting/shavit-chat.sp index 01cd5fc2..f0ec740f 100644 --- a/addons/sourcemod/scripting/shavit-chat.sp +++ b/addons/sourcemod/scripting/shavit-chat.sp @@ -28,6 +28,7 @@ #include #include #include +#include #undef REQUIRE_PLUGIN #include @@ -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) { diff --git a/addons/sourcemod/scripting/shavit-core.sp b/addons/sourcemod/scripting/shavit-core.sp index c0871e22..c20863e9 100644 --- a/addons/sourcemod/scripting/shavit-core.sp +++ b/addons/sourcemod/scripting/shavit-core.sp @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -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) { diff --git a/addons/sourcemod/scripting/shavit-stats.sp b/addons/sourcemod/scripting/shavit-stats.sp index 512cd052..f3a99aa3 100644 --- a/addons/sourcemod/scripting/shavit-stats.sp +++ b/addons/sourcemod/scripting/shavit-stats.sp @@ -29,6 +29,8 @@ #undef REQUIRE_PLUGIN #include +#include + #undef REQUIRE_EXTENSIONS #include @@ -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) {