using System;
using System.Threading;
using System.Threading.Tasks;
using SharedLibraryCore.Events;
using SharedLibraryCore.Events.Management;
namespace SharedLibraryCore.Interfaces.Events;
public interface IManagementEventSubscriptions
{
///
/// Raised when is loading
///
static event Func Load;
///
/// Raised when is restarting
///
static event Func Unload;
///
/// Raised when client enters a tracked state
///
/// At this point, the client is not guaranteed to be allowed to play on the server.
/// See for final state.
///
///
///
static event Func ClientStateInitialized;
///
/// Raised when client enters an authorized state (valid data and no bans)
///
///
static event Func ClientStateAuthorized;
///
/// Raised when client is no longer tracked (unknown state)
/// At this point any references to the client should be dropped
///
///
static event Func ClientStateDisposed;
///
/// Raised when a client receives a penalty
///
///
static event Func ClientPenaltyAdministered;
///
/// Raised when a client penalty is revoked (eg unflag/unban)
///
///
static event Func ClientPenaltyRevoked;
///
/// Raised when a client command is executed (after completion of the command)
///
///
static event Func ClientCommandExecuted;
///
/// Raised when a client's permission level changes
///
///
static event Func ClientPermissionChanged;
///
/// Raised when a client logs in to the webfront or ingame
///
///
static event Func ClientLoggedIn;
///
/// Raised when a client logs out of the webfront
///
///
static event Func ClientLoggedOut;
///
/// Raised when a client's persistent id (stats file marker) is received
///
///
static event Func ClientPersistentIdReceived;
static Task InvokeEventAsync(CoreEvent coreEvent, CancellationToken token)
{
return coreEvent switch
{
ClientStateInitializeEvent clientStateInitializeEvent => ClientStateInitialized?.InvokeAsync(
clientStateInitializeEvent, token) ?? Task.CompletedTask,
ClientStateDisposeEvent clientStateDisposedEvent => ClientStateDisposed?.InvokeAsync(
clientStateDisposedEvent, token) ?? Task.CompletedTask,
ClientStateAuthorizeEvent clientStateAuthorizeEvent => ClientStateAuthorized?.InvokeAsync(
clientStateAuthorizeEvent, token) ?? Task.CompletedTask,
ClientPenaltyRevokeEvent clientPenaltyRevokeEvent => ClientPenaltyRevoked?.InvokeAsync(
clientPenaltyRevokeEvent, token) ?? Task.CompletedTask,
ClientPenaltyEvent clientPenaltyEvent =>
ClientPenaltyAdministered?.InvokeAsync(clientPenaltyEvent, token) ?? Task.CompletedTask,
ClientPermissionChangeEvent clientPermissionChangeEvent => ClientPermissionChanged?.InvokeAsync(
clientPermissionChangeEvent, token) ?? Task.CompletedTask,
ClientExecuteCommandEvent clientExecuteCommandEvent => ClientCommandExecuted?.InvokeAsync(
clientExecuteCommandEvent, token) ?? Task.CompletedTask,
LogoutEvent logoutEvent => ClientLoggedOut?.InvokeAsync(logoutEvent, token) ?? Task.CompletedTask,
LoginEvent loginEvent => ClientLoggedIn?.InvokeAsync(loginEvent, token) ?? Task.CompletedTask,
ClientPersistentIdReceiveEvent clientPersistentIdReceiveEvent => ClientPersistentIdReceived?.InvokeAsync(
clientPersistentIdReceiveEvent, token) ?? Task.CompletedTask,
_ => Task.CompletedTask
};
}
static Task InvokeLoadAsync(IManager manager, CancellationToken token) => Load?.InvokeAsync(manager, token) ?? Task.CompletedTask;
static Task InvokeUnloadAsync(IManager manager, CancellationToken token) => Unload?.InvokeAsync(manager, token) ?? Task.CompletedTask;
static void ClearEventInvocations()
{
Load = null;
Unload = null;
ClientStateInitialized = null;
ClientStateAuthorized = null;
ClientStateDisposed = null;
ClientPenaltyAdministered = null;
ClientPenaltyRevoked = null;
ClientCommandExecuted = null;
ClientPermissionChanged = null;
ClientLoggedIn = null;
ClientLoggedOut = null;
ClientPersistentIdReceived = null;
}
}