diff --git a/.travis.yml b/.travis.yml index bf27da8..cf2f7c3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,7 @@ before_script: - mv sbpp_discord.sp addons/sourcemod/scripting/ - cd addons/sourcemod/scripting/ - wget https://raw.githubusercontent.com/sbpp/sourcebans-pp/v1.x/game/addons/sourcemod/scripting/include/sourcebanspp.inc -O include/sourcebanspp.inc + - wget https://raw.githubusercontent.com/sbpp/sourcebans-pp/v1.x/game/addons/sourcemod/scripting/include/sourcecomms.inc -O include/sourcecomms.inc - wget https://raw.githubusercontent.com/KyleSanderson/SteamWorks/master/Pawn/includes/SteamWorks.inc -O include/SteamWorks.inc - wget https://raw.githubusercontent.com/thraaawn/SMJansson/master/pawn/scripting/include/smjansson.inc -O include/smjansson.inc - chmod +x spcomp @@ -35,7 +36,7 @@ deploy: skip_cleanup: true on: tags: true - condition: $SOURCEMOD = 1.8 + condition: $SOURCEMOD = 1.9 notifications: email: false diff --git a/sbpp_discord.sp b/sbpp_discord.sp index 03e6573..2ea4270 100644 --- a/sbpp_discord.sp +++ b/sbpp_discord.sp @@ -1,10 +1,11 @@ #pragma semicolon 1 #define PLUGIN_AUTHOR "RumbleFrog, SourceBans++ Dev Team" -#define PLUGIN_VERSION "1.0.4" +#define PLUGIN_VERSION "1.1.0" #include #include +#include #include #include @@ -14,12 +15,22 @@ enum { Ban, Report, - Type_Count + Comms, + Type_Count, + Type_Unknown, +}; + +int EmbedColors[Type_Count] = { + 0xDA1D87, // Ban + 0xF9D942, // Report + 0x4362FA, // Comms }; ConVar Convars[Type_Count]; -char sEndpoints[Type_Count][256], sHostname[64], sHost[64]; +char sEndpoints[Type_Count][256] + , sHostname[64] + , sHost[64]; public Plugin myinfo = { @@ -35,34 +46,54 @@ public void OnPluginStart() CreateConVar("sbpp_discord_version", PLUGIN_VERSION, "SBPP Discord Version", FCVAR_REPLICATED | FCVAR_SPONLY | FCVAR_DONTRECORD | FCVAR_NOTIFY); Convars[Ban] = CreateConVar("sbpp_discord_banhook", "", "Discord web hook endpoint for ban forward", FCVAR_PROTECTED); + Convars[Report] = CreateConVar("sbpp_discord_reporthook", "", "Discord web hook endpoint for report forward. If left empty, the ban endpoint will be used instead", FCVAR_PROTECTED); + + Convars[Comms] = CreateConVar("sbpp_discord_commshook", "", "Discord web hook endpoint for comms forward. If left empty, the ban endpoint will be used instead", FCVAR_PROTECTED); Convars[Ban].AddChangeHook(OnConvarChanged); Convars[Report].AddChangeHook(OnConvarChanged); + Convars[Comms].AddChangeHook(OnConvarChanged); } public void OnConfigsExecuted() { FindConVar("hostname").GetString(sHostname, sizeof sHostname); - - int iIPB = FindConVar("hostip").IntValue; - Format(sHost, sizeof sHost, "%d.%d.%d.%d:%d", iIPB >> 24 & 0x000000FF, iIPB >> 16 & 0x000000FF, iIPB >> 8 & 0x000000FF, iIPB & 0x000000FF, FindConVar("hostport").IntValue); + + int ip[4]; + + SteamWorks_GetPublicIP(ip); + + if (SteamWorks_GetPublicIP(ip)) + { + Format(sHost, sizeof sHost, "%d.%d.%d.%d:%d", ip[0], ip[1], ip[2], ip[3], FindConVar("hostport").IntValue); + } else + { + int iIPB = FindConVar("hostip").IntValue; + Format(sHost, sizeof sHost, "%d.%d.%d.%d:%d", iIPB >> 24 & 0x000000FF, iIPB >> 16 & 0x000000FF, iIPB >> 8 & 0x000000FF, iIPB & 0x000000FF, FindConVar("hostport").IntValue); + } Convars[Ban].GetString(sEndpoints[Ban], sizeof sEndpoints[]); Convars[Report].GetString(sEndpoints[Report], sizeof sEndpoints[]); + Convars[Comms].GetString(sEndpoints[Comms], sizeof sEndpoints[]); } public void SBPP_OnBanPlayer(int iAdmin, int iTarget, int iTime, const char[] sReason) { - SendReport(iAdmin, iTarget, sReason, iTime); + SendReport(iAdmin, iTarget, sReason, Ban, iTime); +} + +public void SourceComms_OnBlockAdded(int iAdmin, int iTarget, int iTime, int iCommType, char[] sReason) +{ + SendReport(iAdmin, iTarget, sReason, Comms, iTime, iCommType); } public void SBPP_OnReportPlayer(int iReporter, int iTarget, const char[] sReason) { - SendReport(iReporter, iTarget, sReason); + SendReport(iReporter, iTarget, sReason, Report); } -void SendReport(int iClient, int iTarget, const char[] sReason, int iTime = -1) +void SendReport(int iClient, int iTarget, const char[] sReason, int iType = Ban, int iTime = -1, any extra = 0) { if (iTarget != -1 && !IsValidClient(iTarget)) return; @@ -95,8 +126,8 @@ void SendReport(int iClient, int iTarget, const char[] sReason, int iTime = -1) Handle jContent = json_object(); - - json_object_set(jContent, "color", json_integer((iTime != -1) ? 14294407 : 16374082)); + + json_object_set(jContent, "color", json_integer(GetEmbedColor(iType))); Handle jContentAuthor = json_object(); @@ -136,7 +167,7 @@ void SendReport(int iClient, int iTarget, const char[] sReason, int iTime = -1) json_array_append_new(jFields, jFieldAuthor); json_array_append_new(jFields, jFieldTarget); - if (iTime != -1) + if (iType == Ban || iType == Comms) { Handle jFieldDuration = json_object(); @@ -151,6 +182,21 @@ void SendReport(int iClient, int iTarget, const char[] sReason, int iTime = -1) json_array_append_new(jFields, jFieldDuration); } + + if (iType == Comms) + { + Handle jFieldCommType = json_object(); + + json_object_set_new(jFieldCommType, "name", json_string("Comm Type")); + + char cType[32]; + + GetCommType(cType, sizeof cType, extra); + + json_object_set_new(jFieldCommType, "value", json_string(cType)); + + json_array_append_new(jFields, jFieldCommType); + } json_array_append_new(jFields, jFieldReason); @@ -174,8 +220,12 @@ void SendReport(int iClient, int iTarget, const char[] sReason, int iTime = -1) #endif CloseHandle(jRequest); + + char sEndpoint[256]; + + GetEndpoint(sEndpoint, sizeof sEndpoint, iType); - Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST, (iTime != -1) ? sEndpoints[Ban] : (StrEqual(sEndpoints[Report], "")) ? sEndpoints[Ban] : sEndpoints[Report]); + Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST, sEndpoint); SteamWorks_SetHTTPRequestContextValue(hRequest, iClient, iTarget); SteamWorks_SetHTTPRequestGetOrPostParameter(hRequest, "payload_json", sJson); @@ -214,6 +264,40 @@ public void OnConvarChanged(ConVar convar, const char[] oldValue, const char[] n Convars[Ban].GetString(sEndpoints[Ban], sizeof sEndpoints[]); else if (convar == Convars[Report]) Convars[Report].GetString(sEndpoints[Report], sizeof sEndpoints[]); + else if (convar == Convars[Comms]) + Convars[Comms].GetString(sEndpoints[Comms], sizeof sEndpoints[]); +} + +int GetEmbedColor(int iType) +{ + if (iType != Type_Unknown) + return EmbedColors[iType]; + + return EmbedColors[Ban]; +} + +void GetEndpoint(char[] sBuffer, int iBufferSize, int iType) +{ + if (!StrEqual(sEndpoints[iType], "")) + { + strcopy(sBuffer, iBufferSize, sEndpoints[iType]); + return; + } + + strcopy(sBuffer, iBufferSize, sEndpoints[Ban]); +} + +void GetCommType(char[] sBuffer, int iBufferSize, int iType) +{ + switch (iType) + { + case TYPE_MUTE: + strcopy(sBuffer, iBufferSize, "Mute"); + case TYPE_GAG: + strcopy(sBuffer, iBufferSize, "Gag"); + case TYPE_SILENCE: + strcopy(sBuffer, iBufferSize, "Silence"); + } } stock bool IsValidClient(int iClient, bool bAlive = false)