IW4M-Admin/SharedLibrary/Event.cs

165 lines
4.3 KiB
C#
Raw Normal View History

2015-03-08 17:20:10 -04:00
using System;
using System.Collections.Generic;
using System.Linq;
2015-03-08 17:20:10 -04:00
using System.Text;
using System.Text.RegularExpressions;
using SharedLibrary.Objects;
namespace SharedLibrary
2015-03-08 17:20:10 -04:00
{
[Serializable]
public class Chat
{
public Chat(string O, String M, DateTime D)
{
Name = O;
Message = M;
Time = D;
}
public String Message { get; private set; }
public DateTime Time { get; private set; }
public string Name;
}
[Serializable]
public struct RestEvent
{
public RestEvent(EventType Ty, EventVersion V, string M, string T, string O, string Ta)
{
Type = Ty;
Version = V;
Message = System.Web.HttpUtility.HtmlEncode(M);
Title = T;
Origin = System.Web.HttpUtility.HtmlEncode(O);
Target = System.Web.HttpUtility.HtmlEncode(Ta);
ID = Math.Abs(DateTime.Now.GetHashCode());
}
public enum EventType
{
NOTIFICATION,
STATUS,
ALERT,
}
public enum EventVersion
{
IW4MAdmin
}
public EventType Type;
public EventVersion Version;
public string Message;
public string Title;
public string Origin;
public string Target;
public int ID;
}
public class Event
2015-03-08 17:20:10 -04:00
{
public enum GType
{
//FROM SERVER
Start,
Stop,
2015-03-08 17:20:10 -04:00
Connect,
Disconnect,
Say,
MapChange,
MapEnd,
2015-03-08 17:20:10 -04:00
//FROM ADMIN
Broadcast,
Tell,
Kick,
Ban,
Remote,
2015-03-08 17:20:10 -04:00
Unknown,
//FROM PLAYER
Report,
Flag,
// FROM GAME
Script,
Kill,
Death,
2015-03-08 17:20:10 -04:00
}
public Event(GType t, string d, Player O, Player T, Server S)
{
Type = t;
Data = d.Trim();
2015-03-08 17:20:10 -04:00
Origin = O;
Target = T;
Owner = S;
}
public static Event ParseEventString(String[] line, Server SV)
2015-03-08 17:20:10 -04:00
{
#if DEBUG == false
2015-03-08 17:20:10 -04:00
try
#endif
2015-03-08 17:20:10 -04:00
{
string removeTime = Regex.Replace(line[0], @"[0-9]+:[0-9]+\ ", "");
2015-03-08 17:20:10 -04:00
if (removeTime[0] == 'K')
2015-08-20 15:23:13 -04:00
{
StringBuilder Data = new StringBuilder();
if (line.Length > 9)
{
for (int i = 9; i < line.Length; i++)
Data.Append(line[i] + ";");
}
if (!SV.CustomCallback)
return new Event(GType.Script, Data.ToString(), SV.ParseClientFromString(line, 6), SV.ParseClientFromString(line, 2), SV);
2015-08-20 15:23:13 -04:00
}
2015-03-08 17:20:10 -04:00
if (line[0].Substring(line[0].Length - 3).Trim() == "say")
{
Regex rgx = new Regex("[^a-zA-Z0-9 -! -_]");
string message = rgx.Replace(line[4], "");
return new Event(GType.Say, message.StripColors(), SV.ParseClientFromString(line, 2), null, SV) { Message = message };
2015-03-08 17:20:10 -04:00
}
if (removeTime.Contains("ScriptKill"))
{
return new Event(GType.Script, String.Join(";", line), SV.Players.First(p => p != null && p.NetworkId == line[1].ConvertLong()), SV.Players.First(p => p != null && p.NetworkId == line[2].ConvertLong()), SV);
}
if (removeTime.Contains("ExitLevel"))
return new Event(GType.MapEnd, line[0], null, null, SV);
2015-03-08 17:20:10 -04:00
if (removeTime.Contains("InitGame"))
return new Event(GType.MapChange, line[0], null, null, SV);
2015-03-08 17:20:10 -04:00
return null;
}
#if DEBUG == false
2015-03-08 17:20:10 -04:00
catch (Exception E)
{
SV.Manager.GetLogger().WriteError("Error requesting event " + E.Message);
2015-03-08 17:20:10 -04:00
return null;
}
#endif
2015-03-08 17:20:10 -04:00
}
public GType Type;
public string Data; // Data is usually the message sent by player
public string Message;
2015-03-08 17:20:10 -04:00
public Player Origin;
public Player Target;
public Server Owner;
public Boolean Remote = false;
2015-03-08 17:20:10 -04:00
}
}