|
|
|
@ -192,70 +192,73 @@ public Action Command_PrintToAllChat(int args)
|
|
|
|
|
|
|
|
|
|
public Action Timer_DataProcessor(Handle hThis)
|
|
|
|
|
{
|
|
|
|
|
if (!g_bProcessingData)
|
|
|
|
|
return;
|
|
|
|
|
if (!g_bProcessingData)
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
|
|
|
|
|
|
if (g_iRatelimitRemaining == 0 && GetTime() < g_iRatelimitReset)
|
|
|
|
|
return;
|
|
|
|
|
if (g_iRatelimitRemaining == 0 && GetTime() < g_iRatelimitReset)
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
|
|
|
|
|
|
//PrintToServer("[Timer_DataProcessor] Array Length #1: %d", g_arrQueuedMessages.Length);
|
|
|
|
|
//PrintToServer("[Timer_DataProcessor] Array Length #1: %d", g_arrQueuedMessages.Length);
|
|
|
|
|
|
|
|
|
|
char sContent[1024];
|
|
|
|
|
g_arrQueuedMessages.GetString(0, sContent, sizeof(sContent));
|
|
|
|
|
g_arrQueuedMessages.Erase(0);
|
|
|
|
|
char sContent[1024];
|
|
|
|
|
g_arrQueuedMessages.GetString(0, sContent, sizeof(sContent));
|
|
|
|
|
g_arrQueuedMessages.Erase(0);
|
|
|
|
|
|
|
|
|
|
char sURL[128];
|
|
|
|
|
g_arrQueuedMessages.GetString(0, sURL, sizeof(sURL));
|
|
|
|
|
g_arrQueuedMessages.Erase(0);
|
|
|
|
|
char sURL[128];
|
|
|
|
|
g_arrQueuedMessages.GetString(0, sURL, sizeof(sURL));
|
|
|
|
|
g_arrQueuedMessages.Erase(0);
|
|
|
|
|
|
|
|
|
|
if (g_arrQueuedMessages.Length == 0)
|
|
|
|
|
g_bProcessingData = false;
|
|
|
|
|
if (g_arrQueuedMessages.Length == 0)
|
|
|
|
|
g_bProcessingData = false;
|
|
|
|
|
|
|
|
|
|
//PrintToServer("[Timer_DataProcessor] Array Length #2: %d", g_arrQueuedMessages.Length);
|
|
|
|
|
//PrintToServer("[Timer_DataProcessor] Array Length #2: %d", g_arrQueuedMessages.Length);
|
|
|
|
|
|
|
|
|
|
//PrintToServer("%s | %s", sURL, sContent);
|
|
|
|
|
//PrintToServer("%s | %s", sURL, sContent);
|
|
|
|
|
|
|
|
|
|
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST, sURL);
|
|
|
|
|
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST, sURL);
|
|
|
|
|
|
|
|
|
|
JSONObject RequestJSON = view_as<JSONObject>(json_load(sContent));
|
|
|
|
|
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.");
|
|
|
|
|
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;
|
|
|
|
|
delete RequestJSON;
|
|
|
|
|
delete hRequest;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
|
}
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
|
}
|
|
|
|
|
public Action Hook_UserMessage(UserMsg msg_id, Handle bf, const players[], int playersNum, bool reliable, bool init)
|
|
|
|
|
|
|
|
|
|
public Action Hook_UserMessage(UserMsg msg_id, Handle bf, const int[] players, int playersNum, bool reliable, bool init)
|
|
|
|
|
{
|
|
|
|
|
char sMessageName[32];
|
|
|
|
|
char sMessageSender[64];
|
|
|
|
|
int iAuthor = BfReadByte(bf);
|
|
|
|
|
bool bIsChat = view_as<bool>(BfReadByte(bf)); if (bIsChat) bIsChat=false; //fucking compiler shut the fuck up REEEEEE
|
|
|
|
|
BfReadString(bf, sMessageName, sizeof(sMessageName), false);
|
|
|
|
|
BfReadString(bf, sMessageSender, sizeof(sMessageSender), false);
|
|
|
|
|
char sMessageName[32];
|
|
|
|
|
char sMessageSender[64];
|
|
|
|
|
int iAuthor = BfReadByte(bf);
|
|
|
|
|
bool bIsChat = view_as<bool>(BfReadByte(bf)); if (bIsChat) bIsChat=false; //fucking compiler shut the fuck up REEEEEE
|
|
|
|
|
BfReadString(bf, sMessageName, sizeof(sMessageName), false);
|
|
|
|
|
BfReadString(bf, sMessageSender, sizeof(sMessageSender), false);
|
|
|
|
|
|
|
|
|
|
if (iAuthor <= 0 || iAuthor > MaxClients)
|
|
|
|
|
return;
|
|
|
|
|
if (iAuthor <= 0 || iAuthor > MaxClients)
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
|
|
|
|
|
|
if (strlen(sMessageName) == 0 || strlen(sMessageSender) == 0)
|
|
|
|
|
return;
|
|
|
|
|
if (strlen(sMessageName) == 0 || strlen(sMessageSender) == 0)
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
|
|
|
|
|
|
if (strcmp(sMessageName, "#Cstrike_Name_Change") == 0)
|
|
|
|
|
return;
|
|
|
|
|
if (strcmp(sMessageName, "#Cstrike_Name_Change") == 0)
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
|
|
|
|
|
|
if (sMessageName[13] == 'C' || sMessageName[13] == 'T' || sMessageName[13] == 'S')
|
|
|
|
|
g_bTeamChat = true;
|
|
|
|
|
else
|
|
|
|
|
g_bTeamChat = false;
|
|
|
|
|
if (sMessageName[13] == 'C' || sMessageName[13] == 'T' || sMessageName[13] == 'S')
|
|
|
|
|
g_bTeamChat = true;
|
|
|
|
|
else
|
|
|
|
|
g_bTeamChat = false;
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stock bool Steam32IDtoSteam64ID(const char[] sSteam32ID, char[] sSteam64ID, int Size)
|
|
|
|
@ -350,26 +353,27 @@ 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);
|
|
|
|
|
}
|
|
|
|
|
if (bFailure || !bRequestSuccessful || eStatusCode != k_EHTTPStatusCode200OK)
|
|
|
|
|
{
|
|
|
|
|
if (eStatusCode != k_EHTTPStatusCode429TooManyRequests)
|
|
|
|
|
{
|
|
|
|
|
LogError("SteamAPI HTTP Response failed: %d", eStatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete hRequest;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
delete hRequest;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int iBodyLength;
|
|
|
|
|
SteamWorks_GetHTTPResponseBodySize(hRequest, iBodyLength);
|
|
|
|
|
int iBodyLength;
|
|
|
|
|
SteamWorks_GetHTTPResponseBodySize(hRequest, iBodyLength);
|
|
|
|
|
|
|
|
|
|
char[] sData = new char[iBodyLength];
|
|
|
|
|
SteamWorks_GetHTTPResponseBodyData(hRequest, sData, iBodyLength);
|
|
|
|
|
char[] sData = new char[iBodyLength];
|
|
|
|
|
SteamWorks_GetHTTPResponseBodyData(hRequest, sData, iBodyLength);
|
|
|
|
|
|
|
|
|
|
delete hRequest;
|
|
|
|
|
delete hRequest;
|
|
|
|
|
|
|
|
|
|
APIWebResponse(sData, client);
|
|
|
|
|
APIWebResponse(sData, client);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stock void APIWebResponse(const char[] sData, int client)
|
|
|
|
@ -520,58 +524,59 @@ stock void Discord_POST(const char[] sURL, char[] sText, bool bUsingUsername=fal
|
|
|
|
|
|
|
|
|
|
public int OnHTTPRequestCompleted(Handle hRequest, bool bFailure, bool bRequestSuccessful, EHTTPStatusCode eStatusCode, JSONObject RequestJSON)
|
|
|
|
|
{
|
|
|
|
|
if (bFailure || !bRequestSuccessful || (eStatusCode != k_EHTTPStatusCode200OK && eStatusCode != k_EHTTPStatusCode204NoContent))
|
|
|
|
|
{
|
|
|
|
|
if (eStatusCode != k_EHTTPStatusCode429TooManyRequests)
|
|
|
|
|
LogError("Discord HTTP request failed: %d", eStatusCode);
|
|
|
|
|
if (bFailure || !bRequestSuccessful || (eStatusCode != k_EHTTPStatusCode200OK && eStatusCode != k_EHTTPStatusCode204NoContent))
|
|
|
|
|
{
|
|
|
|
|
if (eStatusCode != k_EHTTPStatusCode429TooManyRequests)
|
|
|
|
|
LogError("Discord HTTP request failed: %d", eStatusCode);
|
|
|
|
|
|
|
|
|
|
if (eStatusCode == k_EHTTPStatusCode400BadRequest)
|
|
|
|
|
{
|
|
|
|
|
char sData[2048];
|
|
|
|
|
if (eStatusCode == k_EHTTPStatusCode400BadRequest)
|
|
|
|
|
{
|
|
|
|
|
char sData[2048];
|
|
|
|
|
|
|
|
|
|
(view_as<JSONRootNode>(RequestJSON)).ToString(sData, sizeof(sData), 0);
|
|
|
|
|
(view_as<JSONRootNode>(RequestJSON)).ToString(sData, sizeof(sData), 0);
|
|
|
|
|
|
|
|
|
|
LogError("Malformed request? Dumping request data:\n%s", sData);
|
|
|
|
|
}
|
|
|
|
|
else if (eStatusCode == k_EHTTPStatusCode429TooManyRequests)
|
|
|
|
|
{
|
|
|
|
|
g_iRatelimitRemaining = 0;
|
|
|
|
|
g_iRatelimitReset = GetTime() + 5;
|
|
|
|
|
}
|
|
|
|
|
LogError("Malformed request? Dumping request data:\n%s", sData);
|
|
|
|
|
}
|
|
|
|
|
else if (eStatusCode == k_EHTTPStatusCode429TooManyRequests)
|
|
|
|
|
{
|
|
|
|
|
g_iRatelimitRemaining = 0;
|
|
|
|
|
g_iRatelimitReset = GetTime() + 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete RequestJSON;
|
|
|
|
|
delete hRequest;
|
|
|
|
|
delete RequestJSON;
|
|
|
|
|
delete hRequest;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int iLastRatelimitRemaining = 0;
|
|
|
|
|
static int iLastRatelimitReset = 0;
|
|
|
|
|
char sTmp[32];
|
|
|
|
|
bool bHeaderExists = SteamWorks_GetHTTPResponseHeaderValue(hRequest, "x-ratelimit-remaining", sTmp, sizeof(sTmp));
|
|
|
|
|
static int iLastRatelimitRemaining = 0;
|
|
|
|
|
static int iLastRatelimitReset = 0;
|
|
|
|
|
char sTmp[32];
|
|
|
|
|
bool bHeaderExists = SteamWorks_GetHTTPResponseHeaderValue(hRequest, "x-ratelimit-remaining", sTmp, sizeof(sTmp));
|
|
|
|
|
|
|
|
|
|
if (!bHeaderExists)
|
|
|
|
|
LogError("x-ratelimit-remaining header value could not be retrieved");
|
|
|
|
|
if (!bHeaderExists)
|
|
|
|
|
LogError("x-ratelimit-remaining header value could not be retrieved");
|
|
|
|
|
|
|
|
|
|
int iRatelimitRemaining = StringToInt(sTmp);
|
|
|
|
|
int iRatelimitRemaining = StringToInt(sTmp);
|
|
|
|
|
|
|
|
|
|
bHeaderExists = SteamWorks_GetHTTPResponseHeaderValue(hRequest, "x-ratelimit-reset", sTmp, sizeof(sTmp));
|
|
|
|
|
bHeaderExists = SteamWorks_GetHTTPResponseHeaderValue(hRequest, "x-ratelimit-reset", sTmp, sizeof(sTmp));
|
|
|
|
|
|
|
|
|
|
if (!bHeaderExists)
|
|
|
|
|
LogError("x-ratelimit-reset header value could not be retrieved");
|
|
|
|
|
if (!bHeaderExists)
|
|
|
|
|
LogError("x-ratelimit-reset header value could not be retrieved");
|
|
|
|
|
|
|
|
|
|
int iRatelimitReset = StringToInt(sTmp);
|
|
|
|
|
int iRatelimitReset = StringToInt(sTmp);
|
|
|
|
|
|
|
|
|
|
if (iRatelimitRemaining < iLastRatelimitRemaining || iRatelimitReset >= iLastRatelimitReset) //don't be fooled by different completion times
|
|
|
|
|
{
|
|
|
|
|
g_iRatelimitRemaining = iRatelimitRemaining;
|
|
|
|
|
g_iRatelimitReset = iRatelimitReset;
|
|
|
|
|
}
|
|
|
|
|
if (iRatelimitRemaining < iLastRatelimitRemaining || iRatelimitReset >= iLastRatelimitReset) //don't be fooled by different completion times
|
|
|
|
|
{
|
|
|
|
|
g_iRatelimitRemaining = iRatelimitRemaining;
|
|
|
|
|
g_iRatelimitReset = iRatelimitReset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//PrintToServer("limit: %d | remaining: %d || reset %d - now %d", g_iRatelimitLimit, g_iRatelimitRemaining, g_iRatelimitReset, GetTime());
|
|
|
|
|
//PrintToServer("limit: %d | remaining: %d || reset %d - now %d", g_iRatelimitLimit, g_iRatelimitRemaining, g_iRatelimitReset, GetTime());
|
|
|
|
|
|
|
|
|
|
delete RequestJSON;
|
|
|
|
|
delete hRequest;
|
|
|
|
|
delete RequestJSON;
|
|
|
|
|
delete hRequest;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stock bool IsValidClient(int client)
|
|
|
|
@ -581,34 +586,34 @@ stock bool IsValidClient(int client)
|
|
|
|
|
|
|
|
|
|
public Action OnLogAction(Handle hSource, Identity ident, int client, int target, const char[] sMsg)
|
|
|
|
|
{
|
|
|
|
|
if (client <= 0)
|
|
|
|
|
return;
|
|
|
|
|
if (client <= 0)
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
|
|
|
|
|
|
if ((StrContains(sMsg, "sm_psay", false)!= -1) || (StrContains(sMsg, "sm_chat", false)!= -1))
|
|
|
|
|
return;// dont log sm_psay and sm_chat
|
|
|
|
|
if ((StrContains(sMsg, "sm_psay", false)!= -1) || (StrContains(sMsg, "sm_chat", false)!= -1))
|
|
|
|
|
return Plugin_Handled;// dont log sm_psay and sm_chat
|
|
|
|
|
|
|
|
|
|
char sFinal[256];
|
|
|
|
|
char sCurrentMap[32];
|
|
|
|
|
char sDemoInfo[64];
|
|
|
|
|
char sClientName[64];
|
|
|
|
|
char sFinal[256];
|
|
|
|
|
char sCurrentMap[32];
|
|
|
|
|
char sDemoInfo[64];
|
|
|
|
|
char sClientName[64];
|
|
|
|
|
|
|
|
|
|
GetCurrentMap(sCurrentMap, sizeof(sCurrentMap));
|
|
|
|
|
GetCurrentMap(sCurrentMap, sizeof(sCurrentMap));
|
|
|
|
|
|
|
|
|
|
if (IsDemoRecording())
|
|
|
|
|
Format(sDemoInfo, sizeof(sDemoInfo), "Demo: %d @ Tick: %d", GetDemoRecordingNumber(), GetDemoRecordingTick());
|
|
|
|
|
else
|
|
|
|
|
Format(sDemoInfo, sizeof(sDemoInfo), "Not recording");
|
|
|
|
|
if (IsDemoRecording())
|
|
|
|
|
Format(sDemoInfo, sizeof(sDemoInfo), "Demo: %d @ Tick: %d", GetDemoRecordingNumber(), GetDemoRecordingTick());
|
|
|
|
|
else
|
|
|
|
|
Format(sDemoInfo, sizeof(sDemoInfo), "Not recording");
|
|
|
|
|
|
|
|
|
|
Format(sFinal, sizeof(sFinal), "[ %s ][ %s ]```%s```", sCurrentMap, sDemoInfo, sMsg);
|
|
|
|
|
Format(sFinal, sizeof(sFinal), "[ %s ][ %s ]```%s```", sCurrentMap, sDemoInfo, sMsg);
|
|
|
|
|
|
|
|
|
|
GetClientName(client, sClientName, sizeof(sClientName));
|
|
|
|
|
GetClientName(client, sClientName, sizeof(sClientName));
|
|
|
|
|
|
|
|
|
|
if (g_sAvatarURL[client][0] != '\0')
|
|
|
|
|
Discord_POST(DISCORD_ADMINLOGS_WEBHOOKURL, sFinal, true, sClientName, true, g_sAvatarURL[client], false);
|
|
|
|
|
else
|
|
|
|
|
Discord_POST(DISCORD_ADMINLOGS_WEBHOOKURL, sFinal, true, sClientName, false, "", false);
|
|
|
|
|
if (g_sAvatarURL[client][0] != '\0')
|
|
|
|
|
Discord_POST(DISCORD_ADMINLOGS_WEBHOOKURL, sFinal, true, sClientName, true, g_sAvatarURL[client], false);
|
|
|
|
|
else
|
|
|
|
|
Discord_POST(DISCORD_ADMINLOGS_WEBHOOKURL, sFinal, true, sClientName, false, "", false);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Action CommandListener_SmChat(int client, const char[] sCommand, int argc)
|
|
|
|
|