Re-implemented server state machine. Cleaned up code

TODO: Handle trigger errors
This commit is contained in:
2025-02-12 23:02:00 +01:00
parent 4088bfaef5
commit f45699f300
44 changed files with 913 additions and 831 deletions

View File

@@ -0,0 +1,52 @@
using Docker.DotNet.Models;
using MoonlightServers.Daemon.Enums;
using MoonlightServers.Daemon.Models;
using MoonlightServers.Daemon.Models.Cache;
using Stateless;
namespace MoonlightServers.Daemon.Abstractions;
public partial class Server
{
// Exposed configuration/state values
public int Id => Configuration.Id;
public ServerState State => StateMachine.State;
// Exposed container names and ids
public string RuntimeContainerName { get; private set; }
public string? RuntimeContainerId { get; private set; }
public string InstallationContainerName { get; private set; }
public string? InstallationContainerId { get; private set; }
// Events
public event Func<ServerState, Task> OnStateChanged;
public event Func<string, Task> OnConsoleOutput;
// Private stuff
private readonly ILogger Logger;
private readonly IServiceProvider ServiceProvider;
private readonly ServerConsole Console;
private StateMachine<ServerState, ServerTrigger> StateMachine;
private ServerConfiguration Configuration;
private CancellationTokenSource Cancellation;
public Server(
ILogger logger,
IServiceProvider serviceProvider,
ServerConfiguration configuration
)
{
Logger = logger;
ServiceProvider = serviceProvider;
Configuration = configuration;
Console = new();
Cancellation = new();
RuntimeContainerName = $"moonlight-runtime-{Configuration.Id}";
InstallationContainerName = $"moonlight-install-{Configuration.Id}";
}
}