IW4M-Admin/Application/API/EventAPI.cs

76 lines
2.3 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using SharedLibraryCore;
2018-04-08 02:44:42 -04:00
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Interfaces;
2018-04-08 02:44:42 -04:00
using SharedLibraryCore.Objects;
2018-03-09 03:01:12 -05:00
namespace IW4MAdmin.Application.API
2018-03-09 03:01:12 -05:00
{
class EventApi : IEventApi
2018-03-09 03:01:12 -05:00
{
Queue<EventInfo> Events = new Queue<EventInfo>();
DateTime LastFlagEvent;
2018-03-09 03:01:12 -05:00
static string[] FlaggedMessageContains =
{
" wh ",
"hax",
"cheat",
" hack ",
"aim",
"wall",
"cheto",
"hak",
"bot"
};
int FlaggedMessageCount;
public Queue<EventInfo> GetEvents() => Events;
2018-03-09 03:01:12 -05:00
public void OnServerEvent(object sender, GameEvent E)
2018-03-09 03:01:12 -05:00
{
if (E.Type == GameEvent.EventType.Say && E.Origin.Level < Player.Permission.Trusted)
2018-03-09 03:01:12 -05:00
{
bool flaggedMessage = false;
foreach (string msg in FlaggedMessageContains)
flaggedMessage = flaggedMessage ? flaggedMessage : E.Data.ToLower().Contains(msg);
if (flaggedMessage)
FlaggedMessageCount++;
if (FlaggedMessageCount > 3)
{
if (Events.Count > 20)
Events.Dequeue();
FlaggedMessageCount = 0;
E.Owner.Broadcast(Utilities.CurrentLocalization.LocalizationIndex["GLOBAL_REPORT"]).Wait(5000);
2018-04-08 02:44:42 -04:00
Events.Enqueue(new EventInfo(
EventInfo.EventType.ALERT,
EventInfo.EventVersion.IW4MAdmin,
2018-03-09 03:01:12 -05:00
"Chat indicates there may be a cheater",
"Alert",
E.Owner.Hostname, ""));
}
if ((DateTime.UtcNow - LastFlagEvent).Minutes >= 3)
{
FlaggedMessageCount = 0;
LastFlagEvent = DateTime.Now;
}
}
if (E.Type == GameEvent.EventType.Report)
2018-03-09 03:01:12 -05:00
{
2018-04-08 02:44:42 -04:00
Events.Enqueue(new EventInfo(
EventInfo.EventType.ALERT,
EventInfo.EventVersion.IW4MAdmin,
2018-03-09 03:01:12 -05:00
$"**{E.Origin.Name}** has reported **{E.Target.Name}** for: {E.Data.Trim()}",
E.Target.Name, E.Origin.Name, ""));
}
}
}
}