using System;
using System.Threading;
using System.Threading.Tasks;
using SharedLibraryCore.Events;
using SharedLibraryCore.Events.Server;
namespace SharedLibraryCore.Interfaces.Events;
public interface IGameServerEventSubscriptions
{
///
/// Raised when IW4MAdmin starts monitoring a game server
///
///
static event Func MonitoringStarted;
///
/// Raised when IW4MAdmin stops monitoring a game server
///
///
static event Func MonitoringStopped;
///
/// Raised when communication was interrupted with a game server
///
///
static event Func ConnectionInterrupted;
///
/// Raised when communication was resumed with a game server
///
///
static event Func ConnectionRestored;
///
/// Raised when updated client data was received from a game server
///
///
static event Func ClientDataUpdated;
///
/// Raised when a command is requested to be executed on a game server
///
static event Func ServerCommandExecuteRequested;
///
/// Raised when a command was executed on a game server
///
///
static event Func ServerCommandExecuted;
///
/// Raised when a server value is requested for a game server
///
///
static event Func ServerValueRequested;
///
/// Raised when a server value was received from a game server (success or fail)
///
///
static event Func ServerValueReceived;
///
/// Raised when a request to set a server value on a game server is received
///
///
static event Func ServerValueSetRequested;
///
/// Raised when a setting server value on a game server is completed (success or fail)
///
///
static event Func ServerValueSetCompleted;
static Task InvokeEventAsync(CoreEvent coreEvent, CancellationToken token)
{
return coreEvent switch
{
MonitorStartEvent monitoringStartEvent => MonitoringStarted?.InvokeAsync(monitoringStartEvent, token) ?? Task.CompletedTask,
MonitorStopEvent monitorStopEvent => MonitoringStopped?.InvokeAsync(monitorStopEvent, CancellationToken.None) ?? Task.CompletedTask,
ConnectionInterruptEvent connectionInterruptEvent => ConnectionInterrupted?.InvokeAsync(connectionInterruptEvent, token) ?? Task.CompletedTask,
ConnectionRestoreEvent connectionRestoreEvent => ConnectionRestored?.InvokeAsync(connectionRestoreEvent, token) ?? Task.CompletedTask,
ClientDataUpdateEvent clientDataUpdateEvent => ClientDataUpdated?.InvokeAsync(clientDataUpdateEvent, token) ?? Task.CompletedTask,
ServerCommandRequestExecuteEvent serverCommandRequestExecuteEvent => ServerCommandExecuteRequested?.InvokeAsync(serverCommandRequestExecuteEvent, token) ?? Task.CompletedTask,
ServerCommandExecuteEvent dataReceiveEvent => ServerCommandExecuted?.InvokeAsync(dataReceiveEvent, token) ?? Task.CompletedTask,
ServerValueRequestEvent serverValueRequestEvent => ServerValueRequested?.InvokeAsync(serverValueRequestEvent, token) ?? Task.CompletedTask,
ServerValueReceiveEvent serverValueReceiveEvent => ServerValueReceived?.InvokeAsync(serverValueReceiveEvent, token) ?? Task.CompletedTask,
ServerValueSetRequestEvent serverValueSetRequestEvent => ServerValueSetRequested?.InvokeAsync(serverValueSetRequestEvent, token) ?? Task.CompletedTask,
ServerValueSetCompleteEvent serverValueSetCompleteEvent => ServerValueSetCompleted?.InvokeAsync(serverValueSetCompleteEvent, token) ?? Task.CompletedTask,
_ => Task.CompletedTask
};
}
static void ClearEventInvocations()
{
MonitoringStarted = null;
MonitoringStopped = null;
ConnectionInterrupted = null;
ConnectionRestored = null;
ClientDataUpdated = null;
ServerCommandExecuteRequested = null;
ServerCommandExecuted = null;
ServerValueReceived = null;
ServerValueRequested = null;
ServerValueSetRequested = null;
ServerValueSetCompleted = null;
}
}