2015-03-08 16:20:10 -05:00
|
|
|
|
using System;
|
2018-04-26 01:13:04 -05:00
|
|
|
|
using System.Threading;
|
2018-04-08 01:44:42 -05:00
|
|
|
|
using SharedLibraryCore.Objects;
|
2017-11-25 19:29:58 -06:00
|
|
|
|
|
2018-04-08 01:44:42 -05:00
|
|
|
|
namespace SharedLibraryCore
|
2015-03-08 16:20:10 -05:00
|
|
|
|
{
|
2018-04-13 01:32:30 -05:00
|
|
|
|
public class GameEvent
|
2015-03-08 16:20:10 -05:00
|
|
|
|
{
|
2018-04-13 01:32:30 -05:00
|
|
|
|
public enum EventType
|
2015-03-08 16:20:10 -05:00
|
|
|
|
{
|
2018-06-16 21:11:25 -05:00
|
|
|
|
Unknown,
|
2018-07-04 21:09:42 -05:00
|
|
|
|
|
2018-06-16 21:11:25 -05:00
|
|
|
|
// events "generated" by the server
|
2015-08-21 20:11:35 -05:00
|
|
|
|
Start,
|
|
|
|
|
Stop,
|
2015-03-08 16:20:10 -05:00
|
|
|
|
Connect,
|
2018-04-28 20:11:13 -05:00
|
|
|
|
Join,
|
2018-06-16 21:11:25 -05:00
|
|
|
|
Quit,
|
2015-03-08 16:20:10 -05:00
|
|
|
|
Disconnect,
|
|
|
|
|
MapEnd,
|
2018-06-16 21:11:25 -05:00
|
|
|
|
MapChange,
|
2015-08-20 00:06:44 -05:00
|
|
|
|
|
2018-06-16 21:11:25 -05:00
|
|
|
|
// events "generated" by clients
|
|
|
|
|
Say,
|
2017-06-19 13:58:01 -04:00
|
|
|
|
Report,
|
2017-09-29 21:42:24 -05:00
|
|
|
|
Flag,
|
2018-06-16 21:11:25 -05:00
|
|
|
|
Unflag,
|
|
|
|
|
Kick,
|
|
|
|
|
TempBan,
|
|
|
|
|
Ban,
|
2018-04-13 23:51:38 -05:00
|
|
|
|
Command,
|
2017-09-29 21:42:24 -05:00
|
|
|
|
|
2018-06-16 21:11:25 -05:00
|
|
|
|
// events "generated" by IW4MAdmin
|
|
|
|
|
Broadcast,
|
|
|
|
|
Tell,
|
|
|
|
|
|
|
|
|
|
// events "generated" by script/log
|
2018-05-07 23:58:46 -05:00
|
|
|
|
ScriptDamage,
|
2018-05-10 00:34:29 -05:00
|
|
|
|
ScriptKill,
|
2018-04-15 20:27:43 -05:00
|
|
|
|
Damage,
|
2018-06-16 21:11:25 -05:00
|
|
|
|
Kill,
|
2018-06-05 16:31:36 -05:00
|
|
|
|
JoinTeam,
|
2015-03-08 16:20:10 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 01:32:30 -05:00
|
|
|
|
public GameEvent(EventType t, string d, Player O, Player T, Server S)
|
2015-03-08 16:20:10 -05:00
|
|
|
|
{
|
|
|
|
|
Type = t;
|
2018-03-13 16:30:22 -05:00
|
|
|
|
Data = d?.Trim();
|
2015-03-08 16:20:10 -05:00
|
|
|
|
Origin = O;
|
|
|
|
|
Target = T;
|
|
|
|
|
Owner = S;
|
2018-04-26 01:13:04 -05:00
|
|
|
|
OnProcessed = new ManualResetEventSlim();
|
2018-05-03 00:25:49 -05:00
|
|
|
|
Time = DateTime.UtcNow;
|
2018-05-10 00:34:29 -05:00
|
|
|
|
CurrentEventId++;
|
|
|
|
|
Id = CurrentEventId;
|
2015-03-08 16:20:10 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 01:13:04 -05:00
|
|
|
|
public GameEvent()
|
|
|
|
|
{
|
2018-05-03 00:25:49 -05:00
|
|
|
|
OnProcessed = new ManualResetEventSlim();
|
|
|
|
|
Time = DateTime.UtcNow;
|
2018-05-10 00:34:29 -05:00
|
|
|
|
CurrentEventId++;
|
|
|
|
|
Id = CurrentEventId;
|
2018-04-26 01:13:04 -05:00
|
|
|
|
}
|
2015-03-08 16:20:10 -05:00
|
|
|
|
|
2018-05-10 00:34:29 -05:00
|
|
|
|
private static long CurrentEventId;
|
2018-04-28 16:39:45 -05:00
|
|
|
|
|
2018-04-13 01:32:30 -05:00
|
|
|
|
public EventType Type;
|
2015-03-08 16:20:10 -05:00
|
|
|
|
public string Data; // Data is usually the message sent by player
|
2017-05-31 00:31:56 -05:00
|
|
|
|
public string Message;
|
2015-03-08 16:20:10 -05:00
|
|
|
|
public Player Origin;
|
|
|
|
|
public Player Target;
|
|
|
|
|
public Server Owner;
|
2017-05-26 17:49:27 -05:00
|
|
|
|
public Boolean Remote = false;
|
2018-04-13 23:51:38 -05:00
|
|
|
|
public object Extra { get; set; }
|
2018-04-28 16:39:45 -05:00
|
|
|
|
public ManualResetEventSlim OnProcessed { get; set; }
|
2018-05-03 00:25:49 -05:00
|
|
|
|
public DateTime Time { get; private set; }
|
2018-05-10 00:34:29 -05:00
|
|
|
|
public long Id { get; private set; }
|
2018-07-04 21:09:42 -05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// determine whether an event should be delayed or not
|
|
|
|
|
/// applies only to the origin entity
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="queuedEvent">event to determine status for</param>
|
|
|
|
|
/// <returns>true if event should be delayed, false otherwise</returns>
|
|
|
|
|
public static bool ShouldOriginEventBeDelayed(GameEvent queuedEvent)
|
|
|
|
|
{
|
|
|
|
|
return queuedEvent.Origin != null &&
|
|
|
|
|
!queuedEvent.Origin.IsAuthenticated &&
|
|
|
|
|
// we want to allow join and quit events
|
|
|
|
|
queuedEvent.Type != EventType.Join &&
|
|
|
|
|
queuedEvent.Type != EventType.Quit &&
|
|
|
|
|
// we don't care about unknown events
|
|
|
|
|
queuedEvent.Origin.NetworkId != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// determine whether an event should be delayed or not
|
|
|
|
|
/// applies only to the target entity
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="queuedEvent">event to determine status for</param>
|
|
|
|
|
/// <returns>true if event should be delayed, false otherwise</returns>
|
|
|
|
|
public static bool ShouldTargetEventBeDelayed(GameEvent queuedEvent)
|
|
|
|
|
{
|
|
|
|
|
return queuedEvent.Target != null &&
|
|
|
|
|
!queuedEvent.Target.IsAuthenticated &&
|
|
|
|
|
queuedEvent.Target.NetworkId != 0;
|
|
|
|
|
}
|
2015-03-08 16:20:10 -05:00
|
|
|
|
}
|
|
|
|
|
}
|