Implemented restorer, wired up for basic testing. Improved abstractions and fixed observer pattern issues
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using System.Reactive.Concurrency;
|
||||
using System.Reactive.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Docker.DotNet;
|
||||
@@ -13,9 +15,13 @@ using MoonlightServers.Daemon.Configuration;
|
||||
using MoonlightServers.Daemon.Helpers;
|
||||
using MoonlightServers.Daemon.Http.Hubs;
|
||||
using MoonlightServers.Daemon.Mappers;
|
||||
using MoonlightServers.Daemon.Models.Cache;
|
||||
using MoonlightServers.Daemon.ServerSys;
|
||||
using MoonlightServers.Daemon.ServerSys.Abstractions;
|
||||
using MoonlightServers.Daemon.ServerSys.Implementations;
|
||||
using MoonlightServers.Daemon.ServerSystem;
|
||||
using MoonlightServers.Daemon.Services;
|
||||
using Server = MoonlightServers.Daemon.ServerSystem.Server;
|
||||
|
||||
namespace MoonlightServers.Daemon;
|
||||
|
||||
@@ -65,6 +71,70 @@ public class Startup
|
||||
await MapBase();
|
||||
await MapHubs();
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Press enter to create server instance");
|
||||
Console.ReadLine();
|
||||
|
||||
var config = new ServerConfiguration()
|
||||
{
|
||||
Allocations = [
|
||||
new ServerConfiguration.AllocationConfiguration()
|
||||
{
|
||||
IpAddress = "0.0.0.0",
|
||||
Port = 25565
|
||||
}
|
||||
],
|
||||
Cpu = 400,
|
||||
Disk = 10240,
|
||||
DockerImage = "ghcr.io/parkervcp/yolks:java_21",
|
||||
Id = 69,
|
||||
Memory = 4096,
|
||||
OnlineDetection = "\\)! For help, type ",
|
||||
StartupCommand = "java -Xms128M -Xmx{{SERVER_MEMORY}}M -Dterminal.jline=false -Dterminal.ansi=true -jar {{SERVER_JARFILE}}",
|
||||
StopCommand = "stop",
|
||||
Variables = new()
|
||||
{
|
||||
{
|
||||
"SERVER_JARFILE",
|
||||
"server.jar"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var factory = WebApplication.Services.GetRequiredService<ServerFactory>();
|
||||
var server = factory.CreateServer(config);
|
||||
|
||||
using var consoleSub = server.Console.OnOutput
|
||||
.Subscribe(Console.Write);
|
||||
|
||||
using var stateSub = server.OnState.Subscribe(state =>
|
||||
{
|
||||
Console.WriteLine($"State: {state}");
|
||||
});
|
||||
|
||||
await server.Initialize();
|
||||
|
||||
Console.ReadLine();
|
||||
|
||||
if(server.StateMachine.State == ServerState.Offline)
|
||||
await server.StateMachine.FireAsync(ServerTrigger.Start);
|
||||
else
|
||||
await server.StateMachine.FireAsync(ServerTrigger.Stop);
|
||||
|
||||
Console.ReadLine();
|
||||
|
||||
await server.Context.ServiceScope.DisposeAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
});
|
||||
|
||||
await WebApplication.RunAsync();
|
||||
}
|
||||
|
||||
@@ -72,7 +142,6 @@ public class Startup
|
||||
{
|
||||
Directory.CreateDirectory("storage");
|
||||
Directory.CreateDirectory(Path.Combine("storage", "logs"));
|
||||
Directory.CreateDirectory(Path.Combine("storage", "plugins"));
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
@@ -261,6 +330,17 @@ public class Startup
|
||||
|
||||
WebApplicationBuilder.Services.AddSingleton<ServerFactory>();
|
||||
|
||||
// Server scoped stuff
|
||||
WebApplicationBuilder.Services.AddScoped<IConsole, DockerConsole>();
|
||||
WebApplicationBuilder.Services.AddScoped<IFileSystem, RawFileSystem>();
|
||||
WebApplicationBuilder.Services.AddScoped<IRestorer, DefaultRestorer>();
|
||||
WebApplicationBuilder.Services.AddScoped<IInstaller, DockerInstaller>();
|
||||
WebApplicationBuilder.Services.AddScoped<IProvisioner, DockerProvisioner>();
|
||||
WebApplicationBuilder.Services.AddScoped<IStatistics, DockerStatistics>();
|
||||
WebApplicationBuilder.Services.AddScoped<ServerContext>();
|
||||
|
||||
WebApplicationBuilder.Services.AddScoped<ServerSys.Abstractions.Server>();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user