2022-01-26 11:32:16 -05:00
|
|
|
|
using System;
|
2021-01-17 22:58:18 -05:00
|
|
|
|
using System.Collections.Generic;
|
2018-04-26 02:13:04 -04:00
|
|
|
|
using System.Threading;
|
2018-09-06 14:25:58 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Serilog.Context;
|
2022-01-26 11:32:16 -05:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
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-09-29 15:52:22 -04:00
|
|
|
|
public enum EventFailReason
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// event execution did not fail
|
2018-09-29 15:52:22 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
None,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-29 15:52:22 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// an internal exception prevented the event
|
|
|
|
|
/// from executing
|
2018-09-29 15:52:22 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
Exception,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-29 15:52:22 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// event origin didn't have the necessary privileges
|
|
|
|
|
/// to execute the command
|
2018-09-29 15:52:22 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
Permission,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-29 15:52:22 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// executing the event would cause an invalid state
|
2018-09-29 15:52:22 -04:00
|
|
|
|
/// </summary>
|
2018-10-03 22:20:49 -04:00
|
|
|
|
Invalid,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-10-03 22:20:49 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// client is doing too much of something
|
2018-10-03 22:20:49 -04:00
|
|
|
|
/// </summary>
|
2019-07-21 18:14:44 -04:00
|
|
|
|
Throttle,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2019-07-21 18:14:44 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// the event timed out before completion
|
2019-07-21 18:14:44 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
Timeout
|
2018-09-29 15:52:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 11:32:16 -05:00
|
|
|
|
[Flags]
|
|
|
|
|
public enum EventRequiredEntity
|
|
|
|
|
{
|
|
|
|
|
None = 1,
|
|
|
|
|
Origin = 2,
|
|
|
|
|
Target = 4
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum EventSource
|
|
|
|
|
{
|
|
|
|
|
Unspecified,
|
|
|
|
|
Log,
|
|
|
|
|
Status,
|
|
|
|
|
Internal
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
public enum EventType
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// the event wasn't parsed properly
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
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
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a server started being monitored
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2015-08-21 21:11:35 -04:00
|
|
|
|
Start,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a server stopped being monitored
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2015-08-21 21:11:35 -04:00
|
|
|
|
Stop,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client was detecting as connecting via log
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2015-03-08 17:20:10 -04:00
|
|
|
|
Connect,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client was detecting joining by RCon
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-04-28 21:11:13 -04:00
|
|
|
|
Join,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client was detected leaving via log
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-06-16 22:11:25 -04:00
|
|
|
|
Quit,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client was detected leaving by RCon
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2015-03-08 17:20:10 -04:00
|
|
|
|
Disconnect,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// the current map ended
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2015-03-08 17:20:10 -04:00
|
|
|
|
MapEnd,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// the current map changed
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-06-16 22:11:25 -04:00
|
|
|
|
MapChange,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client was detected as starting to connect
|
2018-11-07 21:30:11 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
PreConnect,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client was detecting as starting to disconnect
|
2018-11-07 21:30:11 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
PreDisconnect,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client's information was updated
|
2018-11-07 21:30:11 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
Update,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2019-03-24 22:34:20 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// connection was lost to a server (the server has not responded after a number of attempts)
|
2019-03-24 22:34:20 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
ConnectionLost,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2019-03-24 22:34:20 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// connection was restored to a server (the server began responding again)
|
2019-03-24 22:34:20 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
ConnectionRestored,
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
// events "generated" by clients
|
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client sent a message
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
Say = 100,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client was warned
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
Warn = 101,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-29 15:52:22 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// all warnings for a client were cleared
|
2018-09-29 15:52:22 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
WarnClear = 102,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client was reported
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
Report = 103,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client was flagged
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
Flag = 104,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client was unflagged
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
Unflag = 105,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client was kicked
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
Kick = 106,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client was tempbanned
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
TempBan = 107,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client was banned
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
Ban = 108,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-29 15:52:22 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client was unbanned
|
2018-09-29 15:52:22 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
Unban = 109,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client entered a command
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
Command = 110,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a client's permission was changed
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
ChangePermission = 111,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2021-06-30 22:13:25 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// client logged in to webfront
|
2021-06-30 22:13:25 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
Login = 112,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2021-06-30 22:13:25 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// client logged out of webfront
|
2021-06-30 22:13:25 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
Logout = 113,
|
2017-09-29 22:42:24 -04:00
|
|
|
|
|
2018-06-16 22:11:25 -04:00
|
|
|
|
// events "generated" by IW4MAdmin
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a message is sent to all clients
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
Broadcast = 200,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// a message is sent to a specific client
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
Tell = 201,
|
2018-06-16 22:11:25 -04:00
|
|
|
|
|
|
|
|
|
// events "generated" by script/log
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// AC Damage Log
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
ScriptDamage = 300,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// AC Kill Log
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
ScriptKill = 301,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// damage info printed out by game script
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
Damage = 302,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// kill info printed out by game script
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
Kill = 303,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// team info printed out by game script
|
2018-09-12 20:53:11 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
JoinTeam = 304,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2019-03-24 22:34:20 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// used for community generated plugin events
|
2019-03-24 22:34:20 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
Other
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 11:32:16 -05:00
|
|
|
|
private static long NextEventId;
|
2022-02-02 17:21:08 -05:00
|
|
|
|
private readonly SemaphoreSlim _eventFinishedWaiter = new(0, 1);
|
2022-01-26 11:32:16 -05:00
|
|
|
|
public string Data; // Data is usually the message sent by player
|
|
|
|
|
public string Message;
|
|
|
|
|
public EFClient Origin;
|
|
|
|
|
public Server Owner;
|
|
|
|
|
public EFClient Target;
|
2020-05-04 17:50:02 -04:00
|
|
|
|
|
2022-01-26 11:32:16 -05:00
|
|
|
|
public EventType Type;
|
2022-03-07 20:59:34 -05:00
|
|
|
|
public string TypeName => Type.ToString();
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2018-04-26 02:13:04 -04:00
|
|
|
|
public GameEvent()
|
|
|
|
|
{
|
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
|
|
|
|
}
|
2022-02-02 17:21:08 -05:00
|
|
|
|
|
|
|
|
|
~GameEvent()
|
|
|
|
|
{
|
|
|
|
|
_eventFinishedWaiter.Dispose();
|
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2020-05-04 17:50:02 -04:00
|
|
|
|
public EventSource Source { get; set; }
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2020-04-04 13:40:23 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// suptype of the event for more detailed classification
|
2020-04-04 13:40:23 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
public string Subtype { get; set; }
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2019-05-29 17:55:35 -04:00
|
|
|
|
public EventRequiredEntity RequiredEntity { get; set; }
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2020-02-06 19:35:30 -05:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Specifies the game time offset as printed in the log
|
2020-02-06 19:35:30 -05:00
|
|
|
|
/// </summary>
|
2020-12-13 21:33:37 -05:00
|
|
|
|
public long? GameTime { get; set; }
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2020-04-26 22:12:49 -04:00
|
|
|
|
public EFClient ImpersonationOrigin { get; set; }
|
2020-05-04 17:50:02 -04:00
|
|
|
|
public bool IsRemote { get; set; }
|
2018-04-14 00:51:38 -04:00
|
|
|
|
public object Extra { get; set; }
|
2018-08-30 21:53:00 -04:00
|
|
|
|
public DateTime Time { get; set; }
|
2022-01-26 11:32:16 -05:00
|
|
|
|
public long Id { get; }
|
2018-09-29 15:52:22 -04:00
|
|
|
|
public EventFailReason FailReason { get; set; }
|
|
|
|
|
public bool Failed => FailReason != EventFailReason.None;
|
2021-01-17 22:58:18 -05:00
|
|
|
|
public Guid CorrelationId { get; set; } = Guid.NewGuid();
|
|
|
|
|
public List<string> Output { get; set; } = new List<string>();
|
2019-11-15 15:50:20 -05:00
|
|
|
|
|
2019-10-18 14:39:21 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Indicates if the event should block until it is complete
|
2019-10-18 14:39:21 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsBlocking { get; set; }
|
2018-07-04 22:09:42 -04:00
|
|
|
|
|
2022-01-26 11:32:16 -05:00
|
|
|
|
private static long GetNextEventId()
|
|
|
|
|
{
|
|
|
|
|
return Interlocked.Increment(ref NextEventId);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-15 15:50:20 -05:00
|
|
|
|
public void Complete()
|
|
|
|
|
{
|
2022-02-02 17:21:08 -05:00
|
|
|
|
if (_eventFinishedWaiter.CurrentCount == 0)
|
|
|
|
|
{
|
|
|
|
|
_eventFinishedWaiter.Release();
|
|
|
|
|
}
|
2019-11-15 15:50:20 -05:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-24 12:47:19 -05:00
|
|
|
|
public async Task<GameEvent> WaitAsync()
|
|
|
|
|
{
|
|
|
|
|
return await WaitAsync(Utilities.DefaultCommandTimeout, new CancellationToken());
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 14:25:58 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// asynchronously wait for GameEvent to be processed
|
2018-09-06 14:25:58 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>waitable task </returns>
|
2019-11-15 15:50:20 -05:00
|
|
|
|
public async Task<GameEvent> WaitAsync(TimeSpan timeSpan, CancellationToken token)
|
2018-09-29 15:52:22 -04:00
|
|
|
|
{
|
2022-01-26 11:32:16 -05:00
|
|
|
|
var processed = false;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
Utilities.DefaultLogger.LogDebug("Begin wait for event {Id}", Id);
|
2019-11-15 15:50:20 -05:00
|
|
|
|
try
|
2018-11-07 21:30:11 -05:00
|
|
|
|
{
|
2022-02-02 17:21:08 -05:00
|
|
|
|
processed = await _eventFinishedWaiter.WaitAsync(timeSpan, token);
|
2019-11-15 15:50:20 -05:00
|
|
|
|
}
|
2019-09-26 17:08:49 -04:00
|
|
|
|
|
2020-01-13 17:51:16 -05:00
|
|
|
|
catch (TaskCanceledException)
|
|
|
|
|
{
|
|
|
|
|
processed = true;
|
|
|
|
|
}
|
2019-11-15 15:50:20 -05:00
|
|
|
|
|
2022-03-23 12:38:09 -04:00
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (_eventFinishedWaiter.CurrentCount == 0)
|
|
|
|
|
{
|
|
|
|
|
_eventFinishedWaiter.Release();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-15 15:50:20 -05:00
|
|
|
|
if (!processed)
|
|
|
|
|
{
|
2022-01-26 11:32:16 -05:00
|
|
|
|
using (LogContext.PushProperty("Server", Owner?.ToString()))
|
2020-11-11 18:31:26 -05:00
|
|
|
|
{
|
2022-01-26 11:32:16 -05:00
|
|
|
|
Utilities.DefaultLogger.LogError("Waiting for event to complete timed out {@eventData}",
|
|
|
|
|
new { Event = this, Message, Origin = Origin?.ToString(), Target = Target?.ToString() });
|
2020-11-11 18:31:26 -05:00
|
|
|
|
}
|
2019-11-15 15:50:20 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this lets us know if the the action timed out
|
|
|
|
|
FailReason = FailReason == EventFailReason.None && !processed ? EventFailReason.Timeout : FailReason;
|
2019-09-26 17:08:49 -04:00
|
|
|
|
return this;
|
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
2022-02-02 17:21:08 -05:00
|
|
|
|
}
|