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;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
using Data.Models;
|
2018-04-10 20:36:28 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
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";
|
|
|
|
|
|
2020-02-11 17:44:06 -05:00
|
|
|
|
private readonly IConfigurationHandler<Configuration> _configHandler;
|
|
|
|
|
|
|
|
|
|
public Plugin(IConfigurationHandlerFactory configurationHandlerFactory)
|
|
|
|
|
{
|
|
|
|
|
_configHandler = configurationHandlerFactory.GetConfigurationHandler<Configuration>("ProfanityDetermentSettings");
|
|
|
|
|
}
|
2018-03-29 00:40:57 -04:00
|
|
|
|
|
2018-09-29 15:52:22 -04:00
|
|
|
|
public Task OnEventAsync(GameEvent E, Server S)
|
2018-03-29 00:40:57 -04:00
|
|
|
|
{
|
2020-02-11 17:44:06 -05:00
|
|
|
|
if (!_configHandler.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
|
|
|
|
|
2020-02-11 17:44:06 -05:00
|
|
|
|
var objectionalWords = _configHandler.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
|
|
|
|
}
|
|
|
|
|
};
|
2020-02-11 17:44:06 -05:00
|
|
|
|
E.Origin.Kick(_configHandler.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
|
|
|
|
{
|
2020-02-11 17:44:06 -05:00
|
|
|
|
var objectionalWords = _configHandler.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)}"
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-11 17:44:06 -05:00
|
|
|
|
if (profanityInfringments >= _configHandler.Configuration().KickAfterInfringementCount)
|
2018-03-29 00:40:57 -04:00
|
|
|
|
{
|
2020-02-11 17:44:06 -05:00
|
|
|
|
E.Origin.Kick(_configHandler.Configuration().ProfanityKickMessage, sender);
|
2018-03-29 00:40:57 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 17:44:06 -05:00
|
|
|
|
else if (profanityInfringments < _configHandler.Configuration().KickAfterInfringementCount)
|
2018-03-29 00:40:57 -04:00
|
|
|
|
{
|
2019-05-13 11:36:11 -04:00
|
|
|
|
E.Origin.SetAdditionalProperty("_profanityInfringements", profanityInfringments + 1);
|
2020-02-11 17:44:06 -05:00
|
|
|
|
E.Origin.Warn(_configHandler.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)
|
|
|
|
|
{
|
2022-01-28 10:35:01 -05:00
|
|
|
|
await _configHandler.BuildAsync();
|
2020-02-11 17:44:06 -05:00
|
|
|
|
if (_configHandler.Configuration() == null)
|
2018-03-29 00:40:57 -04:00
|
|
|
|
{
|
2020-02-11 17:44:06 -05:00
|
|
|
|
_configHandler.Set((Configuration)new Configuration().Generate());
|
|
|
|
|
await _configHandler.Save();
|
2018-03-29 00:40:57 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|