2015-03-08 17:20:10 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-09-29 22:42:24 -04:00
|
|
|
|
using System.Linq;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
using SharedLibrary.Objects;
|
|
|
|
|
|
2015-08-20 01:06:44 -04:00
|
|
|
|
namespace SharedLibrary
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2015-08-20 01:06:44 -04:00
|
|
|
|
public class Event
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
|
|
|
|
public enum GType
|
|
|
|
|
{
|
|
|
|
|
//FROM SERVER
|
2015-08-21 21:11:35 -04:00
|
|
|
|
Start,
|
|
|
|
|
Stop,
|
2015-03-08 17:20:10 -04:00
|
|
|
|
Connect,
|
|
|
|
|
Disconnect,
|
|
|
|
|
Say,
|
|
|
|
|
MapChange,
|
|
|
|
|
MapEnd,
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2015-03-08 17:20:10 -04:00
|
|
|
|
//FROM ADMIN
|
|
|
|
|
Broadcast,
|
|
|
|
|
Tell,
|
|
|
|
|
Kick,
|
2015-08-20 01:06:44 -04:00
|
|
|
|
Ban,
|
2017-05-26 18:49:27 -04:00
|
|
|
|
Remote,
|
2015-03-08 17:20:10 -04:00
|
|
|
|
Unknown,
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
//FROM PLAYER
|
2017-06-19 13:58:01 -04:00
|
|
|
|
Report,
|
2017-09-29 22:42:24 -04:00
|
|
|
|
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;
|
2018-03-13 17:30:22 -04:00
|
|
|
|
Data = d?.Trim();
|
2015-03-08 17:20:10 -04:00
|
|
|
|
Origin = O;
|
|
|
|
|
Target = T;
|
|
|
|
|
Owner = S;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-07 17:08:29 -04:00
|
|
|
|
public static Event ParseEventString(String[] line, Server SV)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-09-29 22:42:24 -04:00
|
|
|
|
string removeTime = Regex.Replace(line[0], @"[0-9]+:[0-9]+\ ", "");
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2017-09-29 22:42:24 -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] + ";");
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-02 12:49:45 -04:00
|
|
|
|
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-09 21:28:37 -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], "");
|
2017-11-16 18:09:19 -05:00
|
|
|
|
return new Event(GType.Say, message.StripColors(), SV.ParseClientFromString(line, 2), null, SV) { Message = message };
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-29 22:42:24 -04:00
|
|
|
|
if (removeTime.Contains("ScriptKill"))
|
|
|
|
|
{
|
2018-02-27 23:19:54 -05:00
|
|
|
|
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);
|
2017-09-29 22:42:24 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (removeTime.Contains("ExitLevel"))
|
2018-03-09 03:01:12 -05:00
|
|
|
|
return new Event(GType.MapEnd, line[0], new Player() { ClientId = 1 }, null, SV);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2017-09-29 22:42:24 -04:00
|
|
|
|
if (removeTime.Contains("InitGame"))
|
2018-03-09 03:01:12 -05:00
|
|
|
|
return new Event(GType.MapChange, line[0], new Player() { ClientId = 1 }, null, SV);
|
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)
|
|
|
|
|
{
|
2017-05-28 16:47:21 -04:00
|
|
|
|
SV.Manager.GetLogger().WriteError("Error requesting event " + E.Message);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
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
|
2017-05-31 01:31:56 -04:00
|
|
|
|
public string Message;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
public Player Origin;
|
|
|
|
|
public Player Target;
|
|
|
|
|
public Server Owner;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public Boolean Remote = false;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|