add ServerCommandRequestExecuteEvent implementation

This commit is contained in:
RaidMax
2023-04-09 14:07:30 -05:00
parent c550d424dd
commit 22af762a9d
8 changed files with 109 additions and 42 deletions

View File

@ -38,6 +38,11 @@ public interface IGameServerEventSubscriptions
/// </summary>
static event Func<ClientDataUpdateEvent, CancellationToken, Task> ClientDataUpdated;
/// <summary>
/// Raised when a command is requested to be executed on a game server
/// </summary>
static event Func<ServerCommandRequestExecuteEvent, CancellationToken, Task> ServerCommandExecuteRequested;
/// <summary>
/// Raised when a command was executed on a game server
/// <value><see cref="ServerCommandExecuteEvent"/></value>
@ -67,7 +72,7 @@ public interface IGameServerEventSubscriptions
/// <value><see cref="ServerValueSetRequestEvent"/></value>
/// </summary>
static event Func<ServerValueSetCompleteEvent, CancellationToken, Task> ServerValueSetCompleted;
static Task InvokeEventAsync(CoreEvent coreEvent, CancellationToken token)
{
return coreEvent switch
@ -77,6 +82,7 @@ public interface IGameServerEventSubscriptions
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,
@ -93,6 +99,7 @@ public interface IGameServerEventSubscriptions
ConnectionInterrupted = null;
ConnectionRestored = null;
ClientDataUpdated = null;
ServerCommandExecuteRequested = null;
ServerCommandExecuted = null;
ServerValueReceived = null;
ServerValueRequested = null;

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Data.Models;
using SharedLibraryCore.Database.Models;
@ -17,6 +18,23 @@ namespace SharedLibraryCore.Interfaces
/// <param name="previousPenalty">previous penalty the kick is occuring for (if applicable)</param>
/// <returns></returns>
Task Kick(string reason, EFClient target, EFClient origin, EFPenalty previousPenalty = null);
/// <summary>
/// Execute a server command
/// </summary>
/// <param name="command">Server command to execute</param>
/// <param name="token"><see cref="CancellationToken"/></param>
/// <returns>Collection of console command output lines</returns>
Task<string[]> ExecuteCommandAsync(string command, CancellationToken token = default);
/// <summary>
/// Set value for server dvar
/// </summary>
/// <param name="name">Name of the server value to set</param>
/// <param name="value">Value of the server value</param>
/// <param name="token"><see cref="CancellationToken"/></param>
/// <returns></returns>
Task SetDvarAsync(string name, object value, CancellationToken token = default);
/// <summary>
/// Time the most recent match ended