mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
fix alias command sending message to origin instead of target
(hopefully) fix an issue with banned players causing exception if they create events before they are kicked out fix issues with sometimes wrong error message for timeout show most recent IP address at top of alias list optimization to some sql queries
This commit is contained in:
@ -8,9 +8,6 @@ namespace SharedLibraryCore
|
||||
{
|
||||
public class GameEvent
|
||||
{
|
||||
// define what the delagate function looks like
|
||||
public delegate void OnServerEventEventHandler(object sender, GameEventArgs e);
|
||||
|
||||
public enum EventFailReason
|
||||
{
|
||||
/// <summary>
|
||||
@ -205,11 +202,17 @@ namespace SharedLibraryCore
|
||||
|
||||
public GameEvent()
|
||||
{
|
||||
OnProcessed = new ManualResetEventSlim(false);
|
||||
_eventFinishedWaiter = new ManualResetEvent(false);
|
||||
Time = DateTime.UtcNow;
|
||||
Id = GetNextEventId();
|
||||
}
|
||||
|
||||
~GameEvent()
|
||||
{
|
||||
_eventFinishedWaiter.Set();
|
||||
_eventFinishedWaiter.Dispose();
|
||||
}
|
||||
|
||||
public EventType Type;
|
||||
public EventRequiredEntity RequiredEntity { get; set; }
|
||||
public string Data; // Data is usually the message sent by player
|
||||
@ -219,34 +222,56 @@ namespace SharedLibraryCore
|
||||
public Server Owner;
|
||||
public bool IsRemote { get; set; } = false;
|
||||
public object Extra { get; set; }
|
||||
public ManualResetEventSlim OnProcessed { get; set; }
|
||||
private readonly ManualResetEvent _eventFinishedWaiter;
|
||||
public DateTime Time { get; set; }
|
||||
public long Id { get; private set; }
|
||||
public EventFailReason FailReason { get; set; }
|
||||
public bool Failed => FailReason != EventFailReason.None;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the event should block until it is complete
|
||||
/// </summary>
|
||||
public bool IsBlocking { get; set; }
|
||||
|
||||
public void Complete()
|
||||
{
|
||||
_eventFinishedWaiter.Set();
|
||||
#if DEBUG
|
||||
Owner?.Logger.WriteDebug($"Completed internal for event {Id}");
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// asynchronously wait for GameEvent to be processed
|
||||
/// </summary>
|
||||
/// <returns>waitable task </returns>
|
||||
public Task<GameEvent> WaitAsync(TimeSpan timeSpan, CancellationToken token)
|
||||
public async Task<GameEvent> WaitAsync(TimeSpan timeSpan, CancellationToken token)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
bool processed = OnProcessed.Wait(timeSpan, token);
|
||||
// this let's us know if the the action timed out
|
||||
FailReason = FailReason == EventFailReason.None & !processed ? EventFailReason.Timeout : FailReason;
|
||||
return this;
|
||||
});
|
||||
}
|
||||
bool processed = false;
|
||||
|
||||
public GameEvent Wait()
|
||||
{
|
||||
OnProcessed.Wait();
|
||||
#if DEBUG
|
||||
Owner?.Logger.WriteDebug($"Begin wait for event {Id}");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
processed = await Task.Run(() => _eventFinishedWaiter.WaitOne(timeSpan), token);
|
||||
}
|
||||
catch { }
|
||||
|
||||
|
||||
if (!processed)
|
||||
{
|
||||
#if DEBUG
|
||||
//throw new Exception();
|
||||
#endif
|
||||
Owner?.Logger.WriteError("Waiting for event to complete timed out");
|
||||
Owner?.Logger.WriteDebug($"{Id}, {Type}, {Data}, {Extra}, {FailReason.ToString()}, {Message}, {Origin}, {Target}");
|
||||
}
|
||||
|
||||
|
||||
// this lets us know if the the action timed out
|
||||
FailReason = FailReason == EventFailReason.None && !processed ? EventFailReason.Timeout : FailReason;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user