2015-03-08 17:20:10 -04:00
|
|
|
|
using System;
|
2018-04-26 02:13:04 -04:00
|
|
|
|
using System.Threading;
|
2018-09-06 14:25:58 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore.Objects;
|
2017-11-25 20:29:58 -05:00
|
|
|
|
|
2018-04-08 02:44:42 -04:00
|
|
|
|
namespace SharedLibraryCore
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2018-04-13 02:32:30 -04:00
|
|
|
|
public class GameEvent
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2018-04-13 02:32:30 -04:00
|
|
|
|
public enum EventType
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2018-06-16 22:11:25 -04:00
|
|
|
|
Unknown,
|
2018-07-04 22:09:42 -04:00
|
|
|
|
|
2018-06-16 22:11:25 -04:00
|
|
|
|
// events "generated" by the server
|
2015-08-21 21:11:35 -04:00
|
|
|
|
Start,
|
|
|
|
|
Stop,
|
2015-03-08 17:20:10 -04:00
|
|
|
|
Connect,
|
2018-04-28 21:11:13 -04:00
|
|
|
|
Join,
|
2018-06-16 22:11:25 -04:00
|
|
|
|
Quit,
|
2015-03-08 17:20:10 -04:00
|
|
|
|
Disconnect,
|
|
|
|
|
MapEnd,
|
2018-06-16 22:11:25 -04:00
|
|
|
|
MapChange,
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2018-06-16 22:11:25 -04:00
|
|
|
|
// events "generated" by clients
|
|
|
|
|
Say,
|
2018-09-02 22:25:09 -04:00
|
|
|
|
Warn,
|
2017-06-19 13:58:01 -04:00
|
|
|
|
Report,
|
2017-09-29 22:42:24 -04:00
|
|
|
|
Flag,
|
2018-06-16 22:11:25 -04:00
|
|
|
|
Unflag,
|
|
|
|
|
Kick,
|
|
|
|
|
TempBan,
|
|
|
|
|
Ban,
|
2018-04-14 00:51:38 -04:00
|
|
|
|
Command,
|
2017-09-29 22:42:24 -04:00
|
|
|
|
|
2018-06-16 22:11:25 -04:00
|
|
|
|
// events "generated" by IW4MAdmin
|
|
|
|
|
Broadcast,
|
|
|
|
|
Tell,
|
|
|
|
|
|
|
|
|
|
// events "generated" by script/log
|
2018-05-08 00:58:46 -04:00
|
|
|
|
ScriptDamage,
|
2018-05-10 01:34:29 -04:00
|
|
|
|
ScriptKill,
|
2018-04-15 21:27:43 -04:00
|
|
|
|
Damage,
|
2018-06-16 22:11:25 -04:00
|
|
|
|
Kill,
|
2018-06-05 17:31:36 -04:00
|
|
|
|
JoinTeam,
|
2018-08-27 18:07:54 -04:00
|
|
|
|
|
|
|
|
|
StatusUpdate
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-30 21:53:00 -04:00
|
|
|
|
static long NextEventId;
|
|
|
|
|
static long GetNextEventId() => Interlocked.Increment(ref NextEventId);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2018-04-26 02:13:04 -04:00
|
|
|
|
public GameEvent()
|
|
|
|
|
{
|
2018-09-07 23:29:42 -04:00
|
|
|
|
OnProcessed = new ManualResetEventSlim(false);
|
2018-05-03 01:25:49 -04:00
|
|
|
|
Time = DateTime.UtcNow;
|
2018-08-30 21:53:00 -04:00
|
|
|
|
Id = GetNextEventId();
|
2018-04-26 02:13:04 -04:00
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
public EventType Type;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
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;
|
2018-04-14 00:51:38 -04:00
|
|
|
|
public object Extra { get; set; }
|
2018-09-06 14:25:58 -04:00
|
|
|
|
public ManualResetEventSlim OnProcessed { get; set; }
|
2018-08-30 21:53:00 -04:00
|
|
|
|
public DateTime Time { get; set; }
|
2018-05-10 01:34:29 -04:00
|
|
|
|
public long Id { get; private set; }
|
2018-07-04 22:09:42 -04:00
|
|
|
|
|
2018-09-06 14:25:58 -04: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 22:09:42 -04: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 20:20:47 -04:00
|
|
|
|
queuedEvent.Origin.State != Player.ClientState.Connected &&
|
2018-07-04 22:09:42 -04:00
|
|
|
|
// we want to allow join and quit events
|
2018-08-27 18:07:54 -04:00
|
|
|
|
queuedEvent.Type != EventType.Connect &&
|
2018-07-04 22:09:42 -04:00
|
|
|
|
queuedEvent.Type != EventType.Join &&
|
|
|
|
|
queuedEvent.Type != EventType.Quit &&
|
2018-08-28 17:32:59 -04:00
|
|
|
|
queuedEvent.Type != EventType.Disconnect &&
|
2018-07-04 22:09:42 -04: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 20:20:47 -04:00
|
|
|
|
queuedEvent.Target.State != Player.ClientState.Connected &&
|
2018-07-04 22:09:42 -04:00
|
|
|
|
queuedEvent.Target.NetworkId != 0;
|
|
|
|
|
}
|
2018-09-07 23:29:42 -04:00
|
|
|
|
|
|
|
|
|
public static bool IsEventTimeSensitive(GameEvent gameEvent) => gameEvent.Type == EventType.Connect;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|