From c288184171d1637f1d92bff0fab68d471894c8bc Mon Sep 17 00:00:00 2001 From: RaidMax Date: Sat, 25 Jul 2020 21:15:46 -0500 Subject: [PATCH] implement action on report plugin for issue #144 --- Application/Main.cs | 5 ++- IW4MAdmin.sln | 1 + Plugins/ScriptPlugins/ActionOnReport.js | 49 +++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 Plugins/ScriptPlugins/ActionOnReport.js diff --git a/Application/Main.cs b/Application/Main.cs index d0da6cd53..45355be12 100644 --- a/Application/Main.cs +++ b/Application/Main.cs @@ -244,7 +244,10 @@ namespace IW4MAdmin.Application customLocale: config?.EnableCustomLocale ?? false ? (config.CustomLocale ?? "en-US") : "en-US"); }) .AddSingleton() - .AddSingleton(_serviceProvider => RestClient.For(Utilities.IsDevelopment ? new Uri("http://127.0.0.1:8080") : _serviceProvider.GetRequiredService().MasterUrl)) + .AddSingleton(_serviceProvider => RestClient + .For(Utilities.IsDevelopment ? new Uri("http://127.0.0.1:8080") : _serviceProvider + .GetRequiredService>().Configuration()?.MasterUrl ?? + new ApplicationConfiguration().MasterUrl)) .AddSingleton(); if (args.Contains("serialevents")) diff --git a/IW4MAdmin.sln b/IW4MAdmin.sln index 6ab317bbd..c10e5c4b8 100644 --- a/IW4MAdmin.sln +++ b/IW4MAdmin.sln @@ -36,6 +36,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IW4ScriptCommands", "Plugin EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ScriptPlugins", "ScriptPlugins", "{3F9ACC27-26DB-49FA-BCD2-50C54A49C9FA}" ProjectSection(SolutionItems) = preProject + Plugins\ScriptPlugins\ActionOnReport.js = Plugins\ScriptPlugins\ActionOnReport.js Plugins\ScriptPlugins\ParserCoD4x.js = Plugins\ScriptPlugins\ParserCoD4x.js Plugins\ScriptPlugins\ParserIW4x.js = Plugins\ScriptPlugins\ParserIW4x.js Plugins\ScriptPlugins\ParserPIW5.js = Plugins\ScriptPlugins\ParserPIW5.js diff --git a/Plugins/ScriptPlugins/ActionOnReport.js b/Plugins/ScriptPlugins/ActionOnReport.js new file mode 100644 index 000000000..f6950a5a6 --- /dev/null +++ b/Plugins/ScriptPlugins/ActionOnReport.js @@ -0,0 +1,49 @@ +let plugin = { + author: 'RaidMax', + version: 1.0, + name: 'Action on Report', + enabled: false, // indicates if the plugin is enabled + reportAction: 'TempBan', // can be TempBan or Ban + maxReportCount: 5, // how many reports before action is taken + tempBanDurationMinutes: 60, // how long to temporarily ban the player + eventTypes: { 'report': 103 }, + + onEventAsync: function (gameEvent, server) { + if (!this.enabled) { + return; + } + + if (gameEvent.Type === this.eventTypes['report']) { + if (!gameEvent.Target.IsIngame) { + return; + } + + let reportCount = this.reportCounts[gameEvent.Target.NetworkId] === undefined ? 0 : this.reportCounts[gameEvent.Target.NetworkId]; + reportCount++; + this.reportCounts[gameEvent.Target.NetworkId] = reportCount; + + if (reportCount >= this.maxReportCount) { + switch (this.reportAction) { + case 'TempBan': + server.Logger.WriteInfo(`TempBanning client (id) ${gameEvent.Target.ClientId} because they received ${reportCount} reports`); + gameEvent.Target.TempBan(_localization.LocalizationIndex['PLUGINS_REPORT_ACTION'], System.TimeSpan.FromMinutes(this.tempBanDurationMinutes), _IW4MAdminClient); + break; + case 'Ban': + server.Logger.WriteInfo(`Banning client (id) ${gameEvent.Target.ClientId} because they received ${reportCount} reports`); + gameEvent.Target.Ban(_localization.LocalizationIndex['PLUGINS_REPORT_ACTION'], _IW4MAdminClient, false); + break; + } + } + } + }, + + onLoadAsync: function (manager) { + this.reportCounts = {}; + }, + + onUnloadAsync: function () { + }, + + onTickAsync: function (server) { + } +}; \ No newline at end of file