2015-03-08 17:20:10 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
2015-08-20 01:06:44 -04:00
|
|
|
|
namespace SharedLibrary
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
[Serializable]
|
2015-08-20 01:06:44 -04:00
|
|
|
|
public class Chat
|
2015-04-19 14:14:30 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public Chat(string O, String M, DateTime D)
|
2015-04-19 14:14:30 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
Name = O;
|
2015-04-19 14:14:30 -04:00
|
|
|
|
Message = M;
|
|
|
|
|
Time = D;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2015-04-19 14:14:30 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String timeString()
|
|
|
|
|
{
|
|
|
|
|
return Time.ToShortTimeString();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
//public Player Origin { get; private set; }
|
2015-04-19 14:14:30 -04:00
|
|
|
|
public String Message { get; private set; }
|
|
|
|
|
public DateTime Time { get; private set; }
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public string Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
public struct RestEvent
|
|
|
|
|
{
|
|
|
|
|
public RestEvent(eType Ty, eVersion V, string M, string T, string O, string Ta)
|
|
|
|
|
{
|
|
|
|
|
Type = Ty;
|
|
|
|
|
Version = V;
|
|
|
|
|
Message = M;
|
|
|
|
|
Title = T;
|
|
|
|
|
Origin = O;
|
|
|
|
|
Target = Ta;
|
|
|
|
|
|
|
|
|
|
ID = Math.Abs(DateTime.Now.GetHashCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum eType
|
|
|
|
|
{
|
|
|
|
|
NOTIFICATION,
|
|
|
|
|
STATUS,
|
|
|
|
|
ALERT,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum eVersion
|
|
|
|
|
{
|
|
|
|
|
IW4MAdmin
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public eType Type;
|
|
|
|
|
public eVersion Version;
|
|
|
|
|
public string Message;
|
|
|
|
|
public string Title;
|
|
|
|
|
public string Origin;
|
|
|
|
|
public string Target;
|
|
|
|
|
public int ID;
|
2015-04-19 14:14:30 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -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,
|
|
|
|
|
Kill,
|
|
|
|
|
Death,
|
|
|
|
|
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
|
|
|
|
|
Report
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Event(GType t, string d, Player O, Player T, Server S)
|
|
|
|
|
{
|
|
|
|
|
Type = t;
|
|
|
|
|
Data = d;
|
|
|
|
|
Origin = O;
|
|
|
|
|
Target = T;
|
|
|
|
|
Owner = S;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Command isValidCMD(List<Command> list)
|
|
|
|
|
{
|
2015-08-22 02:04:30 -04:00
|
|
|
|
string[] cmd = this.Data.Substring(1, this.Data.Length - 1).Split(' ');
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2015-08-22 02:04:30 -04:00
|
|
|
|
foreach (Command C in list)
|
|
|
|
|
{
|
|
|
|
|
if (C.Name == cmd[0].ToLower() || C.Alias == cmd[0].ToLower())
|
|
|
|
|
return C;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-22 02:04:30 -04:00
|
|
|
|
return null;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
2015-03-09 21:28:37 -04:00
|
|
|
|
if (eventType == "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] + ";");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Event(GType.Kill, Data.ToString(), SV.clientFromEventLine(line, 6), SV.clientFromEventLine(line, 2), SV);
|
|
|
|
|
}
|
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], "");
|
2015-04-10 00:02:12 -04:00
|
|
|
|
return new Event(GType.Say, Utilities.removeNastyChars(message), SV.clientFromEventLine(line, 2), null, SV);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-20 01:06:44 -04:00
|
|
|
|
if (eventType == ":")
|
2015-08-20 15:23:13 -04:00
|
|
|
|
return new Event(GType.MapEnd, line[0], new Player("WORLD", "WORLD", 0, 0), null, SV);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (line[0].Contains("InitGame")) // blaze it
|
2015-08-20 15:23:13 -04:00
|
|
|
|
return new Event(GType.MapChange, line[0], new Player("WORLD", "WORLD", 0, 0), 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)
|
|
|
|
|
{
|
|
|
|
|
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;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public Boolean Remote = false;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|