2015-03-08 17:20:10 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin
|
|
|
|
|
{
|
|
|
|
|
class Event
|
|
|
|
|
{
|
|
|
|
|
public enum GType
|
|
|
|
|
{
|
|
|
|
|
//FROM SERVER
|
|
|
|
|
Connect,
|
|
|
|
|
Disconnect,
|
|
|
|
|
Say,
|
|
|
|
|
Kill,
|
|
|
|
|
Death,
|
|
|
|
|
MapChange,
|
|
|
|
|
MapEnd,
|
|
|
|
|
|
|
|
|
|
//FROM ADMIN
|
|
|
|
|
Broadcast,
|
|
|
|
|
Tell,
|
|
|
|
|
Kick,
|
|
|
|
|
Ban,
|
|
|
|
|
|
|
|
|
|
Unknown,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Event(GType t, string d, Player O, Player T, Server S)
|
|
|
|
|
{
|
|
|
|
|
Type = t;
|
|
|
|
|
Data = d;
|
|
|
|
|
Origin = O;
|
|
|
|
|
Target = T;
|
|
|
|
|
Owner = S;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//This needs to be here
|
|
|
|
|
public Command isValidCMD(List<Command> list)
|
|
|
|
|
{
|
|
|
|
|
if (this.Data.Substring(0, 1) == "!")
|
|
|
|
|
{
|
|
|
|
|
string[] cmd = this.Data.Substring(1, this.Data.Length - 1).Split(' ');
|
|
|
|
|
|
|
|
|
|
foreach (Command C in list)
|
|
|
|
|
{
|
|
|
|
|
if (C.getName() == cmd[0].ToLower() || C.getAlias() == cmd[0].ToLower())
|
|
|
|
|
return C;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Event requestEvent(String[] line, Server SV)
|
|
|
|
|
{
|
2015-03-14 12:42:36 -04:00
|
|
|
|
#if DEBUG == false
|
2015-03-08 17:20:10 -04:00
|
|
|
|
try
|
2015-03-14 12:42:36 -04:00
|
|
|
|
#endif
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
|
|
|
|
String eventType = line[0].Substring(line[0].Length - 1);
|
|
|
|
|
eventType = eventType.Trim();
|
|
|
|
|
|
|
|
|
|
if (eventType == "J")
|
|
|
|
|
return new Event(GType.Connect, null, SV.clientFromLine(line, 3, true), null, SV);
|
|
|
|
|
|
|
|
|
|
if (eventType == "Q")
|
2015-03-16 16:40:30 -04:00
|
|
|
|
return new Event(GType.Disconnect, null, SV.getPlayers()[Convert.ToInt16(line[2])], null, null);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2015-03-09 21:28:37 -04:00
|
|
|
|
if (eventType == "K")
|
2015-03-16 16:40:30 -04:00
|
|
|
|
return new Event(GType.Kill, line[9], SV.clientFromLineArr(line, true), SV.clientFromLineArr(line, false), null);
|
2015-03-09 21:28:37 -04:00
|
|
|
|
|
2015-03-08 17:20:10 -04:00
|
|
|
|
if (line[0].Substring(line[0].Length - 3).Trim() == "say")
|
|
|
|
|
{
|
2015-03-09 21:28:37 -04:00
|
|
|
|
if (line.Length < 4)
|
|
|
|
|
{
|
2015-03-14 12:42:36 -04:00
|
|
|
|
Console.WriteLine("SAY FUCKED UP BIG-TIME");
|
2015-03-09 21:28:37 -04:00
|
|
|
|
return null;
|
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
Regex rgx = new Regex("[^a-zA-Z0-9 -! -_]");
|
|
|
|
|
string message = rgx.Replace(line[4], "");
|
|
|
|
|
return new Event(GType.Say, Utilities.removeNastyChars(message), SV.clientFromLine(line, 3, false), null, null);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-10 16:45:20 -04:00
|
|
|
|
if (eventType == ":")
|
2015-03-08 17:20:10 -04:00
|
|
|
|
return new Event(GType.MapEnd, null, null, null, null);
|
|
|
|
|
|
|
|
|
|
if (line[0].Length > 400) // blaze it
|
2015-03-10 16:45:20 -04:00
|
|
|
|
return new Event(GType.MapChange, line[0], null, null, null);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2015-03-14 12:42:36 -04:00
|
|
|
|
#if DEBUG == false
|
2015-03-08 17:20:10 -04:00
|
|
|
|
catch (Exception E)
|
|
|
|
|
{
|
|
|
|
|
SV.Log.Write("Error requesting event " + E.Message, Log.Level.Debug);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2015-03-14 12:42:36 -04:00
|
|
|
|
#endif
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public GType Type;
|
|
|
|
|
public string Data; // Data is usually the message sent by player
|
|
|
|
|
public Player Origin;
|
|
|
|
|
public Player Target;
|
|
|
|
|
public Server Owner;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|