2019-08-06 14:36:37 -04:00
|
|
|
|
using System.Collections.Generic;
|
2018-04-10 20:36:28 -04:00
|
|
|
|
using System.Reflection;
|
2018-09-04 13:40:29 -04:00
|
|
|
|
using System.Text.RegularExpressions;
|
2018-03-29 00:40:57 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2018-04-10 20:36:28 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Configuration;
|
2019-08-06 14:36:37 -04:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2018-04-10 20:36:28 -04:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-03-29 00:40:57 -04:00
|
|
|
|
|
2018-04-10 20:36:28 -04:00
|
|
|
|
namespace IW4MAdmin.Plugins.ProfanityDeterment
|
2018-03-29 00:40:57 -04:00
|
|
|
|
{
|
|
|
|
|
public class Plugin : IPlugin
|
|
|
|
|
{
|
2018-04-10 20:36:28 -04:00
|
|
|
|
public string Name => "ProfanityDeterment";
|
2018-03-29 00:40:57 -04:00
|
|
|
|
|
2018-04-10 20:36:28 -04:00
|
|
|
|
public float Version => Assembly.GetExecutingAssembly().GetName().Version.Major + Assembly.GetExecutingAssembly().GetName().Version.Minor / 10.0f;
|
2018-03-29 00:40:57 -04:00
|
|
|
|
|
|
|
|
|
public string Author => "RaidMax";
|
|
|
|
|
|
|
|
|
|
BaseConfigurationHandler<Configuration> Settings;
|
|
|
|
|
|
2018-09-29 15:52:22 -04:00
|
|
|
|
public Task OnEventAsync(GameEvent E, Server S)
|
2018-03-29 00:40:57 -04:00
|
|
|
|
{
|
2018-03-30 00:13:40 -04:00
|
|
|
|
if (!Settings.Configuration().EnableProfanityDeterment)
|
2018-10-03 22:20:49 -04:00
|
|
|
|
return Task.CompletedTask;
|
2018-03-30 00:13:40 -04:00
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
if (E.Type == GameEvent.EventType.Connect)
|
2018-03-29 00:40:57 -04:00
|
|
|
|
{
|
2019-05-13 11:36:11 -04:00
|
|
|
|
E.Origin.SetAdditionalProperty("_profanityInfringements", 0);
|
2018-03-29 00:40:57 -04:00
|
|
|
|
|
2018-04-29 16:44:04 -04:00
|
|
|
|
var objectionalWords = Settings.Configuration().OffensiveWords;
|
2019-08-08 16:30:06 -04:00
|
|
|
|
var matchedFilters = new List<string>();
|
2019-08-10 18:35:34 -04:00
|
|
|
|
bool containsObjectionalWord = false;
|
2018-04-29 16:44:04 -04:00
|
|
|
|
|
2019-08-10 18:35:34 -04:00
|
|
|
|
foreach (string word in objectionalWords)
|
2018-09-04 13:40:29 -04:00
|
|
|
|
{
|
2019-08-10 18:35:34 -04:00
|
|
|
|
if (Regex.IsMatch(E.Origin.Name.ToLower(), word, RegexOptions.IgnoreCase))
|
2018-09-04 13:40:29 -04:00
|
|
|
|
{
|
2019-08-10 18:35:34 -04:00
|
|
|
|
containsObjectionalWord |= true;
|
|
|
|
|
matchedFilters.Add(word);
|
2018-09-04 13:40:29 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-29 16:44:04 -04:00
|
|
|
|
if (containsObjectionalWord)
|
|
|
|
|
{
|
2019-08-06 14:36:37 -04:00
|
|
|
|
var sender = Utilities.IW4MAdminClient(E.Owner);
|
|
|
|
|
sender.AdministeredPenalties = new List<EFPenalty>()
|
|
|
|
|
{
|
|
|
|
|
new EFPenalty()
|
|
|
|
|
{
|
2019-08-08 16:30:06 -04:00
|
|
|
|
AutomatedOffense = $"{E.Origin.Name} - {string.Join(",", matchedFilters)}"
|
2019-08-06 14:36:37 -04:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
E.Origin.Kick(Settings.Configuration().ProfanityKickMessage, sender);
|
2018-04-29 16:44:04 -04:00
|
|
|
|
};
|
2018-03-29 00:40:57 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
if (E.Type == GameEvent.EventType.Disconnect)
|
2018-03-29 00:40:57 -04:00
|
|
|
|
{
|
2019-05-13 11:36:11 -04:00
|
|
|
|
E.Origin.SetAdditionalProperty("_profanityInfringements", 0);
|
2018-03-29 00:40:57 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
if (E.Type == GameEvent.EventType.Say)
|
2018-03-29 00:40:57 -04:00
|
|
|
|
{
|
|
|
|
|
var objectionalWords = Settings.Configuration().OffensiveWords;
|
2018-09-04 13:40:29 -04:00
|
|
|
|
bool containsObjectionalWord = false;
|
2019-08-08 16:30:06 -04:00
|
|
|
|
var matchedFilters = new List<string>();
|
2018-09-04 13:40:29 -04:00
|
|
|
|
|
|
|
|
|
foreach (string word in objectionalWords)
|
|
|
|
|
{
|
2019-08-08 16:30:06 -04:00
|
|
|
|
if (Regex.IsMatch(E.Data.ToLower(), word, RegexOptions.IgnoreCase))
|
2018-09-04 13:40:29 -04:00
|
|
|
|
{
|
2019-08-08 16:30:06 -04:00
|
|
|
|
containsObjectionalWord |= true;
|
|
|
|
|
matchedFilters.Add(word);
|
2018-09-04 13:40:29 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-29 00:40:57 -04:00
|
|
|
|
|
|
|
|
|
if (containsObjectionalWord)
|
|
|
|
|
{
|
2019-05-13 11:36:11 -04:00
|
|
|
|
int profanityInfringments = E.Origin.GetAdditionalProperty<int>("_profanityInfringements");
|
|
|
|
|
|
2019-08-08 16:30:06 -04:00
|
|
|
|
var sender = Utilities.IW4MAdminClient(E.Owner);
|
|
|
|
|
sender.AdministeredPenalties = new List<EFPenalty>()
|
|
|
|
|
{
|
|
|
|
|
new EFPenalty()
|
|
|
|
|
{
|
|
|
|
|
AutomatedOffense = $"{E.Data} - {string.Join(",", matchedFilters)}"
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-13 11:36:11 -04:00
|
|
|
|
if (profanityInfringments >= Settings.Configuration().KickAfterInfringementCount)
|
2018-03-29 00:40:57 -04:00
|
|
|
|
{
|
2019-08-08 16:30:06 -04:00
|
|
|
|
E.Origin.Kick(Settings.Configuration().ProfanityKickMessage, sender);
|
2018-03-29 00:40:57 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-13 11:36:11 -04:00
|
|
|
|
else if (profanityInfringments < Settings.Configuration().KickAfterInfringementCount)
|
2018-03-29 00:40:57 -04:00
|
|
|
|
{
|
2019-05-13 11:36:11 -04:00
|
|
|
|
E.Origin.SetAdditionalProperty("_profanityInfringements", profanityInfringments + 1);
|
2019-08-06 14:36:37 -04:00
|
|
|
|
E.Origin.Warn(Settings.Configuration().ProfanityWarningMessage, sender);
|
2018-03-29 00:40:57 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-29 15:52:22 -04:00
|
|
|
|
return Task.CompletedTask;
|
2018-03-29 00:40:57 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task OnLoadAsync(IManager manager)
|
|
|
|
|
{
|
|
|
|
|
// load custom configuration
|
|
|
|
|
Settings = new BaseConfigurationHandler<Configuration>("ProfanityDetermentSettings");
|
|
|
|
|
if (Settings.Configuration() == null)
|
|
|
|
|
{
|
|
|
|
|
Settings.Set((Configuration)new Configuration().Generate());
|
|
|
|
|
await Settings.Save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 02:13:04 -04:00
|
|
|
|
public Task OnTickAsync(Server S) => Task.CompletedTask;
|
2018-03-29 00:40:57 -04:00
|
|
|
|
|
2018-04-26 02:13:04 -04:00
|
|
|
|
public Task OnUnloadAsync() => Task.CompletedTask;
|
2018-03-29 00:40:57 -04:00
|
|
|
|
}
|
|
|
|
|
}
|