2017-05-26 18:49:27 -04:00
using System ;
using System.Collections.Generic ;
2017-11-25 20:29:58 -05:00
using System.Threading.Tasks ;
2017-05-26 18:49:27 -04:00
using SharedLibrary ;
2017-05-27 00:22:50 -04:00
using SharedLibrary.Interfaces ;
2017-11-25 20:29:58 -05:00
using SharedLibrary.Objects ;
2017-05-26 18:49:27 -04:00
namespace EventAPI
{
class Events : IPlugin
{
2017-06-12 13:50:00 -04:00
public static Queue < RestEvent > APIEvents { get ; private set ; }
public static List < Server > ActiveServers ;
2017-05-26 18:49:27 -04:00
DateTime lastClear ;
int flaggedMessages ;
List < string > flaggedMessagesText ;
2017-11-15 16:04:13 -05:00
public String Name = > "Event API Plugin" ;
2017-05-26 18:49:27 -04:00
2017-11-15 16:04:13 -05:00
public float Version = > 1.0f ;
2017-05-26 18:49:27 -04:00
2017-11-15 16:04:13 -05:00
public string Author = > "RaidMax" ;
2017-05-26 18:49:27 -04:00
2017-10-16 23:47:41 -04:00
public async Task OnLoadAsync ( IManager manager )
2017-05-26 18:49:27 -04:00
{
2017-06-12 13:50:00 -04:00
APIEvents = new Queue < RestEvent > ( ) ;
2017-05-26 18:49:27 -04:00
flaggedMessagesText = new List < string > ( ) ;
2017-06-12 13:50:00 -04:00
ActiveServers = new List < Server > ( ) ;
2017-05-26 18:49:27 -04:00
}
2017-06-13 18:33:47 -04:00
public async Task OnUnloadAsync ( )
2017-05-26 18:49:27 -04:00
{
2017-06-12 13:50:00 -04:00
APIEvents . Clear ( ) ;
ActiveServers . Clear ( ) ;
2017-05-26 18:49:27 -04:00
}
2017-05-27 18:08:04 -04:00
public async Task OnTickAsync ( Server S )
2017-05-26 18:49:27 -04:00
{
return ;
}
2017-05-27 18:08:04 -04:00
public async Task OnEventAsync ( Event E , Server S )
2017-05-26 18:49:27 -04:00
{
if ( E . Type = = Event . GType . Start )
{
2017-06-12 13:50:00 -04:00
ActiveServers . Add ( S ) ;
2017-05-26 18:49:27 -04:00
}
if ( E . Type = = Event . GType . Stop )
{
2018-02-26 23:24:19 -05:00
ActiveServers . RemoveAll ( s = > s . GetHashCode ( ) = = S . GetHashCode ( ) ) ;
2017-05-26 18:49:27 -04:00
}
if ( E . Type = = Event . GType . Connect )
{
2017-06-12 13:50:00 -04:00
AddRestEvent ( new RestEvent ( RestEvent . EventType . NOTIFICATION , RestEvent . EventVersion . IW4MAdmin , E . Origin . Name + " has joined " + S . Hostname , E . Type . ToString ( ) , S . Hostname , E . Origin . Name ) ) ;
2017-05-26 18:49:27 -04:00
}
if ( E . Type = = Event . GType . Disconnect )
{
2017-06-12 13:50:00 -04:00
AddRestEvent ( new RestEvent ( RestEvent . EventType . NOTIFICATION , RestEvent . EventVersion . IW4MAdmin , E . Origin . Name + " has left " + S . Hostname , E . Type . ToString ( ) , S . Hostname , E . Origin . Name ) ) ;
2017-05-26 18:49:27 -04:00
}
if ( E . Type = = Event . GType . Say )
{
if ( E . Data . Length ! = 0 & & E . Data [ 0 ] ! = '!' )
2017-06-12 13:50:00 -04:00
AddRestEvent ( new RestEvent ( RestEvent . EventType . NOTIFICATION , RestEvent . EventVersion . IW4MAdmin , E . Data , "Chat" , E . Origin . Name , "" ) ) ;
2017-05-26 18:49:27 -04:00
}
2017-11-13 16:58:23 -05:00
if ( E . Type = = Event . GType . Report )
{
AddRestEvent ( new RestEvent ( RestEvent . EventType . ALERT , RestEvent . EventVersion . IW4MAdmin , $"**{E.Origin.Name}** has reported **{E.Target.Name}** for: {E.Data.Trim()}" , E . Target . Name , E . Origin . Name , "" ) ) ;
}
2017-05-26 18:49:27 -04:00
if ( E . Type = = Event . GType . Say & & E . Origin . Level < Player . Permission . Moderator )
{
string message = E . Data . ToLower ( ) ;
2017-11-02 12:49:45 -04:00
bool flagged = message . Contains ( " wh " ) | |
2017-11-13 16:58:23 -05:00
message . Contains ( "hax" ) | |
message . Contains ( "cheat" ) | |
message . Contains ( " hack " ) | |
message . Contains ( "aim" ) | |
message . Contains ( "wall" ) | |
2017-11-02 12:49:45 -04:00
message . Contains ( "cheto" ) | |
2017-11-13 16:58:23 -05:00
message . Contains ( "hak" ) | |
2018-03-09 03:01:12 -05:00
message . Contains ( " bot " ) ;
2017-05-26 18:49:27 -04:00
if ( flagged )
{
flaggedMessages + + ;
flaggedMessagesText . Add ( String . Format ( "{0}: {1}" , E . Origin . Name , E . Data ) ) ;
}
if ( flaggedMessages > 3 )
{
await E . Owner . Broadcast ( "If you suspect someone of ^5CHEATING ^7use the ^5!report ^7command" ) ;
2017-06-12 13:50:00 -04:00
AddRestEvent ( new RestEvent ( RestEvent . EventType . ALERT , RestEvent . EventVersion . IW4MAdmin , "Chat indicates there may be a cheater" , "Alert" , E . Owner . Hostname , "" ) ) ;
AddRestEvent ( new RestEvent ( RestEvent . EventType . NOTIFICATION , RestEvent . EventVersion . IW4MAdmin , String . Join ( "\n" , flaggedMessagesText ) , "Chat Monitor" , E . Owner . Hostname , "" ) ) ;
2017-05-26 18:49:27 -04:00
flaggedMessages = 0 ;
}
else if ( ( DateTime . Now - lastClear ) . TotalMinutes > = 3 )
{
flaggedMessages = 0 ;
flaggedMessagesText . Clear ( ) ;
lastClear = DateTime . Now ;
}
}
}
2017-06-12 13:50:00 -04:00
public static void AddRestEvent ( RestEvent E )
2017-05-26 18:49:27 -04:00
{
2017-11-13 16:58:23 -05:00
if ( APIEvents . Count > 20 )
2017-06-12 13:50:00 -04:00
APIEvents . Dequeue ( ) ;
APIEvents . Enqueue ( E ) ;
2017-05-26 18:49:27 -04:00
}
}
}