-add ScriptBan event

-add new automated penalty to ban players for certain filtered words or phrases
This commit is contained in:
INSANEMODE 2023-04-09 22:32:48 -05:00
parent 231f77bc77
commit 48b52e8c58
4 changed files with 92 additions and 2 deletions

View File

@ -19,6 +19,10 @@
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2023.4.5.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="dotnet publish $(ProjectPath) -c $(ConfigurationName) -o $(ProjectDir)..\..\Build\Plugins --no-build --no-restore --no-dependencies" />
</Target>

View File

@ -3,6 +3,7 @@ using SharedLibraryCore.Commands;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
using SharedLibraryCore.Interfaces.Events;
using System.Threading.Tasks;

View File

@ -1,7 +1,10 @@
using SharedLibraryCore;
using Serilog.Debugging;
using SharedLibraryCore;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Events.Game;
using SharedLibraryCore.Interfaces;
using System.Collections.Generic;
using System.Globalization;
using EventGeneratorCallback = System.ValueTuple<string, string,
System.Func<string, SharedLibraryCore.Interfaces.IEventParserConfiguration,
SharedLibraryCore.GameEvent,
@ -13,6 +16,7 @@ namespace IW4MAdmin.Plugins.ClanTagRankCommands.Events
{
private const string EVENT_RC = "RC";
private const string EVENT_ScriptBan = "ScriptBan";
/// <summary>
/// this is a custom event printed out by _clientids.gsc (used for recording highest personal round records)
@ -37,6 +41,28 @@ namespace IW4MAdmin.Plugins.ClanTagRankCommands.Events
}
);
}
private EventGeneratorCallback ScriptBan()
{
return (EVENT_ScriptBan, EVENT_ScriptBan, (eventLine, _, _) =>
{
string[] lineSplit = eventLine.Split(";");
long originId = lineSplit[1].ConvertGuidToLong(NumberStyles.Integer);
int clientnum = int.Parse(lineSplit[2]);
var scriptBan = new ScriptBanEvent
{
Type = GameEvent.EventType.Other,
Subtype = EVENT_ScriptBan,
Origin = Utilities.IW4MAdminClient(),
Target = new EFClient { NetworkId = originId, Name = lineSplit[3], ClientNumber = clientnum },
ScriptData = eventLine
};
return scriptBan;
}
);
}
//private const string EVENT_RoundNumber = "RoundNumber";
///// <summary>
@ -60,8 +86,12 @@ namespace IW4MAdmin.Plugins.ClanTagRankCommands.Events
public IEnumerable<EventGeneratorCallback> Events =>
new[]
{
RC(),
RC(),ScriptBan()
};
public class ScriptBanEvent : GameScriptEvent
{
}
}
}

View File

@ -17,12 +17,19 @@ using JsonSerializer = System.Text.Json.JsonSerializer;
using System.Linq;
using Serilog.Core;
using EFClient = Data.Models.Client.EFClient;
using static IW4MAdmin.Plugins.ClanTagRankCommands.Events.Script;
using SharedLibraryCore.Events.Game;
using SharedLibraryCore.Events.Server;
using System.Collections.Concurrent;
namespace ClanTagRankCommands
{
public class Plugin : IPluginV2
{
//private const string ProfanityKey = "_profanityInfringements";
//private readonly IConfigurationHandler<ClanTagConfiguration> _configurationHandler;
private readonly ILogger _logger;
//private ClanTagConfiguration Config;
@ -51,7 +58,9 @@ namespace ClanTagRankCommands
public Plugin(IMetaServiceV2 metaService, ClanTagConfiguration Config, ILogger<Plugin> logger, IInteractionRegistration interactionRegistration, IRemoteCommandService remoteCommandService)
{
IManagementEventSubscriptions.Load += OnLoad;
IGameEventSubscriptions.ScriptEventTriggered += OnScriptEvent;
_remoteCommandService = remoteCommandService;
_logger = logger;
_metaService = metaService;
@ -62,6 +71,7 @@ namespace ClanTagRankCommands
public static void RegisterDependencies(IServiceCollection serviceCollection)
{
serviceCollection.AddConfiguration<ClanTagConfiguration>("ClanTagRankCommands");
}
private Task OnLoad(IManager manager, CancellationToken token)
{
@ -203,6 +213,44 @@ namespace ClanTagRankCommands
});
return Task.CompletedTask;
}
private Task OnScriptEvent(GameScriptEvent scriptEvent, CancellationToken token)
{
if (scriptEvent is not ScriptBanEvent ScriptBan)
{
return Task.CompletedTask;
}
try
{
string[] lineSplit = ScriptBan.ScriptData.Split(";");
var sender = Utilities.IW4MAdminClient(ScriptBan.Owner);
sender.AdministeredPenalties = new List<EFPenalty>
{
new()
{
AutomatedOffense = $"Profanity Filter Match: {lineSplit[4]} - {string.Join(",", lineSplit[5])}"
}
};
SharedLibraryCore.Database.Models.EFClient efClient = (SharedLibraryCore.Database.Models.EFClient)null;
string rule = ScriptBan.Owner.Manager.GetApplicationSettings().Configuration().GlobalRules.Where(rule => rule.Contains("hate")).FirstOrDefault().ToString();
efClient = ScriptBan.Owner.GetClientsAsList().First<SharedLibraryCore.Database.Models.EFClient>((Func<SharedLibraryCore.Database.Models.EFClient, bool>)(_client => _client.NetworkId == ScriptBan.Target.NetworkId));
efClient.Ban($"Profanity filter Racism match - {rule}", sender, false);
//ScriptBan.Owner.Ban("Blatent racism match", ScriptBan.Target., sender);
}
catch (Exception e)
{
_logger.LogError(e, "Could not parse ScriptBan Event: {Data}", e.Data);
}
return Task.CompletedTask;
}
public async Task OnEventAsync(GameEvent E, Server S)// => Task.CompletedTask;
{
if (E.Type == GameEvent.EventType.Disconnect && (S.Hostname.Contains("Donator") || S.Hostname.Contains("Test")) && E.Origin.Tag == "Guest")
@ -211,6 +259,13 @@ namespace ClanTagRankCommands
await _metaService.RemovePersistentMeta(EFMeta.ClientTagV2, E.Origin.ClientId,
E.Owner.Manager.CancellationToken);
}
else if (E.Type == GameEvent.EventType.Other && (S.Hostname.Contains("Donator") || S.Hostname.Contains("Test")) && E.Origin.Tag == "Guest")
{
E.Origin.Tag = null;
await _metaService.RemovePersistentMeta(EFMeta.ClientTagV2, E.Origin.ClientId,
E.Owner.Manager.CancellationToken);
}
}
public Task OnTickAsync(Server S)// =>