Discord: Without livechat, and updated urls

This commit is contained in:
zaCade 2019-03-16 23:29:27 +01:00
parent 2fad81dc0e
commit 46beb23bc3

View File

@ -5,7 +5,7 @@
#include <SteamWorks>
#include <regex>
#include <smjansson>
#include <morecolors>
#include <multicolors>
#include "sdktools_functions.inc"
@ -16,30 +16,29 @@
#pragma newdecls required
#define STEAM_API_KEY "7FF6DCA2152A102DFF8CEC89D917B2B2"
#define DISCORD_LIVEWEBHOOK_URL "https://discordapp.com/api/webhooks/420234463335677961/HC5Sd_WJu4fGq1SlwOfvHLPcpCMoNAniITYAbxz2gAT80VAFin8TWK8P9x0xQSJgLXRj"
#define DISCORD_ADMINLOGS_WEBHOOKURL "https://discordapp.com/api/webhooks/420234772254687233/pgqnmLXwR8bTe5SI_EHU5ZbbyITQxBB5FsiyyDzvhQS5LZLsyljzfFGDPpY55aH5H-Lp"
#define DISCORD_ADMINCHAT_WEBHOOKURL "https://discordapp.com/api/webhooks/420234615173939220/4k2ejMnksUxS_Fv0UtTazdoWfOVizxli4Bz97PHhw4vgPkkOuG_nNuFNpmsfxCs6XFbm"
#define DISCORD_RCON_WEBHOOKURL "https://discordapp.com/api/webhooks/421078039699521536/WHHvLf4DkY8UUR_C0BjdCk1REbu5jugAzOrr0MU2nvrhR0hxn6OtlHhHgi-dR7VmfEaT"
#define DISCORD_CALLADMIN_WEBHOOKURL "https://discordapp.com/api/webhooks/423998266544357376/1LeQ5yxlsrAvi8MfgmE1HaI_IHDn419lXefwIS6WveyTa3dbZbPhNOs5cDnc8dLATeNv"
#define DISCORD_ANTIBHOPCHEAT_WEBHOOKURL "https://discordapp.com/api/webhooks/424725421632782353/76taTm6PgfeT02oX_yTgM-WEESAFp5uWxwZCoFnrW23cX8hxg9l-9mZTbCz-uI579n_9"
#define DISCORD_ENTWATCH_WEBHOOKURL "https://discordapp.com/api/webhooks/428546704195715072/s18ixMOKzadul8OwuQ3wONb3bcsjh-CIPq3jg-g2Ljhc50JpWiepwUWewJQybavpuaOv"
#define DISCORD_LIVEWEBHOOK_URL ""
#define DISCORD_ADMINLOGS_WEBHOOKURL "https://discordapp.com/api/webhooks/420234772254687233/pgqnmLXwR8bTe5SI_EHU5ZbbyITQxBB5FsiyyDzvhQS5LZLsyljzfFGDPpY55aH5H-Lp"
#define DISCORD_ADMINCHAT_WEBHOOKURL "https://discordapp.com/api/webhooks/554631582183587841/viMQZB8bQXRtQphtVSd04QTNtPd5PpvClJxunWdySYqM4Jty4xeejqqXGzBzbezycpxF"
#define DISCORD_RCON_WEBHOOKURL "https://discordapp.com/api/webhooks/421078039699521536/WHHvLf4DkY8UUR_C0BjdCk1REbu5jugAzOrr0MU2nvrhR0hxn6OtlHhHgi-dR7VmfEaT"
#define DISCORD_CALLADMIN_WEBHOOKURL "https://discordapp.com/api/webhooks/423998266544357376/1LeQ5yxlsrAvi8MfgmE1HaI_IHDn419lXefwIS6WveyTa3dbZbPhNOs5cDnc8dLATeNv"
#define DISCORD_ANTIBHOPCHEAT_WEBHOOKURL "https://discordapp.com/api/webhooks/424725421632782353/76taTm6PgfeT02oX_yTgM-WEESAFp5uWxwZCoFnrW23cX8hxg9l-9mZTbCz-uI579n_9"
#define DISCORD_ENTWATCH_WEBHOOKURL "https://discordapp.com/api/webhooks/428546704195715072/s18ixMOKzadul8OwuQ3wONb3bcsjh-CIPq3jg-g2Ljhc50JpWiepwUWewJQybavpuaOv"
Regex g_Regex_Clyde = null;
ArrayList g_arrQueuedMessages = null;
Handle g_hDataTimer = null;
Handle g_hReplaceConfigFile = null;
//Handle g_hReplaceConfigFile = null;
UserMsg g_umSayText2 = INVALID_MESSAGE_ID;
bool g_bLoadedLate;
bool g_bProcessingData;
bool g_bGotReplaceFile;
bool g_bTeamChat;
//bool g_bGotReplaceFile;
//bool g_bTeamChat;
char g_sReplacePath[PLATFORM_MAX_PATH];
//char g_sReplacePath[PLATFORM_MAX_PATH];
char g_sAvatarURL[MAXPLAYERS + 1][128];
int g_iRatelimitRemaining = 5;
@ -73,11 +72,11 @@ public void OnPluginStart()
if (RegexErr != REGEX_ERROR_NONE)
LogError("Could not compile \"Clyde\" regex (err: %s)", sRegexErr);
g_hReplaceConfigFile = CreateKeyValues("AutoReplace");
BuildPath(Path_SM, g_sReplacePath, sizeof(g_sReplacePath), "configs/custom-chatcolorsreplace.cfg");
// g_hReplaceConfigFile = CreateKeyValues("AutoReplace");
// BuildPath(Path_SM, g_sReplacePath, sizeof(g_sReplacePath), "configs/custom-chatcolorsreplace.cfg");
if (FileToKeyValues(g_hReplaceConfigFile, g_sReplacePath))
g_bGotReplaceFile = true;
// if (FileToKeyValues(g_hReplaceConfigFile, g_sReplacePath))
// g_bGotReplaceFile = true;
g_arrQueuedMessages = CreateArray(ByteCountToCells(1024));
@ -88,9 +87,8 @@ public void OnPluginStart()
if (g_umSayText2 == INVALID_MESSAGE_ID)
SetFailState("This game doesn't support SayText2 user messages.");
HookUserMessage(g_umSayText2, Hook_UserMessage, false);
HookEvent("player_say", EventHook_PlayerSay, EventHookMode_Post);
// HookUserMessage(g_umSayText2, Hook_UserMessage, false);
// HookEvent("player_say", EventHook_PlayerSay, EventHookMode_Post);
if (g_bLoadedLate)
{
@ -117,8 +115,8 @@ public void OnPluginEnd()
delete g_arrQueuedMessages;
delete g_hDataTimer;
UnhookUserMessage(g_umSayText2, Hook_UserMessage, false);
UnhookEvent("player_say", EventHook_PlayerSay, EventHookMode_Post);
// UnhookUserMessage(g_umSayText2, Hook_UserMessage, false);
// UnhookEvent("player_say", EventHook_PlayerSay, EventHookMode_Post);
}
public void OnClientAuthorized(int client, const char[] sAuthID32)
@ -187,7 +185,7 @@ public Action Timer_DataProcessor(Handle hThis)
if (g_iRatelimitRemaining == 0 && GetTime() < g_iRatelimitReset)
return;
//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));
@ -200,9 +198,9 @@ public Action Timer_DataProcessor(Handle hThis)
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);
@ -223,6 +221,7 @@ public Action Timer_DataProcessor(Handle hThis)
return;
}
}
/*
public Action Hook_UserMessage(UserMsg msg_id, Handle bf, const players[], int playersNum, bool reliable, bool init)
{
char sMessageName[32];
@ -251,8 +250,8 @@ public void EventHook_PlayerSay(Event hThis, const char[] sName, bool bDontBroad
{
int iUserID = GetEventInt(hThis, "userid");
int iClient = GetClientOfUserId(iUserID);
char sMessageText[192];
char sMessageText[192];
GetEventString(hThis, "text", sMessageText, sizeof(sMessageText));
//PrintToServer("[EventHook_PlayerSay] Fired for %N: %s", iClient, sMessageText);
@ -263,11 +262,8 @@ public void EventHook_PlayerSay(Event hThis, const char[] sName, bool bDontBroad
return;
char sClientName[64];
GetClientName(iClient, sClientName, sizeof(sClientName));
if (g_bGotReplaceFile)
{
char sPart[192];
@ -321,7 +317,7 @@ public void EventHook_PlayerSay(Event hThis, const char[] sName, bool bDontBroad
else
Discord_POST(DISCORD_LIVEWEBHOOK_URL, sMessageText, true, sClientName);
}
*/
stock bool Steam32IDtoSteam64ID(const char[] sSteam32ID, char[] sSteam64ID, int Size)
{
if (strlen(sSteam32ID) < 11 || strncmp(sSteam32ID[0], "STEAM_0:", 8) || strcmp(sSteam32ID, "STEAM_ID_PENDING") == 0)
@ -354,27 +350,27 @@ stock void Discord_MakeStringSafe(const char[] sOrigin, char[] sOut, int iOutSiz
{
if (sOrigin[i] < 0x20 && sOrigin[i] != 0x0)
{
//sOut[iCurIndex] = 0x20;
//iCurIndex++;
// 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, "\\u0022");
// iCurIndex += 6;
//
// continue;
// }
// case '\\':
// {
// strcopy(sOut[iCurIndex], iOutSize, "\\u005C");
// iCurIndex += 6;
//
// continue;
// }
case '@':
{
strcopy(sOut[iCurIndex], iOutSize, "@"); //@ + zero-width space
@ -440,7 +436,7 @@ stock void APIWebResponse(const char[] sData, int client)
if (!kvResponse.ImportFromString(sData, "SteamAPIResponse"))
{
//LogError("kvResponse.ImportFromString(\"SteamAPIResponse\") in APIWebResponse failed.");
// LogError("kvResponse.ImportFromString(\"SteamAPIResponse\") in APIWebResponse failed.");
delete kvResponse;
return;
@ -448,7 +444,7 @@ stock void APIWebResponse(const char[] sData, int client)
if (!kvResponse.JumpToKey("players"))
{
//LogError("kvResponse.JumpToKey(\"players\") in APIWebResponse failed.");
// LogError("kvResponse.JumpToKey(\"players\") in APIWebResponse failed.");
delete kvResponse;
return;
@ -456,7 +452,7 @@ stock void APIWebResponse(const char[] sData, int client)
if (!kvResponse.GotoFirstSubKey())
{
//LogError("kvResponse.GotoFirstSubKey() in APIWebResponse failed.");
// LogError("kvResponse.GotoFirstSubKey() in APIWebResponse failed.");
delete kvResponse;
return;
@ -469,8 +465,8 @@ stock void APIWebResponse(const char[] sData, int client)
stock void HTTPPostJSON(const char[] sURL, const char[] sText)
{
// if (g_iRatelimitRemaining > 0 && !g_bProcessingData && GetTime() < g_iRatelimitReset)
// {
// if (g_iRatelimitRemaining > 0 && !g_bProcessingData && GetTime() < g_iRatelimitReset)
// {
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST, sURL);
JSONObject RequestJSON = view_as<JSONObject>(json_load(sText));
@ -489,20 +485,20 @@ stock void HTTPPostJSON(const char[] sURL, const char[] sText)
return;
}
// }
// else
// {
// g_arrQueuedMessages.PushString(sText);
// g_arrQueuedMessages.PushString(sURL);
// g_bProcessingData = true;
// }
// }
// else
// {
// g_arrQueuedMessages.PushString(sText);
// g_arrQueuedMessages.PushString(sURL);
// g_bProcessingData = true;
// }
//delete hRequest;
// delete hRequest;
}
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);
// PrintToServer("[Discord_POST] Called with text: %s", sText);
JSONRootNode hJSONRoot = new JSONObject();
@ -542,13 +538,13 @@ stock void Discord_POST(const char[] sURL, char[] sText, bool bUsingUsername=fal
(view_as<JSONObject>(hJSONRoot)).SetString("content", sSafeText);
(view_as<JSONObject>(hJSONRoot)).ToString(sFinal, sizeof(sFinal), 0);
//hJSONRoot.DumpToServer();
// hJSONRoot.DumpToServer();
delete hJSONRoot;
if ((g_iRatelimitRemaining > 0 || GetTime() >= g_iRatelimitReset) && !g_bProcessingData)
{
//PrintToServer("[Discord_POST] Have allowances and not processing data");
// PrintToServer("[Discord_POST] Have allowances and not processing data");
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST, sURL);
@ -571,13 +567,13 @@ stock void Discord_POST(const char[] sURL, char[] sText, bool bUsingUsername=fal
}
else
{
//PrintToServer("[Discord_POST] Have allowances? [%s] | Is processing data? [%s]", g_iRatelimitRemaining > 0 ? "YES":"NO", g_bProcessingData?"YES":"NO");
// PrintToServer("[Discord_POST] Have allowances? [%s] | Is processing data? [%s]", g_iRatelimitRemaining > 0 ? "YES":"NO", g_bProcessingData ? "YES":"NO");
g_arrQueuedMessages.PushString(sFinal);
g_arrQueuedMessages.PushString(sURL);
g_bProcessingData = true;
}
//delete hRequest; //nonono
// delete hRequest; //nonono
}
public int OnHTTPRequestCompleted(Handle hRequest, bool bFailure, bool bRequestSuccessful, EHTTPStatusCode eStatusCode, JSONObject RequestJSON)
@ -630,7 +626,7 @@ public int OnHTTPRequestCompleted(Handle hRequest, bool bFailure, bool bRequestS
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;
@ -708,8 +704,8 @@ public Action OnClientSayCommand(int client, const char[] sCommand, const char[]
if (!bAdmin)
{
//g_iReplyTargetSerial = GetClientSerial(client);
//g_iReplyType = REPLYTYPE_CHAT;
// g_iReplyTargetSerial = GetClientSerial(client);
// g_iReplyType = REPLYTYPE_CHAT;
}
return Plugin_Continue;
@ -831,7 +827,6 @@ public int entWatch_OnClientBanned(int admin, int iLenght, int client)
Format(sMessageTmp, sizeof(sMessageTmp), "%L got restricted by %L for %d minutes", client, admin, iLenght);
}
char sMessage[4096];
Format(sMessage, sizeof(sMessage), "```%s - Tick: %d``````%s```", currentMap, GetGameTickCount(), sMessageTmp);