IW4M-Admin/WebfrontCore/Application/API/EventAPI.cs

72 lines
2.3 KiB
C#
Raw Normal View History

2018-04-08 02:44:42 -04:00
using SharedLibraryCore;
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Objects;
2018-03-09 03:01:12 -05:00
using System;
using System.Collections.Generic;
namespace WebfrontCore.Application.API
{
class EventAPI
{
2018-04-08 02:44:42 -04:00
public static Queue<EventInfo> Events = new Queue<EventInfo>();
2018-03-09 03:01:12 -05:00
static DateTime LastFlagEvent;
static string[] FlaggedMessageContains =
{
" wh ",
"hax",
"cheat",
" hack ",
"aim",
"wall",
"cheto",
"hak",
"bot"
};
static int FlaggedMessageCount;
public static void OnServerEventOccurred(object sender, Event E)
{
2018-04-08 02:44:42 -04:00
if (E.Type == Event.GType.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("If you suspect someone of ^5CHEATING ^7use the ^5!report ^7command").Wait();
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 == Event.GType.Report)
{
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, ""));
}
}
}
}