sourcemod 1.13 upgrade. moved all plugins from steamworks to ripext. added smjanson and asyncsocket.inc an extra time so its easier to find. updated plugins that would not compile with 1.13
This commit is contained in:
@@ -2,9 +2,8 @@
|
||||
|
||||
#include <basecomm>
|
||||
#include <sourcemod>
|
||||
#include <SteamWorks>
|
||||
#include <ripext>
|
||||
#include <regex>
|
||||
#include <smjansson>
|
||||
#include <multicolors>
|
||||
#include <sdktools>
|
||||
#include <AFKManager>
|
||||
@@ -139,6 +138,9 @@ public void OnAdminAFKTimeChanged(ConVar convar, const char[] oldValue, const ch
|
||||
g_iAdminAFKTime = g_cvAdminAFKTime.IntValue;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: Steam player summary lookup (avatar) - now via ripext, JSON instead of VDF
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnClientAuthorized(int client, const char[] sAuthID32)
|
||||
{
|
||||
if (IsFakeClient(client))
|
||||
@@ -149,19 +151,44 @@ public void OnClientAuthorized(int client, const char[] sAuthID32)
|
||||
if (!Steam32IDtoSteam64ID(sAuthID32, sAuthID64, sizeof(sAuthID64)))
|
||||
return;
|
||||
|
||||
static char sRequest[256];
|
||||
char sRequest[256];
|
||||
|
||||
FormatEx(sRequest, sizeof(sRequest), "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s&format=vdf", STEAM_API_KEY, sAuthID64);
|
||||
FormatEx(sRequest, sizeof(sRequest), "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s&format=json", STEAM_API_KEY, sAuthID64);
|
||||
|
||||
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, sRequest);
|
||||
HTTPRequest req = new HTTPRequest(sRequest);
|
||||
req.Get(OnTransferComplete, GetClientSerial(client));
|
||||
}
|
||||
|
||||
if (!hRequest ||
|
||||
!SteamWorks_SetHTTPRequestContextValue(hRequest, client) ||
|
||||
!SteamWorks_SetHTTPCallbacks(hRequest, OnTransferComplete) ||
|
||||
!SteamWorks_SendHTTPRequest(hRequest))
|
||||
public void OnTransferComplete(HTTPResponse response, any serial)
|
||||
{
|
||||
int client = GetClientFromSerial(serial);
|
||||
if (!client) //Player disconnected.
|
||||
return;
|
||||
|
||||
if (response.Status != HTTPStatus_OK || response.Data == null)
|
||||
return;
|
||||
|
||||
APIWebResponse(view_as<JSONObject>(response.Data), client);
|
||||
}
|
||||
|
||||
public void APIWebResponse(JSONObject root, int client)
|
||||
{
|
||||
if (!root.HasKey("players"))
|
||||
return;
|
||||
|
||||
JSONArray players = view_as<JSONArray>(root.Get("players"));
|
||||
|
||||
if (players == null || !players.Length)
|
||||
{
|
||||
delete hRequest;
|
||||
delete players;
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject player = view_as<JSONObject>(players.Get(0));
|
||||
player.GetString("avatarfull", g_sAvatarURL[client], sizeof(g_sAvatarURL[]));
|
||||
|
||||
delete player;
|
||||
delete players;
|
||||
}
|
||||
|
||||
public Action Command_PrintToAdminChat(int args)
|
||||
@@ -197,6 +224,9 @@ public Action Command_PrintToAllChat(int args)
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: Drains the rate-limit queue - now via ripext
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action Timer_DataProcessor(Handle hThis)
|
||||
{
|
||||
if (!g_bProcessingData)
|
||||
@@ -205,8 +235,6 @@ public Action Timer_DataProcessor(Handle hThis)
|
||||
if (g_iRatelimitRemaining == 0 && GetTime() < g_iRatelimitReset)
|
||||
return Plugin_Handled;
|
||||
|
||||
//PrintToServer("[Timer_DataProcessor] Array Length #1: %d", g_arrQueuedMessages.Length);
|
||||
|
||||
char sContent[1024];
|
||||
g_arrQueuedMessages.GetString(0, sContent, sizeof(sContent));
|
||||
g_arrQueuedMessages.Erase(0);
|
||||
@@ -218,28 +246,13 @@ public Action Timer_DataProcessor(Handle hThis)
|
||||
if (g_arrQueuedMessages.Length == 0)
|
||||
g_bProcessingData = false;
|
||||
|
||||
//PrintToServer("[Timer_DataProcessor] Array Length #2: %d", g_arrQueuedMessages.Length);
|
||||
JSONObject data = JSONObject.FromString(sContent);
|
||||
|
||||
//PrintToServer("%s | %s", sURL, sContent);
|
||||
HTTPRequest req = new HTTPRequest(sURL);
|
||||
req.Post(data, OnHTTPRequestCompleted);
|
||||
|
||||
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST, sURL);
|
||||
delete data;
|
||||
|
||||
JSONObject RequestJSON = view_as<JSONObject>(json_load(sContent));
|
||||
|
||||
if (!hRequest ||
|
||||
!SteamWorks_SetHTTPRequestContextValue(hRequest, RequestJSON) ||
|
||||
!SteamWorks_SetHTTPCallbacks(hRequest, OnHTTPRequestCompleted) ||
|
||||
!SteamWorks_SetHTTPRequestRawPostBody(hRequest, "application/json", sContent, strlen(sContent)) ||
|
||||
!SteamWorks_SetHTTPRequestNetworkActivityTimeout(hRequest, 10) ||
|
||||
!SteamWorks_SendHTTPRequest(hRequest))
|
||||
{
|
||||
LogError("Discord SteamWorks_CreateHTTPRequest failed.");
|
||||
|
||||
delete RequestJSON;
|
||||
delete hRequest;
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
@@ -300,27 +313,11 @@ stock void Discord_MakeStringSafe(const char[] sOrigin, char[] sOut, int iOutSiz
|
||||
{
|
||||
if (sOrigin[i] < 0x20 && sOrigin[i] != 0x0)
|
||||
{
|
||||
//sOut[iCurIndex] = 0x20;
|
||||
//iCurIndex++;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (sOrigin[i])
|
||||
{
|
||||
// case '"':
|
||||
// {
|
||||
// strcopy(sOut[iCurIndex], iOutSize, "\\u0022");
|
||||
// iCurIndex += 6;
|
||||
|
||||
// continue;
|
||||
// }
|
||||
// case '\\':
|
||||
// {
|
||||
// strcopy(sOut[iCurIndex], iOutSize, "\\u005C");
|
||||
// iCurIndex += 6;
|
||||
|
||||
// continue;
|
||||
// }
|
||||
case '@':
|
||||
{
|
||||
strcopy(sOut[iCurIndex], iOutSize, "@"); //@ + zero-width space
|
||||
@@ -358,102 +355,12 @@ stock void Discord_MakeStringSafe(const char[] sOrigin, char[] sOut, int iOutSiz
|
||||
}
|
||||
}
|
||||
|
||||
stock int OnTransferComplete(Handle hRequest, bool bFailure, bool bRequestSuccessful, EHTTPStatusCode eStatusCode, int client)
|
||||
{
|
||||
if (bFailure || !bRequestSuccessful || eStatusCode != k_EHTTPStatusCode200OK)
|
||||
{
|
||||
if (eStatusCode != k_EHTTPStatusCode429TooManyRequests)
|
||||
{
|
||||
LogError("SteamAPI HTTP Response failed: %d", eStatusCode);
|
||||
}
|
||||
|
||||
delete hRequest;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iBodyLength;
|
||||
SteamWorks_GetHTTPResponseBodySize(hRequest, iBodyLength);
|
||||
|
||||
char[] sData = new char[iBodyLength];
|
||||
SteamWorks_GetHTTPResponseBodyData(hRequest, sData, iBodyLength);
|
||||
|
||||
delete hRequest;
|
||||
|
||||
APIWebResponse(sData, client);
|
||||
return 0;
|
||||
}
|
||||
|
||||
stock void APIWebResponse(const char[] sData, int client)
|
||||
{
|
||||
KeyValues kvResponse = new KeyValues("SteamAPIResponse");
|
||||
|
||||
if (!kvResponse.ImportFromString(sData, "SteamAPIResponse"))
|
||||
{
|
||||
//LogError("kvResponse.ImportFromString(\"SteamAPIResponse\") in APIWebResponse failed.");
|
||||
|
||||
delete kvResponse;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!kvResponse.JumpToKey("players"))
|
||||
{
|
||||
//LogError("kvResponse.JumpToKey(\"players\") in APIWebResponse failed.");
|
||||
|
||||
delete kvResponse;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!kvResponse.GotoFirstSubKey())
|
||||
{
|
||||
//LogError("kvResponse.GotoFirstSubKey() in APIWebResponse failed.");
|
||||
|
||||
delete kvResponse;
|
||||
return;
|
||||
}
|
||||
|
||||
kvResponse.GetString("avatarfull", g_sAvatarURL[client], sizeof(g_sAvatarURL[]));
|
||||
|
||||
delete kvResponse;
|
||||
}
|
||||
|
||||
stock void HTTPPostJSON(const char[] sURL, const char[] sText)
|
||||
{
|
||||
// if (g_iRatelimitRemaining > 0 && !g_bProcessingData && GetTime() < g_iRatelimitReset)
|
||||
// {
|
||||
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST, sURL);
|
||||
|
||||
JSONObject RequestJSON = view_as<JSONObject>(json_load(sText));
|
||||
|
||||
if (!hRequest ||
|
||||
!SteamWorks_SetHTTPRequestContextValue(hRequest, RequestJSON) ||
|
||||
!SteamWorks_SetHTTPCallbacks(hRequest, OnHTTPRequestCompleted) ||
|
||||
!SteamWorks_SetHTTPRequestRawPostBody(hRequest, "application/json", sText, strlen(sText)) ||
|
||||
!SteamWorks_SetHTTPRequestNetworkActivityTimeout(hRequest, 15) ||
|
||||
!SteamWorks_SendHTTPRequest(hRequest))
|
||||
{
|
||||
LogError("Discord SteamWorks_CreateHTTPRequest failed.");
|
||||
|
||||
delete RequestJSON;
|
||||
delete hRequest;
|
||||
|
||||
return;
|
||||
}
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// g_arrQueuedMessages.PushString(sText);
|
||||
// g_arrQueuedMessages.PushString(sURL);
|
||||
// g_bProcessingData = true;
|
||||
// }
|
||||
|
||||
//delete hRequest;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: Webhook POST helper - now via ripext
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
stock void Discord_POST(const char[] sURL, char[] sText, bool bUsingUsername=false, char[] sUsername=NULL_STRING, bool bUsingAvatar=false, char[] sAvatarURL=NULL_STRING, bool bSafe=true, bool bTimestamp=true)
|
||||
{
|
||||
//PrintToServer("[Discord_POST] Called with text: %s", sText);
|
||||
|
||||
JSONRootNode hJSONRoot = new JSONObject();
|
||||
JSONObject hJSONRoot = new JSONObject();
|
||||
|
||||
char sSafeText[4096];
|
||||
char sFinal[4096];
|
||||
@@ -463,13 +370,13 @@ stock void Discord_POST(const char[] sURL, char[] sText, bool bUsingUsername=fal
|
||||
TrimString(sUsername);
|
||||
|
||||
if (g_Regex_Clyde.Match(sUsername) > 0 || strlen(sUsername) < 2)
|
||||
(view_as<JSONObject>(hJSONRoot)).SetString("username", "Invalid Name");
|
||||
hJSONRoot.SetString("username", "Invalid Name");
|
||||
else
|
||||
(view_as<JSONObject>(hJSONRoot)).SetString("username", sUsername);
|
||||
hJSONRoot.SetString("username", sUsername);
|
||||
}
|
||||
|
||||
if (bUsingAvatar)
|
||||
(view_as<JSONObject>(hJSONRoot)).SetString("avatar_url", sAvatarURL);
|
||||
hJSONRoot.SetString("avatar_url", sAvatarURL);
|
||||
|
||||
if (bSafe)
|
||||
{
|
||||
@@ -488,85 +395,61 @@ stock void Discord_POST(const char[] sURL, char[] sText, bool bUsingUsername=fal
|
||||
Format(sSafeText, sizeof(sSafeText), "[ *%s* ] %s", sTime, sText);
|
||||
}
|
||||
|
||||
(view_as<JSONObject>(hJSONRoot)).SetString("content", sSafeText);
|
||||
(view_as<JSONObject>(hJSONRoot)).ToString(sFinal, sizeof(sFinal), 0);
|
||||
|
||||
//hJSONRoot.DumpToServer();
|
||||
|
||||
delete hJSONRoot;
|
||||
hJSONRoot.SetString("content", sSafeText);
|
||||
|
||||
if ((g_iRatelimitRemaining > 0 || GetTime() >= g_iRatelimitReset) && !g_bProcessingData)
|
||||
{
|
||||
//PrintToServer("[Discord_POST] Have allowances and not processing data");
|
||||
HTTPRequest req = new HTTPRequest(sURL);
|
||||
req.Post(hJSONRoot, OnHTTPRequestCompleted);
|
||||
|
||||
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST, sURL);
|
||||
|
||||
JSONObject RequestJSON = view_as<JSONObject>(json_load(sFinal));
|
||||
|
||||
if (!hRequest ||
|
||||
!SteamWorks_SetHTTPRequestContextValue(hRequest, RequestJSON) ||
|
||||
!SteamWorks_SetHTTPCallbacks(hRequest, OnHTTPRequestCompleted) ||
|
||||
!SteamWorks_SetHTTPRequestRawPostBody(hRequest, "application/json", sFinal, strlen(sFinal)) ||
|
||||
!SteamWorks_SetHTTPRequestNetworkActivityTimeout(hRequest, 10) ||
|
||||
!SteamWorks_SendHTTPRequest(hRequest))
|
||||
{
|
||||
LogError("Discord SteamWorks_CreateHTTPRequest failed.");
|
||||
|
||||
delete RequestJSON;
|
||||
delete hRequest;
|
||||
|
||||
return;
|
||||
}
|
||||
delete hJSONRoot;
|
||||
}
|
||||
else
|
||||
{
|
||||
//PrintToServer("[Discord_POST] Have allowances? [%s] | Is processing data? [%s]", g_iRatelimitRemaining > 0 ? "YES":"NO", g_bProcessingData?"YES":"NO");
|
||||
hJSONRoot.ToString(sFinal, sizeof(sFinal), 0);
|
||||
delete hJSONRoot;
|
||||
|
||||
g_arrQueuedMessages.PushString(sFinal);
|
||||
g_arrQueuedMessages.PushString(sURL);
|
||||
g_bProcessingData = true;
|
||||
}
|
||||
|
||||
//delete hRequest; //nonono
|
||||
}
|
||||
|
||||
public int OnHTTPRequestCompleted(Handle hRequest, bool bFailure, bool bRequestSuccessful, EHTTPStatusCode eStatusCode, JSONObject RequestJSON)
|
||||
public void OnHTTPRequestCompleted(HTTPResponse response, any value)
|
||||
{
|
||||
if (bFailure || !bRequestSuccessful || (eStatusCode != k_EHTTPStatusCode200OK && eStatusCode != k_EHTTPStatusCode204NoContent))
|
||||
if (response.Status != HTTPStatus_OK && response.Status != HTTPStatus_NoContent)
|
||||
{
|
||||
if (eStatusCode != k_EHTTPStatusCode429TooManyRequests)
|
||||
LogError("Discord HTTP request failed: %d", eStatusCode);
|
||||
if (response.Status != HTTPStatus_TooManyRequests)
|
||||
LogError("Discord HTTP request failed: %d", response.Status);
|
||||
|
||||
if (eStatusCode == k_EHTTPStatusCode400BadRequest)
|
||||
if (response.Status == HTTPStatus_BadRequest && response.Data != null)
|
||||
{
|
||||
char sData[2048];
|
||||
|
||||
(view_as<JSONRootNode>(RequestJSON)).ToString(sData, sizeof(sData), 0);
|
||||
response.Data.ToString(sData, sizeof(sData), 0);
|
||||
|
||||
LogError("Malformed request? Dumping request data:\n%s", sData);
|
||||
}
|
||||
else if (eStatusCode == k_EHTTPStatusCode429TooManyRequests)
|
||||
else if (response.Status == HTTPStatus_TooManyRequests)
|
||||
{
|
||||
g_iRatelimitRemaining = 0;
|
||||
g_iRatelimitReset = GetTime() + 5;
|
||||
}
|
||||
|
||||
delete RequestJSON;
|
||||
delete hRequest;
|
||||
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
static int iLastRatelimitRemaining = 0;
|
||||
static int iLastRatelimitReset = 0;
|
||||
char sTmp[32];
|
||||
bool bHeaderExists = SteamWorks_GetHTTPResponseHeaderValue(hRequest, "x-ratelimit-remaining", sTmp, sizeof(sTmp));
|
||||
bool bHeaderExists = response.GetHeader("x-ratelimit-remaining", sTmp, sizeof(sTmp));
|
||||
|
||||
if (!bHeaderExists)
|
||||
LogError("x-ratelimit-remaining header value could not be retrieved");
|
||||
|
||||
int iRatelimitRemaining = StringToInt(sTmp);
|
||||
|
||||
bHeaderExists = SteamWorks_GetHTTPResponseHeaderValue(hRequest, "x-ratelimit-reset", sTmp, sizeof(sTmp));
|
||||
bHeaderExists = response.GetHeader("x-ratelimit-reset", sTmp, sizeof(sTmp));
|
||||
|
||||
if (!bHeaderExists)
|
||||
LogError("x-ratelimit-reset header value could not be retrieved");
|
||||
@@ -578,12 +461,6 @@ public int OnHTTPRequestCompleted(Handle hRequest, bool bFailure, bool bRequestS
|
||||
g_iRatelimitRemaining = iRatelimitRemaining;
|
||||
g_iRatelimitReset = iRatelimitReset;
|
||||
}
|
||||
|
||||
//PrintToServer("limit: %d | remaining: %d || reset %d - now %d", g_iRatelimitLimit, g_iRatelimitRemaining, g_iRatelimitReset, GetTime());
|
||||
|
||||
delete RequestJSON;
|
||||
delete hRequest;
|
||||
return 0;
|
||||
}
|
||||
|
||||
stock bool IsValidClient(int client)
|
||||
@@ -815,29 +692,7 @@ public void CallAdmin_OnReportHandled(int client, int id)
|
||||
Call_PushCell(5);
|
||||
Call_Finish();
|
||||
}
|
||||
//
|
||||
/*
|
||||
public Action Oryx_OnTrigger(int client, int &level, char[] cheat)
|
||||
{
|
||||
char sUsername[MAX_NAME_LENGTH];
|
||||
GetClientName(client, sUsername, sizeof(sUsername));
|
||||
|
||||
char currentMap[64];
|
||||
GetCurrentMap(currentMap, sizeof(currentMap));
|
||||
|
||||
char sAuthID[32];
|
||||
GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);
|
||||
char sMessage[1900];
|
||||
Format(sMessage, sizeof(sMessage), "```%s - Tick: %d``````NAME: %N\nSTEAMID: %s\nTRIGGER LEVEL: %i\n%s```", currentMap, GetGameTickCount(), client, sAuthID, level, cheat);
|
||||
|
||||
if (g_sAvatarURL[client][0] != '\0')
|
||||
Discord_POST(DISCORD_ANTIBHOPCHEAT_WEBHOOKURL, sMessage, true, sUsername, true, g_sAvatarURL[client], false);
|
||||
else
|
||||
Discord_POST(DISCORD_ANTIBHOPCHEAT_WEBHOOKURL, sMessage, true, sUsername, false, "", false);
|
||||
|
||||
return Plugin_Continue;
|
||||
}
|
||||
*/
|
||||
public void AntiBhopCheat_OnClientDetected(int client, char[] sReason, char[] sStats)
|
||||
{
|
||||
char sCurrentMap[64];
|
||||
@@ -907,7 +762,6 @@ public void EW_OnClientRestricted(int client, int target, int hours, int minutes
|
||||
Call_Finish();
|
||||
}
|
||||
|
||||
|
||||
public void EW_OnClientUnrestricted(int client, int target)
|
||||
{
|
||||
char sCurrentMap[64];
|
||||
|
||||
Reference in New Issue
Block a user