IW4M-Admin/SharedLibraryCore/Events/GameEvent.cs

104 lines
3.3 KiB
C#
Raw Normal View History

2015-03-08 17:20:10 -04:00
using System;
using System.Threading;
2018-04-08 02:44:42 -04:00
using SharedLibraryCore.Objects;
2018-04-08 02:44:42 -04:00
namespace SharedLibraryCore
2015-03-08 17:20:10 -04:00
{
public class GameEvent
2015-03-08 17:20:10 -04:00
{
public enum EventType
2015-03-08 17:20:10 -04:00
{
Unknown,
// events "generated" by the server
Start,
Stop,
2015-03-08 17:20:10 -04:00
Connect,
Join,
Quit,
2015-03-08 17:20:10 -04:00
Disconnect,
MapEnd,
MapChange,
// events "generated" by clients
Say,
Warn,
Report,
Flag,
Unflag,
Kick,
TempBan,
Ban,
2018-04-14 00:51:38 -04:00
Command,
// events "generated" by IW4MAdmin
Broadcast,
Tell,
// events "generated" by script/log
ScriptDamage,
2018-05-10 01:34:29 -04:00
ScriptKill,
Damage,
Kill,
JoinTeam,
StatusUpdate
2015-03-08 17:20:10 -04:00
}
static long NextEventId;
static long GetNextEventId() => Interlocked.Increment(ref NextEventId);
2015-03-08 17:20:10 -04:00
public GameEvent()
{
OnProcessed = new SemaphoreSlim(0);
OnProcessed.Release();
Time = DateTime.UtcNow;
Id = GetNextEventId();
}
2015-03-08 17:20:10 -04:00
public EventType Type;
2015-03-08 17:20:10 -04:00
public string Data; // Data is usually the message sent by player
public string Message;
2015-03-08 17:20:10 -04:00
public Player Origin;
public Player Target;
public Server Owner;
public Boolean Remote = false;
2018-04-14 00:51:38 -04:00
public object Extra { get; set; }
public SemaphoreSlim OnProcessed { get; set; }
public DateTime Time { get; set; }
2018-05-10 01:34:29 -04:00
public long Id { get; private set; }
/// <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.State != Player.ClientState.Connected &&
// we want to allow join and quit events
queuedEvent.Type != EventType.Connect &&
queuedEvent.Type != EventType.Join &&
queuedEvent.Type != EventType.Quit &&
queuedEvent.Type != EventType.Disconnect &&
// 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.State != Player.ClientState.Connected &&
queuedEvent.Target.NetworkId != 0;
}
2015-03-08 17:20:10 -04:00
}
}