2015-03-08 16:20:10 -05:00
|
|
|
|
using System;
|
2018-04-26 01:13:04 -05:00
|
|
|
|
using System.Threading;
|
2018-09-06 13:25:58 -05:00
|
|
|
|
using System.Threading.Tasks;
|
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,
|
2018-09-02 21:25:09 -05:00
|
|
|
|
Warn,
|
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,
|
2018-08-27 17:07:54 -05:00
|
|
|
|
|
|
|
|
|
StatusUpdate
|
2015-03-08 16:20:10 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-30 20:53:00 -05:00
|
|
|
|
static long NextEventId;
|
|
|
|
|
static long GetNextEventId() => Interlocked.Increment(ref NextEventId);
|
2015-03-08 16:20:10 -05:00
|
|
|
|
|
2018-04-26 01:13:04 -05:00
|
|
|
|
public GameEvent()
|
|
|
|
|
{
|
2018-09-07 22:29:42 -05:00
|
|
|
|
OnProcessed = new ManualResetEventSlim(false);
|
2018-05-03 00:25:49 -05:00
|
|
|
|
Time = DateTime.UtcNow;
|
2018-08-30 20:53:00 -05:00
|
|
|
|
Id = GetNextEventId();
|
2018-04-26 01:13:04 -05:00
|
|
|
|
}
|
2015-03-08 16:20:10 -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-09-06 13:25:58 -05:00
|
|
|
|
public ManualResetEventSlim OnProcessed { get; set; }
|
2018-08-30 20:53:00 -05:00
|
|
|
|
public DateTime Time { get; set; }
|
2018-05-10 00:34:29 -05:00
|
|
|
|
public long Id { get; private set; }
|
2018-07-04 21:09:42 -05:00
|
|
|
|
|
2018-09-06 13:25:58 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// asynchronously wait for GameEvent to be processed
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>waitable task </returns>
|
|
|
|
|
public Task<bool> WaitAsync(int timeOut = int.MaxValue) => Task.FromResult(OnProcessed.Wait(timeOut));
|
|
|
|
|
|
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 &&
|
2018-08-26 19:20:47 -05:00
|
|
|
|
queuedEvent.Origin.State != Player.ClientState.Connected &&
|
2018-07-04 21:09:42 -05:00
|
|
|
|
// we want to allow join and quit events
|
2018-08-27 17:07:54 -05:00
|
|
|
|
queuedEvent.Type != EventType.Connect &&
|
2018-07-04 21:09:42 -05:00
|
|
|
|
queuedEvent.Type != EventType.Join &&
|
|
|
|
|
queuedEvent.Type != EventType.Quit &&
|
2018-08-28 16:32:59 -05:00
|
|
|
|
queuedEvent.Type != EventType.Disconnect &&
|
2018-07-04 21:09:42 -05:00
|
|
|
|
// 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 &&
|
2018-08-26 19:20:47 -05:00
|
|
|
|
queuedEvent.Target.State != Player.ClientState.Connected &&
|
2018-07-04 21:09:42 -05:00
|
|
|
|
queuedEvent.Target.NetworkId != 0;
|
|
|
|
|
}
|
2018-09-07 22:29:42 -05:00
|
|
|
|
|
|
|
|
|
public static bool IsEventTimeSensitive(GameEvent gameEvent) => gameEvent.Type == EventType.Connect;
|
2015-03-08 16:20:10 -05:00
|
|
|
|
}
|
|
|
|
|
}
|