mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2026-03-01 05:07:53 +01:00
Compare commits
4 Commits
wip-update
...
21bfdf90ee
| Author | SHA1 | Date | |
|---|---|---|---|
|
21bfdf90ee
|
|||
|
298f9adac2
|
|||
|
e1e8963ff4
|
|||
|
59bcc7d538
|
@@ -6,7 +6,7 @@
|
|||||||
<option name="PASS_PARENT_ENVS" value="1" />
|
<option name="PASS_PARENT_ENVS" value="1" />
|
||||||
<envs>
|
<envs>
|
||||||
<env name="AGENT_KEY_FILE" value="./key" />
|
<env name="AGENT_KEY_FILE" value="./key" />
|
||||||
<env name="ALLOWED_RCON_PORTS" value="25575,27000,27001" />
|
<env name="ALLOWED_ADDITIONAL_PORTS" value="25575,27000,27001" />
|
||||||
<env name="ALLOWED_SERVER_PORTS" value="25565,26000,26001" />
|
<env name="ALLOWED_SERVER_PORTS" value="25565,26000,26001" />
|
||||||
<env name="CONTROLLER_HOST" value="localhost" />
|
<env name="CONTROLLER_HOST" value="localhost" />
|
||||||
<env name="JAVA_SEARCH_PATH" value="~/.jdks" />
|
<env name="JAVA_SEARCH_PATH" value="~/.jdks" />
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
||||||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
|
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
|
||||||
<option name="PROJECT_KIND" value="DotNetCore" />
|
<option name="PROJECT_KIND" value="DotNetCore" />
|
||||||
<option name="PROJECT_TFM" value="net9.0" />
|
<option name="PROJECT_TFM" value="net10.0" />
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="Build" />
|
<option name="Build" />
|
||||||
</method>
|
</method>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<option name="PASS_PARENT_ENVS" value="1" />
|
<option name="PASS_PARENT_ENVS" value="1" />
|
||||||
<envs>
|
<envs>
|
||||||
<env name="AGENT_KEY_FILE" value="./key" />
|
<env name="AGENT_KEY_FILE" value="./key" />
|
||||||
<env name="ALLOWED_RCON_PORTS" value="27002-27006" />
|
<env name="ALLOWED_ADDITIONAL_PORTS" value="27002-27006" />
|
||||||
<env name="ALLOWED_SERVER_PORTS" value="26002-26006" />
|
<env name="ALLOWED_SERVER_PORTS" value="26002-26006" />
|
||||||
<env name="CONTROLLER_HOST" value="localhost" />
|
<env name="CONTROLLER_HOST" value="localhost" />
|
||||||
<env name="JAVA_SEARCH_PATH" value="~/.jdks" />
|
<env name="JAVA_SEARCH_PATH" value="~/.jdks" />
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
||||||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
|
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
|
||||||
<option name="PROJECT_KIND" value="DotNetCore" />
|
<option name="PROJECT_KIND" value="DotNetCore" />
|
||||||
<option name="PROJECT_TFM" value="net9.0" />
|
<option name="PROJECT_TFM" value="net10.0" />
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="Build" />
|
<option name="Build" />
|
||||||
</method>
|
</method>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<option name="PASS_PARENT_ENVS" value="1" />
|
<option name="PASS_PARENT_ENVS" value="1" />
|
||||||
<envs>
|
<envs>
|
||||||
<env name="AGENT_KEY_FILE" value="./key" />
|
<env name="AGENT_KEY_FILE" value="./key" />
|
||||||
<env name="ALLOWED_RCON_PORTS" value="27007" />
|
<env name="ALLOWED_ADDITIONAL_PORTS" value="27007" />
|
||||||
<env name="ALLOWED_SERVER_PORTS" value="26007" />
|
<env name="ALLOWED_SERVER_PORTS" value="26007" />
|
||||||
<env name="CONTROLLER_HOST" value="localhost" />
|
<env name="CONTROLLER_HOST" value="localhost" />
|
||||||
<env name="JAVA_SEARCH_PATH" value="~/.jdks" />
|
<env name="JAVA_SEARCH_PATH" value="~/.jdks" />
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
||||||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
|
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
|
||||||
<option name="PROJECT_KIND" value="DotNetCore" />
|
<option name="PROJECT_KIND" value="DotNetCore" />
|
||||||
<option name="PROJECT_TFM" value="net9.0" />
|
<option name="PROJECT_TFM" value="net10.0" />
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="Build" />
|
<option name="Build" />
|
||||||
</method>
|
</method>
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
namespace Phantom.Agent.Minecraft.Command;
|
|
||||||
|
|
||||||
public static class MinecraftCommand {
|
|
||||||
public const string SaveOn = "save-on";
|
|
||||||
public const string SaveOff = "save-off";
|
|
||||||
public const string Stop = "stop";
|
|
||||||
|
|
||||||
public static string Say(string message) {
|
|
||||||
return "say " + message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string SaveAll(bool flush) {
|
|
||||||
return flush ? "save-all flush" : "save-all";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using System.Collections.Immutable;
|
|
||||||
using Phantom.Agent.Minecraft.Java;
|
|
||||||
using Phantom.Agent.Minecraft.Properties;
|
|
||||||
using Phantom.Common.Data.Instance;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Instance;
|
|
||||||
|
|
||||||
public sealed record InstanceProperties(
|
|
||||||
Guid InstanceGuid,
|
|
||||||
Guid JavaRuntimeGuid,
|
|
||||||
JvmProperties JvmProperties,
|
|
||||||
ImmutableArray<string> JvmArguments,
|
|
||||||
string InstanceFolder,
|
|
||||||
string ServerVersion,
|
|
||||||
ServerProperties ServerProperties,
|
|
||||||
InstanceLaunchProperties LaunchProperties
|
|
||||||
);
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
using System.Collections.ObjectModel;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Java;
|
|
||||||
|
|
||||||
sealed class JvmArgumentBuilder(JvmProperties basicProperties) {
|
|
||||||
private readonly List<string> customArguments = [];
|
|
||||||
|
|
||||||
public void Add(string argument) {
|
|
||||||
customArguments.Add(argument);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddProperty(string key, string value) {
|
|
||||||
customArguments.Add("-D" + key + "=\"" + value + "\""); // TODO test quoting?
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Build(Collection<string> target) {
|
|
||||||
foreach (var property in customArguments) {
|
|
||||||
target.Add(property);
|
|
||||||
}
|
|
||||||
|
|
||||||
// In case of duplicate JVM arguments, typically the last one wins.
|
|
||||||
target.Add("-Xms" + basicProperties.InitialHeapMegabytes + "M");
|
|
||||||
target.Add("-Xmx" + basicProperties.MaximumHeapMegabytes + "M");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Phantom.Agent.Minecraft.Java;
|
|
||||||
|
|
||||||
public sealed record JvmProperties(
|
|
||||||
uint InitialHeapMegabytes,
|
|
||||||
uint MaximumHeapMegabytes
|
|
||||||
);
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
using System.Text;
|
|
||||||
using Phantom.Agent.Minecraft.Instance;
|
|
||||||
using Phantom.Agent.Minecraft.Java;
|
|
||||||
using Phantom.Agent.Minecraft.Server;
|
|
||||||
using Phantom.Utils.Processes;
|
|
||||||
using Serilog;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Launcher;
|
|
||||||
|
|
||||||
public abstract class BaseLauncher : IServerLauncher {
|
|
||||||
private readonly InstanceProperties instanceProperties;
|
|
||||||
|
|
||||||
protected string MinecraftVersion => instanceProperties.ServerVersion;
|
|
||||||
|
|
||||||
private protected BaseLauncher(InstanceProperties instanceProperties) {
|
|
||||||
this.instanceProperties = instanceProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<LaunchResult> Launch(ILogger logger, LaunchServices services, EventHandler<DownloadProgressEventArgs> downloadProgressEventHandler, CancellationToken cancellationToken) {
|
|
||||||
if (!services.JavaRuntimeRepository.TryGetByGuid(instanceProperties.JavaRuntimeGuid, out var javaRuntimeExecutable)) {
|
|
||||||
return new LaunchResult.InvalidJavaRuntime();
|
|
||||||
}
|
|
||||||
|
|
||||||
var vanillaServerJarPath = await services.ServerExecutables.DownloadAndGetPath(instanceProperties.LaunchProperties.ServerDownloadInfo, MinecraftVersion, downloadProgressEventHandler, cancellationToken);
|
|
||||||
if (vanillaServerJarPath == null) {
|
|
||||||
return new LaunchResult.CouldNotDownloadMinecraftServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerJarInfo? serverJar;
|
|
||||||
try {
|
|
||||||
serverJar = await PrepareServerJar(logger, vanillaServerJarPath, cancellationToken);
|
|
||||||
} catch (OperationCanceledException) {
|
|
||||||
throw;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.Error(e, "Caught exception while preparing the server jar.");
|
|
||||||
return new LaunchResult.CouldNotPrepareMinecraftServerLauncher();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!File.Exists(serverJar.FilePath)) {
|
|
||||||
logger.Error("Missing prepared server or launcher jar: {FilePath}", serverJar.FilePath);
|
|
||||||
return new LaunchResult.CouldNotPrepareMinecraftServerLauncher();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await AcceptEula(instanceProperties);
|
|
||||||
await UpdateServerProperties(instanceProperties, cancellationToken);
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.Error(e, "Caught exception while configuring the server.");
|
|
||||||
return new LaunchResult.CouldNotConfigureMinecraftServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
var processConfigurator = new ProcessConfigurator {
|
|
||||||
FileName = javaRuntimeExecutable.ExecutablePath,
|
|
||||||
WorkingDirectory = instanceProperties.InstanceFolder,
|
|
||||||
RedirectInput = true,
|
|
||||||
UseShellExecute = false,
|
|
||||||
};
|
|
||||||
|
|
||||||
var processArguments = processConfigurator.ArgumentList;
|
|
||||||
PrepareJvmArguments(serverJar).Build(processArguments);
|
|
||||||
processArguments.Add("-jar");
|
|
||||||
processArguments.Add(serverJar.FilePath);
|
|
||||||
processArguments.Add("nogui");
|
|
||||||
|
|
||||||
var process = processConfigurator.CreateProcess();
|
|
||||||
var instanceProcess = new InstanceProcess(instanceProperties, process);
|
|
||||||
|
|
||||||
try {
|
|
||||||
process.Start();
|
|
||||||
} catch (Exception launchException) {
|
|
||||||
logger.Error(launchException, "Caught exception launching the server process.");
|
|
||||||
|
|
||||||
try {
|
|
||||||
process.Kill();
|
|
||||||
} catch (Exception killException) {
|
|
||||||
logger.Error(killException, "Caught exception trying to kill the server process after a failed launch.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return new LaunchResult.CouldNotStartMinecraftServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new LaunchResult.Success(instanceProcess);
|
|
||||||
}
|
|
||||||
|
|
||||||
private JvmArgumentBuilder PrepareJvmArguments(ServerJarInfo serverJar) {
|
|
||||||
var builder = new JvmArgumentBuilder(instanceProperties.JvmProperties);
|
|
||||||
|
|
||||||
foreach (string argument in instanceProperties.JvmArguments) {
|
|
||||||
builder.Add(argument);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var argument in serverJar.ExtraArgs) {
|
|
||||||
builder.Add(argument);
|
|
||||||
}
|
|
||||||
|
|
||||||
CustomizeJvmArguments(builder);
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
private protected virtual void CustomizeJvmArguments(JvmArgumentBuilder arguments) {}
|
|
||||||
|
|
||||||
private protected virtual Task<ServerJarInfo> PrepareServerJar(ILogger logger, string serverJarPath, CancellationToken cancellationToken) {
|
|
||||||
return Task.FromResult(new ServerJarInfo(serverJarPath));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task AcceptEula(InstanceProperties instanceProperties) {
|
|
||||||
var eulaFilePath = Path.Combine(instanceProperties.InstanceFolder, "eula.txt");
|
|
||||||
await File.WriteAllLinesAsync(eulaFilePath, ["# EULA", "eula=true"], Encoding.UTF8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task UpdateServerProperties(InstanceProperties instanceProperties, CancellationToken cancellationToken) {
|
|
||||||
var serverPropertiesEditor = new JavaPropertiesFileEditor();
|
|
||||||
instanceProperties.ServerProperties.SetTo(serverPropertiesEditor);
|
|
||||||
await serverPropertiesEditor.EditOrCreate(Path.Combine(instanceProperties.InstanceFolder, "server.properties"), comment: "server.properties", cancellationToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using Phantom.Agent.Minecraft.Server;
|
|
||||||
using Serilog;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Launcher;
|
|
||||||
|
|
||||||
public interface IServerLauncher {
|
|
||||||
Task<LaunchResult> Launch(ILogger logger, LaunchServices services, EventHandler<DownloadProgressEventArgs> downloadProgressEventHandler, CancellationToken cancellationToken);
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
using Phantom.Agent.Minecraft.Instance;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Launcher;
|
|
||||||
|
|
||||||
public abstract record LaunchResult {
|
|
||||||
private LaunchResult() {}
|
|
||||||
|
|
||||||
public sealed record Success(InstanceProcess Process) : LaunchResult;
|
|
||||||
|
|
||||||
public sealed record InvalidJavaRuntime : LaunchResult;
|
|
||||||
|
|
||||||
public sealed record CouldNotDownloadMinecraftServer : LaunchResult;
|
|
||||||
|
|
||||||
public sealed record CouldNotPrepareMinecraftServerLauncher : LaunchResult;
|
|
||||||
|
|
||||||
public sealed record CouldNotConfigureMinecraftServer : LaunchResult;
|
|
||||||
|
|
||||||
public sealed record CouldNotStartMinecraftServer : LaunchResult;
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
using Phantom.Agent.Minecraft.Java;
|
|
||||||
using Phantom.Agent.Minecraft.Server;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Launcher;
|
|
||||||
|
|
||||||
public sealed record LaunchServices(MinecraftServerExecutables ServerExecutables, JavaRuntimeRepository JavaRuntimeRepository);
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
using System.Collections.Immutable;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Launcher;
|
|
||||||
|
|
||||||
sealed record ServerJarInfo(string FilePath, ImmutableArray<string> ExtraArgs) {
|
|
||||||
public ServerJarInfo(string filePath) : this(filePath, ImmutableArray<string>.Empty) {}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
using Phantom.Agent.Minecraft.Instance;
|
|
||||||
using Phantom.Utils.IO;
|
|
||||||
using Serilog;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Launcher.Types;
|
|
||||||
|
|
||||||
public sealed class FabricLauncher : BaseLauncher {
|
|
||||||
public FabricLauncher(InstanceProperties instanceProperties) : base(instanceProperties) {}
|
|
||||||
|
|
||||||
private protected override async Task<ServerJarInfo> PrepareServerJar(ILogger logger, string serverJarPath, CancellationToken cancellationToken) {
|
|
||||||
var serverJarParentFolderPath = Directory.GetParent(serverJarPath);
|
|
||||||
if (serverJarParentFolderPath == null) {
|
|
||||||
throw new ArgumentException("Could not get parent folder from: " + serverJarPath, nameof(serverJarPath));
|
|
||||||
}
|
|
||||||
|
|
||||||
var launcherJarPath = Path.Combine(serverJarParentFolderPath.FullName, "fabric.jar");
|
|
||||||
|
|
||||||
if (!File.Exists(launcherJarPath)) {
|
|
||||||
await DownloadLauncher(logger, launcherJarPath, cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ServerJarInfo(launcherJarPath, ["-Dfabric.installer.server.gameJar=" + Paths.NormalizeSlashes(serverJarPath)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task DownloadLauncher(ILogger logger, string targetFilePath, CancellationToken cancellationToken) {
|
|
||||||
// TODO customizable loader version, probably with a dedicated temporary folder
|
|
||||||
string installerUrl = $"https://meta.fabricmc.net/v2/versions/loader/{MinecraftVersion}/stable/stable/server/jar";
|
|
||||||
logger.Information("Downloading Fabric launcher from: {Url}", installerUrl);
|
|
||||||
|
|
||||||
using var http = new HttpClient();
|
|
||||||
|
|
||||||
var response = await http.GetAsync(installerUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
|
|
||||||
try {
|
|
||||||
await using var fileStream = new FileStream(targetFilePath, FileMode.CreateNew, FileAccess.Write, FileShare.Read);
|
|
||||||
await using var responseStream = await response.Content.ReadAsStreamAsync(cancellationToken);
|
|
||||||
await responseStream.CopyToAsync(fileStream, cancellationToken);
|
|
||||||
} catch (Exception) {
|
|
||||||
TryDeleteLauncherAfterFailure(logger, targetFilePath);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void TryDeleteLauncherAfterFailure(ILogger logger, string filePath) {
|
|
||||||
if (File.Exists(filePath)) {
|
|
||||||
try {
|
|
||||||
File.Delete(filePath);
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.Warning(e, "Could not clean up partially downloaded Fabric launcher: {FilePath}", filePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using Phantom.Agent.Minecraft.Server;
|
|
||||||
using Serilog;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Launcher.Types;
|
|
||||||
|
|
||||||
public sealed class InvalidLauncher : IServerLauncher {
|
|
||||||
public static InvalidLauncher Instance { get; } = new ();
|
|
||||||
|
|
||||||
private InvalidLauncher() {}
|
|
||||||
|
|
||||||
public Task<LaunchResult> Launch(ILogger logger, LaunchServices services, EventHandler<DownloadProgressEventArgs> downloadProgressEventHandler, CancellationToken cancellationToken) {
|
|
||||||
return Task.FromResult<LaunchResult>(new LaunchResult.CouldNotPrepareMinecraftServerLauncher());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
using Phantom.Agent.Minecraft.Instance;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Launcher.Types;
|
|
||||||
|
|
||||||
public sealed class VanillaLauncher : BaseLauncher {
|
|
||||||
public VanillaLauncher(InstanceProperties instanceProperties) : base(instanceProperties) {}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<InternalsVisibleTo Include="Phantom.Agent.Minecraft.Tests" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\Common\Phantom.Common.Data\Phantom.Common.Data.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Utils\Phantom.Utils\Phantom.Utils.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Utils\Phantom.Utils.Logging\Phantom.Utils.Logging.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
namespace Phantom.Agent.Minecraft.Properties;
|
|
||||||
|
|
||||||
static class MinecraftServerProperties {
|
|
||||||
private sealed class Boolean : MinecraftServerProperty<bool> {
|
|
||||||
public Boolean(string key) : base(key) {}
|
|
||||||
|
|
||||||
protected override bool Read(string value) => value.Equals("true", StringComparison.OrdinalIgnoreCase);
|
|
||||||
protected override string Write(bool value) => value ? "true" : "false";
|
|
||||||
}
|
|
||||||
|
|
||||||
private sealed class UnsignedShort : MinecraftServerProperty<ushort> {
|
|
||||||
public UnsignedShort(string key) : base(key) {}
|
|
||||||
|
|
||||||
protected override ushort Read(string value) => ushort.Parse(value);
|
|
||||||
protected override string Write(ushort value) => value.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static readonly MinecraftServerProperty<ushort> ServerPort = new UnsignedShort("server-port");
|
|
||||||
public static readonly MinecraftServerProperty<ushort> RconPort = new UnsignedShort("rcon.port");
|
|
||||||
public static readonly MinecraftServerProperty<bool> EnableRcon = new Boolean("enable-rcon");
|
|
||||||
public static readonly MinecraftServerProperty<bool> SyncChunkWrites = new Boolean("sync-chunk-writes");
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
using Phantom.Agent.Minecraft.Java;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Properties;
|
|
||||||
|
|
||||||
abstract class MinecraftServerProperty<T> {
|
|
||||||
private readonly string key;
|
|
||||||
|
|
||||||
protected MinecraftServerProperty(string key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract T Read(string value);
|
|
||||||
protected abstract string Write(T value);
|
|
||||||
|
|
||||||
public void Set(JavaPropertiesFileEditor properties, T value) {
|
|
||||||
properties.Set(key, Write(value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using Phantom.Agent.Minecraft.Java;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Properties;
|
|
||||||
|
|
||||||
public sealed record ServerProperties(
|
|
||||||
ushort ServerPort,
|
|
||||||
ushort RconPort,
|
|
||||||
bool EnableRcon = true,
|
|
||||||
bool SyncChunkWrites = false
|
|
||||||
) {
|
|
||||||
internal void SetTo(JavaPropertiesFileEditor properties) {
|
|
||||||
MinecraftServerProperties.ServerPort.Set(properties, ServerPort);
|
|
||||||
MinecraftServerProperties.RconPort.Set(properties, RconPort);
|
|
||||||
MinecraftServerProperties.EnableRcon.Set(properties, EnableRcon);
|
|
||||||
MinecraftServerProperties.SyncChunkWrites.Set(properties, SyncChunkWrites);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Phantom.Agent.Minecraft.Server;
|
|
||||||
|
|
||||||
sealed record MinecraftServerExecutableDownloadListener(EventHandler<DownloadProgressEventArgs> DownloadProgressEventHandler, CancellationToken CancellationToken);
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
using System.Security.Cryptography;
|
|
||||||
using Phantom.Common.Data.Minecraft;
|
|
||||||
using Phantom.Utils.Cryptography;
|
|
||||||
using Phantom.Utils.IO;
|
|
||||||
using Phantom.Utils.Logging;
|
|
||||||
using Phantom.Utils.Runtime;
|
|
||||||
using Serilog;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Server;
|
|
||||||
|
|
||||||
sealed class MinecraftServerExecutableDownloader {
|
|
||||||
private static readonly ILogger Logger = PhantomLogger.Create<MinecraftServerExecutableDownloader>();
|
|
||||||
|
|
||||||
public Task<string?> Task { get; }
|
|
||||||
public event EventHandler<DownloadProgressEventArgs>? DownloadProgress;
|
|
||||||
public event EventHandler? Completed;
|
|
||||||
|
|
||||||
private readonly CancellationTokenSource cancellationTokenSource = new ();
|
|
||||||
|
|
||||||
private readonly List<CancellationTokenRegistration> listenerCancellationRegistrations = [];
|
|
||||||
private int listenerCount = 0;
|
|
||||||
|
|
||||||
public MinecraftServerExecutableDownloader(FileDownloadInfo fileDownloadInfo, string minecraftVersion, string filePath, MinecraftServerExecutableDownloadListener listener) {
|
|
||||||
Register(listener);
|
|
||||||
Task = DownloadAndGetPath(fileDownloadInfo, minecraftVersion, filePath, new DownloadProgressCallback(this), cancellationTokenSource.Token);
|
|
||||||
Task.ContinueWith(OnCompleted, TaskScheduler.Default);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Register(MinecraftServerExecutableDownloadListener listener) {
|
|
||||||
int newListenerCount;
|
|
||||||
|
|
||||||
lock (this) {
|
|
||||||
newListenerCount = ++listenerCount;
|
|
||||||
|
|
||||||
DownloadProgress += listener.DownloadProgressEventHandler;
|
|
||||||
listenerCancellationRegistrations.Add(listener.CancellationToken.Register(Unregister, listener));
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Debug("Registered download listener, current listener count: {Listeners}", newListenerCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Unregister(object? listenerObject) {
|
|
||||||
int newListenerCount;
|
|
||||||
|
|
||||||
lock (this) {
|
|
||||||
MinecraftServerExecutableDownloadListener listener = (MinecraftServerExecutableDownloadListener) listenerObject!;
|
|
||||||
DownloadProgress -= listener.DownloadProgressEventHandler;
|
|
||||||
|
|
||||||
newListenerCount = --listenerCount;
|
|
||||||
if (newListenerCount <= 0) {
|
|
||||||
cancellationTokenSource.Cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newListenerCount <= 0) {
|
|
||||||
Logger.Debug("Unregistered last download listener, cancelling download.");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Logger.Debug("Unregistered download listener, current listener count: {Listeners}", newListenerCount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ReportDownloadProgress(DownloadProgressEventArgs args) {
|
|
||||||
DownloadProgress?.Invoke(this, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnCompleted(Task task) {
|
|
||||||
Logger.Debug("Download task completed.");
|
|
||||||
|
|
||||||
lock (this) {
|
|
||||||
Completed?.Invoke(this, EventArgs.Empty);
|
|
||||||
Completed = null;
|
|
||||||
DownloadProgress = null;
|
|
||||||
|
|
||||||
foreach (var registration in listenerCancellationRegistrations) {
|
|
||||||
registration.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
listenerCancellationRegistrations.Clear();
|
|
||||||
cancellationTokenSource.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private sealed class DownloadProgressCallback {
|
|
||||||
private readonly MinecraftServerExecutableDownloader downloader;
|
|
||||||
|
|
||||||
public DownloadProgressCallback(MinecraftServerExecutableDownloader downloader) {
|
|
||||||
this.downloader = downloader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ReportProgress(ulong downloadedBytes, ulong totalBytes) {
|
|
||||||
downloader.ReportDownloadProgress(new DownloadProgressEventArgs(downloadedBytes, totalBytes));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task<string?> DownloadAndGetPath(FileDownloadInfo fileDownloadInfo, string minecraftVersion, string filePath, DownloadProgressCallback progressCallback, CancellationToken cancellationToken) {
|
|
||||||
string tmpFilePath = filePath + ".tmp";
|
|
||||||
|
|
||||||
try {
|
|
||||||
Logger.Information("Downloading server version {Version} from: {Url} ({Size})", minecraftVersion, fileDownloadInfo.DownloadUrl, fileDownloadInfo.Size.ToHumanReadable(decimalPlaces: 1));
|
|
||||||
try {
|
|
||||||
using var http = new HttpClient();
|
|
||||||
await FetchServerExecutableFile(http, progressCallback, fileDownloadInfo, tmpFilePath, cancellationToken);
|
|
||||||
} catch (Exception) {
|
|
||||||
TryDeleteExecutableAfterFailure(tmpFilePath);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
File.Move(tmpFilePath, filePath, overwrite: true);
|
|
||||||
Logger.Information("Server version {Version} downloaded.", minecraftVersion);
|
|
||||||
|
|
||||||
return filePath;
|
|
||||||
} catch (OperationCanceledException) {
|
|
||||||
Logger.Information("Download for server version {Version} was cancelled.", minecraftVersion);
|
|
||||||
throw;
|
|
||||||
} catch (StopProcedureException) {
|
|
||||||
return null;
|
|
||||||
} catch (Exception e) {
|
|
||||||
Logger.Error(e, "An unexpected error occurred.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task FetchServerExecutableFile(HttpClient http, DownloadProgressCallback progressCallback, FileDownloadInfo fileDownloadInfo, string filePath, CancellationToken cancellationToken) {
|
|
||||||
Sha1String downloadedFileHash;
|
|
||||||
|
|
||||||
try {
|
|
||||||
var response = await http.GetAsync(fileDownloadInfo.DownloadUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
|
|
||||||
await using var fileStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write, FileShare.Read);
|
|
||||||
await using var responseStream = await response.Content.ReadAsStreamAsync(cancellationToken);
|
|
||||||
|
|
||||||
using var streamCopier = new MinecraftServerDownloadStreamCopier(progressCallback, fileDownloadInfo.Size.Bytes);
|
|
||||||
downloadedFileHash = await streamCopier.Copy(responseStream, fileStream, cancellationToken);
|
|
||||||
} catch (OperationCanceledException) {
|
|
||||||
throw;
|
|
||||||
} catch (Exception e) {
|
|
||||||
Logger.Error(e, "Unable to download server executable.");
|
|
||||||
throw StopProcedureException.Instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!downloadedFileHash.Equals(fileDownloadInfo.Hash)) {
|
|
||||||
Logger.Error("Downloaded server executable has mismatched SHA1 hash. Expected {Expected}, got {Actual}.", fileDownloadInfo.Hash, downloadedFileHash);
|
|
||||||
throw StopProcedureException.Instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void TryDeleteExecutableAfterFailure(string filePath) {
|
|
||||||
if (File.Exists(filePath)) {
|
|
||||||
try {
|
|
||||||
File.Delete(filePath);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Logger.Warning(e, "Could not clean up partially downloaded server executable: {FilePath}", filePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private sealed class MinecraftServerDownloadStreamCopier : IDisposable {
|
|
||||||
private readonly StreamCopier streamCopier = new ();
|
|
||||||
private readonly IncrementalHash sha1 = IncrementalHash.CreateHash(HashAlgorithmName.SHA1);
|
|
||||||
|
|
||||||
private readonly DownloadProgressCallback progressCallback;
|
|
||||||
private readonly ulong totalBytes;
|
|
||||||
private ulong readBytes;
|
|
||||||
|
|
||||||
public MinecraftServerDownloadStreamCopier(DownloadProgressCallback progressCallback, ulong totalBytes) {
|
|
||||||
this.progressCallback = progressCallback;
|
|
||||||
this.totalBytes = totalBytes;
|
|
||||||
this.streamCopier.BufferReady += OnBufferReady;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnBufferReady(object? sender, StreamCopier.BufferEventArgs args) {
|
|
||||||
sha1.AppendData(args.Buffer.Span);
|
|
||||||
|
|
||||||
readBytes += (uint) args.Buffer.Length;
|
|
||||||
progressCallback.ReportProgress(readBytes, totalBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<Sha1String> Copy(Stream source, Stream destination, CancellationToken cancellationToken) {
|
|
||||||
await streamCopier.Copy(source, destination, cancellationToken);
|
|
||||||
return Sha1String.FromBytes(sha1.GetHashAndReset());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() {
|
|
||||||
sha1.Dispose();
|
|
||||||
streamCopier.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
using System.Text.RegularExpressions;
|
|
||||||
using Phantom.Common.Data.Minecraft;
|
|
||||||
using Phantom.Utils.IO;
|
|
||||||
using Phantom.Utils.Logging;
|
|
||||||
using Serilog;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Server;
|
|
||||||
|
|
||||||
public sealed partial class MinecraftServerExecutables {
|
|
||||||
private static readonly ILogger Logger = PhantomLogger.Create<MinecraftServerExecutables>();
|
|
||||||
|
|
||||||
[GeneratedRegex(@"[^a-zA-Z0-9_\-\.]", RegexOptions.Compiled)]
|
|
||||||
private static partial Regex SanitizePathRegex();
|
|
||||||
|
|
||||||
private readonly string basePath;
|
|
||||||
private readonly Dictionary<string, MinecraftServerExecutableDownloader> runningDownloadersByVersion = new ();
|
|
||||||
|
|
||||||
public MinecraftServerExecutables(string basePath) {
|
|
||||||
this.basePath = basePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal async Task<string?> DownloadAndGetPath(FileDownloadInfo? fileDownloadInfo, string minecraftVersion, EventHandler<DownloadProgressEventArgs> progressEventHandler, CancellationToken cancellationToken) {
|
|
||||||
string serverExecutableFolderPath = Path.Combine(basePath, SanitizePathRegex().IsMatch(minecraftVersion) ? SanitizePathRegex().Replace(minecraftVersion, "_") : minecraftVersion);
|
|
||||||
string serverExecutableFilePath = Path.Combine(serverExecutableFolderPath, "server.jar");
|
|
||||||
|
|
||||||
if (File.Exists(serverExecutableFilePath)) {
|
|
||||||
return serverExecutableFilePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fileDownloadInfo == null) {
|
|
||||||
Logger.Error("Unable to download server executable for version {Version} because no download info was provided.", minecraftVersion);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Directories.Create(serverExecutableFolderPath, Chmod.URWX_GRX);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Logger.Error(e, "Unable to create folder for server executable: {ServerExecutableFolderPath}", serverExecutableFolderPath);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
MinecraftServerExecutableDownloader? downloader;
|
|
||||||
MinecraftServerExecutableDownloadListener listener = new (progressEventHandler, cancellationToken);
|
|
||||||
|
|
||||||
lock (this) {
|
|
||||||
if (runningDownloadersByVersion.TryGetValue(minecraftVersion, out downloader)) {
|
|
||||||
Logger.Information("A download for server version {Version} is already running, waiting for it to finish...", minecraftVersion);
|
|
||||||
downloader.Register(listener);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
downloader = new MinecraftServerExecutableDownloader(fileDownloadInfo, minecraftVersion, serverExecutableFilePath, listener);
|
|
||||||
downloader.Completed += (_, _) => {
|
|
||||||
lock (this) {
|
|
||||||
runningDownloadersByVersion.Remove(minecraftVersion);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
runningDownloadersByVersion[minecraftVersion] = downloader;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return await downloader.Task.WaitAsync(cancellationToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Phantom.Agent.Minecraft.Java;
|
using Phantom.Agent.Services.Java;
|
||||||
using Phantom.Utils.Collections;
|
using Phantom.Utils.Collections;
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Tests.Java;
|
namespace Phantom.Agent.Services.Tests.Java;
|
||||||
|
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public sealed class JavaPropertiesStreamTests {
|
public sealed class JavaPropertiesStreamTests {
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Phantom.Agent.Minecraft\Phantom.Agent.Minecraft.csproj" />
|
<ProjectReference Include="..\Phantom.Agent.Services\Phantom.Agent.Services.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -7,12 +7,12 @@ namespace Phantom.Agent.Services;
|
|||||||
public sealed class AgentFolders {
|
public sealed class AgentFolders {
|
||||||
private static readonly ILogger Logger = PhantomLogger.Create<AgentFolders>();
|
private static readonly ILogger Logger = PhantomLogger.Create<AgentFolders>();
|
||||||
|
|
||||||
public string DataFolderPath { get; }
|
internal string DataFolderPath { get; }
|
||||||
public string InstancesFolderPath { get; }
|
internal string InstancesFolderPath { get; }
|
||||||
public string BackupsFolderPath { get; }
|
internal string BackupsFolderPath { get; }
|
||||||
|
|
||||||
public string TemporaryFolderPath { get; }
|
internal string TemporaryFolderPath { get; }
|
||||||
public string ServerExecutableFolderPath { get; }
|
internal string ServerExecutableFolderPath { get; }
|
||||||
|
|
||||||
public string JavaSearchFolderPath { get; }
|
public string JavaSearchFolderPath { get; }
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public sealed class AgentRegistrationHandler {
|
|||||||
foreach (var configureInstanceMessage in configureInstanceMessages) {
|
foreach (var configureInstanceMessage in configureInstanceMessages) {
|
||||||
var configureInstanceResult = await agentServices.InstanceManager.Request(GetCommand(configureInstanceMessage), cancellationToken);
|
var configureInstanceResult = await agentServices.InstanceManager.Request(GetCommand(configureInstanceMessage), cancellationToken);
|
||||||
if (!configureInstanceResult.Is(ConfigureInstanceResult.Success)) {
|
if (!configureInstanceResult.Is(ConfigureInstanceResult.Success)) {
|
||||||
logger.Fatal("Unable to configure instance \"{Name}\" (GUID {Guid}), shutting down.", configureInstanceMessage.Configuration.InstanceName, configureInstanceMessage.InstanceGuid);
|
logger.Fatal("Unable to configure instance \"{Name}\" (GUID {Guid}), shutting down.", configureInstanceMessage.Info.InstanceName, configureInstanceMessage.InstanceGuid);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ public sealed class AgentRegistrationHandler {
|
|||||||
foreach (var configureInstanceMessage in configureInstanceMessages) {
|
foreach (var configureInstanceMessage in configureInstanceMessages) {
|
||||||
var configureInstanceResult = await agentServices.InstanceManager.Request(GetCommand(configureInstanceMessage), cancellationToken);
|
var configureInstanceResult = await agentServices.InstanceManager.Request(GetCommand(configureInstanceMessage), cancellationToken);
|
||||||
if (!configureInstanceResult.Is(ConfigureInstanceResult.Success)) {
|
if (!configureInstanceResult.Is(ConfigureInstanceResult.Success)) {
|
||||||
logger.Error("Unable to configure instance \"{Name}\" (GUID {Guid}).", configureInstanceMessage.Configuration.InstanceName, configureInstanceMessage.InstanceGuid);
|
logger.Error("Unable to configure instance \"{Name}\" (GUID {Guid}).", configureInstanceMessage.Info.InstanceName, configureInstanceMessage.InstanceGuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,9 +76,10 @@ public sealed class AgentRegistrationHandler {
|
|||||||
private static InstanceManagerActor.ConfigureInstanceCommand GetCommand(ConfigureInstanceMessage configureInstanceMessage) {
|
private static InstanceManagerActor.ConfigureInstanceCommand GetCommand(ConfigureInstanceMessage configureInstanceMessage) {
|
||||||
return new InstanceManagerActor.ConfigureInstanceCommand(
|
return new InstanceManagerActor.ConfigureInstanceCommand(
|
||||||
configureInstanceMessage.InstanceGuid,
|
configureInstanceMessage.InstanceGuid,
|
||||||
configureInstanceMessage.Configuration,
|
configureInstanceMessage.Info,
|
||||||
configureInstanceMessage.LaunchProperties,
|
configureInstanceMessage.LaunchRecipe,
|
||||||
configureInstanceMessage.LaunchNow,
|
configureInstanceMessage.LaunchNow,
|
||||||
|
configureInstanceMessage.StopRecipe,
|
||||||
AlwaysReportStatus: true
|
AlwaysReportStatus: true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Akka.Actor;
|
using Akka.Actor;
|
||||||
using Phantom.Agent.Minecraft.Java;
|
|
||||||
using Phantom.Agent.Services.Backups;
|
using Phantom.Agent.Services.Backups;
|
||||||
using Phantom.Agent.Services.Instances;
|
using Phantom.Agent.Services.Instances;
|
||||||
|
using Phantom.Agent.Services.Java;
|
||||||
using Phantom.Agent.Services.Rpc;
|
using Phantom.Agent.Services.Rpc;
|
||||||
using Phantom.Common.Data.Agent;
|
using Phantom.Common.Data.Agent;
|
||||||
using Phantom.Utils.Actor;
|
using Phantom.Utils.Actor;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Formats.Tar;
|
using System.Formats.Tar;
|
||||||
using Phantom.Agent.Minecraft.Instance;
|
using Phantom.Agent.Services.Instances;
|
||||||
using Phantom.Common.Data.Backups;
|
using Phantom.Common.Data.Backups;
|
||||||
using Phantom.Utils.IO;
|
using Phantom.Utils.IO;
|
||||||
using Phantom.Utils.Logging;
|
using Phantom.Utils.Logging;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Phantom.Agent.Minecraft.Instance;
|
using Phantom.Agent.Services.Instances.State;
|
||||||
using Phantom.Common.Data.Backups;
|
using Phantom.Common.Data.Backups;
|
||||||
using Phantom.Utils.Logging;
|
using Phantom.Utils.Logging;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Phantom.Agent.Minecraft.Command;
|
using Phantom.Agent.Services.Games;
|
||||||
using Phantom.Agent.Minecraft.Instance;
|
using Phantom.Agent.Services.Instances.State;
|
||||||
using Phantom.Utils.Tasks;
|
using Phantom.Utils.Tasks;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
namespace Phantom.Agent.Minecraft.Server;
|
namespace Phantom.Agent.Services.Downloads;
|
||||||
|
|
||||||
public sealed class DownloadProgressEventArgs : EventArgs {
|
sealed class DownloadProgressEventArgs : EventArgs {
|
||||||
public ulong DownloadedBytes { get; }
|
public ulong DownloadedBytes { get; }
|
||||||
public ulong TotalBytes { get; }
|
public ulong? TotalBytes { get; }
|
||||||
|
|
||||||
internal DownloadProgressEventArgs(ulong downloadedBytes, ulong totalBytes) {
|
internal DownloadProgressEventArgs(ulong downloadedBytes, ulong? totalBytes) {
|
||||||
DownloadedBytes = downloadedBytes;
|
DownloadedBytes = downloadedBytes;
|
||||||
TotalBytes = totalBytes;
|
TotalBytes = totalBytes;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Phantom.Agent.Services.Downloads;
|
||||||
|
|
||||||
|
sealed record FileDownloadListener(EventHandler<DownloadProgressEventArgs> DownloadProgressEventHandler, CancellationToken CancellationToken);
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
using Phantom.Common.Data.Agent;
|
||||||
|
using Phantom.Utils.IO;
|
||||||
|
using Phantom.Utils.Logging;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
|
namespace Phantom.Agent.Services.Downloads;
|
||||||
|
|
||||||
|
sealed class FileDownloadManager {
|
||||||
|
private static readonly ILogger Logger = PhantomLogger.Create<FileDownloadManager>();
|
||||||
|
|
||||||
|
private readonly Dictionary<string, FileDownloader> runningDownloadersByPath = new ();
|
||||||
|
|
||||||
|
public async Task<string?> DownloadAndGetPath(FileDownloadInfo fileDownloadInfo, string filePath, EventHandler<DownloadProgressEventArgs> progressEventHandler, CancellationToken cancellationToken) {
|
||||||
|
var fileInfo = new FileInfo(filePath);
|
||||||
|
if (fileInfo.Exists) {
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
filePath = fileInfo.FullName;
|
||||||
|
|
||||||
|
if (Directory.GetParent(filePath) is {} parentPath) {
|
||||||
|
try {
|
||||||
|
Directories.Create(parentPath.FullName, Chmod.URWX_GRX);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.Error(e, "Unable to create folder: {FolderName}", parentPath.FullName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FileDownloader? downloader;
|
||||||
|
FileDownloadListener listener = new (progressEventHandler, cancellationToken);
|
||||||
|
|
||||||
|
lock (this) {
|
||||||
|
if (runningDownloadersByPath.TryGetValue(filePath, out downloader)) {
|
||||||
|
Logger.Information("A download for {Path} is already running, waiting for it to finish...", filePath);
|
||||||
|
downloader.Register(listener);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
downloader = new FileDownloader(fileDownloadInfo, filePath, listener);
|
||||||
|
downloader.Completed += (_, _) => {
|
||||||
|
lock (this) {
|
||||||
|
runningDownloadersByPath.Remove(filePath);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
runningDownloadersByPath[filePath] = downloader;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return await downloader.Task.WaitAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
201
Agent/Phantom.Agent.Services/Downloads/FileDownloader.cs
Normal file
201
Agent/Phantom.Agent.Services/Downloads/FileDownloader.cs
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
using System.Security.Cryptography;
|
||||||
|
using Phantom.Common.Data.Agent;
|
||||||
|
using Phantom.Utils.Cryptography;
|
||||||
|
using Phantom.Utils.IO;
|
||||||
|
using Phantom.Utils.Logging;
|
||||||
|
using Phantom.Utils.Runtime;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
|
namespace Phantom.Agent.Services.Downloads;
|
||||||
|
|
||||||
|
sealed class FileDownloader {
|
||||||
|
private static readonly ILogger Logger = PhantomLogger.Create<FileDownloader>();
|
||||||
|
|
||||||
|
public Task<string?> Task { get; }
|
||||||
|
public event EventHandler<DownloadProgressEventArgs>? DownloadProgress;
|
||||||
|
public event EventHandler? Completed;
|
||||||
|
|
||||||
|
private readonly CancellationTokenSource cancellationTokenSource = new ();
|
||||||
|
|
||||||
|
private readonly List<CancellationTokenRegistration> listenerCancellationRegistrations = [];
|
||||||
|
private int listenerCount = 0;
|
||||||
|
|
||||||
|
public FileDownloader(FileDownloadInfo fileDownloadInfo, string filePath, FileDownloadListener listener) {
|
||||||
|
Register(listener);
|
||||||
|
Task = DownloadFileAndGetFinalPath(fileDownloadInfo, filePath, new DownloadProgressCallback(this), cancellationTokenSource.Token);
|
||||||
|
Task.ContinueWith(OnCompleted, TaskScheduler.Default);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Register(FileDownloadListener listener) {
|
||||||
|
int newListenerCount;
|
||||||
|
|
||||||
|
lock (this) {
|
||||||
|
newListenerCount = ++listenerCount;
|
||||||
|
|
||||||
|
DownloadProgress += listener.DownloadProgressEventHandler;
|
||||||
|
listenerCancellationRegistrations.Add(listener.CancellationToken.Register(Unregister, listener));
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.Debug("Registered download listener, current listener count: {Listeners}", newListenerCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Unregister(object? listenerObject) {
|
||||||
|
int newListenerCount;
|
||||||
|
|
||||||
|
lock (this) {
|
||||||
|
FileDownloadListener listener = (FileDownloadListener) listenerObject!;
|
||||||
|
DownloadProgress -= listener.DownloadProgressEventHandler;
|
||||||
|
|
||||||
|
newListenerCount = --listenerCount;
|
||||||
|
if (newListenerCount <= 0) {
|
||||||
|
cancellationTokenSource.Cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newListenerCount <= 0) {
|
||||||
|
Logger.Debug("Unregistered last download listener, cancelling download.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Logger.Debug("Unregistered download listener, current listener count: {Listeners}", newListenerCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReportDownloadProgress(DownloadProgressEventArgs args) {
|
||||||
|
DownloadProgress?.Invoke(this, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCompleted(Task task) {
|
||||||
|
Logger.Debug("Download task completed.");
|
||||||
|
|
||||||
|
lock (this) {
|
||||||
|
Completed?.Invoke(this, EventArgs.Empty);
|
||||||
|
Completed = null;
|
||||||
|
DownloadProgress = null;
|
||||||
|
|
||||||
|
foreach (var registration in listenerCancellationRegistrations) {
|
||||||
|
registration.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
listenerCancellationRegistrations.Clear();
|
||||||
|
cancellationTokenSource.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class DownloadProgressCallback(FileDownloader downloader) {
|
||||||
|
public void ReportProgress(ulong downloadedBytes, ulong? totalBytes) {
|
||||||
|
downloader.ReportDownloadProgress(new DownloadProgressEventArgs(downloadedBytes, totalBytes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task<string?> DownloadFileAndGetFinalPath(FileDownloadInfo fileDownloadInfo, string filePath, DownloadProgressCallback progressCallback, CancellationToken cancellationToken) {
|
||||||
|
string tmpFilePath = filePath + ".tmp";
|
||||||
|
|
||||||
|
try {
|
||||||
|
await DownloadFile(tmpFilePath, fileDownloadInfo, progressCallback, cancellationToken);
|
||||||
|
MoveDownloadedFile(filePath, tmpFilePath);
|
||||||
|
} catch (Exception) {
|
||||||
|
TryDeletePartiallyDownloadedFile(tmpFilePath);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task DownloadFile(string filePath, FileDownloadInfo fileDownloadInfo, DownloadProgressCallback progressCallback, CancellationToken cancellationToken) {
|
||||||
|
string downloadUrl = fileDownloadInfo.Url;
|
||||||
|
|
||||||
|
DownloadResult result;
|
||||||
|
try {
|
||||||
|
var httpClient = new HttpClient();
|
||||||
|
var response = await httpClient.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
FileSize? fileSize = response.Content.Headers.ContentLength is {} length and >= 0 ? new FileSize((ulong) length) : null;
|
||||||
|
ulong? fileSizeBytes = fileSize?.Bytes;
|
||||||
|
|
||||||
|
Logger.Information("Downloading {Url} ({Size})...", downloadUrl, FormatFileSize(fileSize));
|
||||||
|
progressCallback.ReportProgress(downloadedBytes: 0, fileSizeBytes);
|
||||||
|
|
||||||
|
await using var fileStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write, FileShare.Read);
|
||||||
|
await using var responseStream = await response.Content.ReadAsStreamAsync(cancellationToken);
|
||||||
|
|
||||||
|
using var streamCopier = new DownloadStreamCopier(progressCallback, fileSizeBytes);
|
||||||
|
result = await streamCopier.Copy(responseStream, fileStream, cancellationToken);
|
||||||
|
} catch (OperationCanceledException) {
|
||||||
|
Logger.Information("File download was cancelled: {Url}", downloadUrl);
|
||||||
|
throw;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.Error(e, "Could not download file: {Url}", downloadUrl);
|
||||||
|
throw StopProcedureException.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileDownloadInfo.Hash is {} expectedHash && !result.Hash.Equals(expectedHash)) {
|
||||||
|
Logger.Error("Downloaded file from {Url} has mismatched SHA1 hash. Expected {Expected}, got {Actual}.", downloadUrl, expectedHash, result.Hash);
|
||||||
|
throw StopProcedureException.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.Information("Finished downloading {Url} ({Size}).", downloadUrl, FormatFileSize(result.Size));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string FormatFileSize(FileSize? fileSize) {
|
||||||
|
return fileSize?.ToHumanReadable(decimalPlaces: 1) ?? "unknown size";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void MoveDownloadedFile(string filePath, string tmpFilePath) {
|
||||||
|
try {
|
||||||
|
File.Move(tmpFilePath, filePath, overwrite: true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.Error(e, "Could not move downloaded file from {SourcePath} to {TargetPath}", tmpFilePath, filePath);
|
||||||
|
throw StopProcedureException.Instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void TryDeletePartiallyDownloadedFile(string filePath) {
|
||||||
|
if (!File.Exists(filePath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
File.Delete(filePath);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.Warning(e, "Could not clean up partially downloaded file: {FilePath}", filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class DownloadStreamCopier : IDisposable {
|
||||||
|
private readonly StreamCopier streamCopier = new ();
|
||||||
|
private readonly IncrementalHash sha1 = IncrementalHash.CreateHash(HashAlgorithmName.SHA1);
|
||||||
|
|
||||||
|
private readonly DownloadProgressCallback progressCallback;
|
||||||
|
private readonly ulong? totalBytes;
|
||||||
|
private ulong readBytes;
|
||||||
|
|
||||||
|
public DownloadStreamCopier(DownloadProgressCallback progressCallback, ulong? totalBytes) {
|
||||||
|
this.progressCallback = progressCallback;
|
||||||
|
this.totalBytes = totalBytes;
|
||||||
|
this.streamCopier.BufferReady += OnBufferReady;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBufferReady(object? sender, StreamCopier.BufferEventArgs args) {
|
||||||
|
sha1.AppendData(args.Buffer.Span);
|
||||||
|
|
||||||
|
readBytes += (uint) args.Buffer.Length;
|
||||||
|
progressCallback.ReportProgress(readBytes, totalBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<DownloadResult> Copy(Stream source, Stream destination, CancellationToken cancellationToken) {
|
||||||
|
await streamCopier.Copy(source, destination, cancellationToken);
|
||||||
|
|
||||||
|
FileSize size = new FileSize(readBytes);
|
||||||
|
Sha1String hash = Sha1String.FromBytes(sha1.GetHashAndReset());
|
||||||
|
return new DownloadResult(size, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
sha1.Dispose();
|
||||||
|
streamCopier.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly record struct DownloadResult(FileSize Size, Sha1String Hash);
|
||||||
|
}
|
||||||
10
Agent/Phantom.Agent.Services/Games/MinecraftCommand.cs
Normal file
10
Agent/Phantom.Agent.Services/Games/MinecraftCommand.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Phantom.Agent.Services.Games;
|
||||||
|
|
||||||
|
static class MinecraftCommand {
|
||||||
|
public const string SaveOn = "save-on";
|
||||||
|
public const string SaveOff = "save-off";
|
||||||
|
|
||||||
|
public static string SaveAll(bool flush) {
|
||||||
|
return flush ? "save-all flush" : "save-all";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,9 +5,9 @@ using System.Net.Sockets;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Server;
|
namespace Phantom.Agent.Services.Games;
|
||||||
|
|
||||||
public static class ServerStatusProtocol {
|
static class MinecraftServerStatusProtocol {
|
||||||
public static async Task<InstancePlayerCounts> GetPlayerCounts(ushort serverPort, CancellationToken cancellationToken) {
|
public static async Task<InstancePlayerCounts> GetPlayerCounts(ushort serverPort, CancellationToken cancellationToken) {
|
||||||
using var tcpClient = new TcpClient();
|
using var tcpClient = new TcpClient();
|
||||||
await tcpClient.ConnectAsync(IPAddress.Loopback, serverPort, cancellationToken);
|
await tcpClient.ConnectAsync(IPAddress.Loopback, serverPort, cancellationToken);
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
using Phantom.Agent.Minecraft.Launcher;
|
using Phantom.Agent.Services.Backups;
|
||||||
using Phantom.Agent.Services.Backups;
|
using Phantom.Agent.Services.Instances.Launch;
|
||||||
using Phantom.Agent.Services.Instances.State;
|
using Phantom.Agent.Services.Instances.State;
|
||||||
using Phantom.Agent.Services.Rpc;
|
using Phantom.Agent.Services.Rpc;
|
||||||
|
using Phantom.Common.Data.Agent.Instance;
|
||||||
|
using Phantom.Common.Data.Agent.Instance.Stop;
|
||||||
using Phantom.Common.Data.Backups;
|
using Phantom.Common.Data.Backups;
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
using Phantom.Common.Data.Minecraft;
|
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
using Phantom.Common.Messages.Agent.ToController;
|
using Phantom.Common.Messages.Agent.ToController;
|
||||||
using Phantom.Utils.Actor;
|
using Phantom.Utils.Actor;
|
||||||
@@ -82,9 +83,9 @@ sealed class InstanceActor : ReceiveActor<InstanceActor.ICommand> {
|
|||||||
|
|
||||||
public sealed record ReportInstanceStatusCommand : ICommand;
|
public sealed record ReportInstanceStatusCommand : ICommand;
|
||||||
|
|
||||||
public sealed record LaunchInstanceCommand(InstanceConfiguration Configuration, IServerLauncher Launcher, InstanceTicketManager.Ticket Ticket, bool IsRestarting) : ICommand;
|
public sealed record LaunchInstanceCommand(InstanceInfo Info, InstanceLauncher Launcher, InstanceTicketManager.Ticket Ticket, bool IsRestarting) : ICommand;
|
||||||
|
|
||||||
public sealed record StopInstanceCommand(MinecraftStopStrategy StopStrategy) : ICommand;
|
public sealed record StopInstanceCommand(InstanceStopRecipe StopRecipe) : ICommand;
|
||||||
|
|
||||||
public sealed record SendCommandToInstanceCommand(string Command) : ICommand, ICanReply<SendCommandToInstanceResult>;
|
public sealed record SendCommandToInstanceCommand(string Command) : ICommand, ICanReply<SendCommandToInstanceResult>;
|
||||||
|
|
||||||
@@ -92,7 +93,7 @@ sealed class InstanceActor : ReceiveActor<InstanceActor.ICommand> {
|
|||||||
|
|
||||||
public sealed record HandleProcessEndedCommand(IInstanceStatus Status) : ICommand, IJumpAhead;
|
public sealed record HandleProcessEndedCommand(IInstanceStatus Status) : ICommand, IJumpAhead;
|
||||||
|
|
||||||
public sealed record ShutdownCommand : ICommand;
|
public sealed record ShutdownCommand(InstanceStopRecipe StopRecipe) : ICommand;
|
||||||
|
|
||||||
private void ReportInstanceStatus(ReportInstanceStatusCommand command) {
|
private void ReportInstanceStatus(ReportInstanceStatusCommand command) {
|
||||||
ReportCurrentStatus();
|
ReportCurrentStatus();
|
||||||
@@ -100,9 +101,14 @@ sealed class InstanceActor : ReceiveActor<InstanceActor.ICommand> {
|
|||||||
|
|
||||||
private async Task LaunchInstance(LaunchInstanceCommand command) {
|
private async Task LaunchInstance(LaunchInstanceCommand command) {
|
||||||
if (command.IsRestarting || runningState is null) {
|
if (command.IsRestarting || runningState is null) {
|
||||||
SetAndReportStatus(command.IsRestarting ? InstanceStatus.Restarting : InstanceStatus.Launching);
|
var defaultLaunchStatus = command.IsRestarting ? InstanceStatus.Restarting : InstanceStatus.Launching;
|
||||||
|
SetAndReportStatus(defaultLaunchStatus);
|
||||||
|
|
||||||
var newState = await InstanceLaunchProcedure.Run(context, command.Configuration, command.Launcher, instanceTicketManager, command.Ticket, SetAndReportStatus, shutdownCancellationToken);
|
void UpdateStatus(IInstanceStatus? newStatus) {
|
||||||
|
SetAndReportStatus(newStatus ?? defaultLaunchStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
var newState = await InstanceLaunchProcedure.Run(context, command.Info, command.Launcher, instanceTicketManager, command.Ticket, UpdateStatus, shutdownCancellationToken);
|
||||||
if (newState is null) {
|
if (newState is null) {
|
||||||
instanceTicketManager.Release(command.Ticket);
|
instanceTicketManager.Release(command.Ticket);
|
||||||
}
|
}
|
||||||
@@ -119,7 +125,7 @@ sealed class InstanceActor : ReceiveActor<InstanceActor.ICommand> {
|
|||||||
IInstanceStatus oldStatus = currentStatus;
|
IInstanceStatus oldStatus = currentStatus;
|
||||||
SetAndReportStatus(InstanceStatus.Stopping);
|
SetAndReportStatus(InstanceStatus.Stopping);
|
||||||
|
|
||||||
if (await InstanceStopProcedure.Run(context, command.StopStrategy, runningState, SetAndReportStatus, shutdownCancellationToken)) {
|
if (await InstanceStopProcedure.Run(context, command.StopRecipe, runningState, SetAndReportStatus, shutdownCancellationToken)) {
|
||||||
instanceTicketManager.Release(runningState.Ticket);
|
instanceTicketManager.Release(runningState.Ticket);
|
||||||
TransitionState(null);
|
TransitionState(null);
|
||||||
}
|
}
|
||||||
@@ -161,7 +167,7 @@ sealed class InstanceActor : ReceiveActor<InstanceActor.ICommand> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task Shutdown(ShutdownCommand command) {
|
private async Task Shutdown(ShutdownCommand command) {
|
||||||
await StopInstance(new StopInstanceCommand(MinecraftStopStrategy.Instant));
|
await StopInstance(new StopInstanceCommand(command.StopRecipe));
|
||||||
await actorCancellationTokenSource.CancelAsync();
|
await actorCancellationTokenSource.CancelAsync();
|
||||||
|
|
||||||
await Task.WhenAll(
|
await Task.WhenAll(
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
using Phantom.Agent.Minecraft.Instance;
|
using Phantom.Agent.Services.Backups;
|
||||||
using Phantom.Agent.Minecraft.Java;
|
using Phantom.Agent.Services.Downloads;
|
||||||
using Phantom.Agent.Minecraft.Launcher;
|
using Phantom.Agent.Services.Instances.Launch;
|
||||||
using Phantom.Agent.Minecraft.Launcher.Types;
|
using Phantom.Agent.Services.Java;
|
||||||
using Phantom.Agent.Minecraft.Properties;
|
|
||||||
using Phantom.Agent.Minecraft.Server;
|
|
||||||
using Phantom.Agent.Services.Backups;
|
|
||||||
using Phantom.Agent.Services.Rpc;
|
using Phantom.Agent.Services.Rpc;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
|
using Phantom.Common.Data.Agent.Instance;
|
||||||
|
using Phantom.Common.Data.Agent.Instance.Launch;
|
||||||
|
using Phantom.Common.Data.Agent.Instance.Stop;
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
using Phantom.Common.Data.Minecraft;
|
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
using Phantom.Utils.Actor;
|
using Phantom.Utils.Actor;
|
||||||
using Phantom.Utils.IO;
|
using Phantom.Utils.IO;
|
||||||
@@ -27,11 +26,11 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly AgentState agentState;
|
private readonly AgentState agentState;
|
||||||
private readonly string basePath;
|
private readonly AgentFolders agentFolders;
|
||||||
|
|
||||||
private readonly InstanceServices instanceServices;
|
private readonly InstanceServices instanceServices;
|
||||||
private readonly InstanceTicketManager instanceTicketManager;
|
private readonly InstanceTicketManager instanceTicketManager;
|
||||||
private readonly Dictionary<Guid, InstanceInfo> instances = new ();
|
private readonly Dictionary<Guid, Instance> instances = new ();
|
||||||
|
|
||||||
private readonly CancellationTokenSource shutdownCancellationTokenSource = new ();
|
private readonly CancellationTokenSource shutdownCancellationTokenSource = new ();
|
||||||
private readonly CancellationToken shutdownCancellationToken;
|
private readonly CancellationToken shutdownCancellationToken;
|
||||||
@@ -40,15 +39,12 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
|
|
||||||
private InstanceManagerActor(Init init) {
|
private InstanceManagerActor(Init init) {
|
||||||
this.agentState = init.AgentState;
|
this.agentState = init.AgentState;
|
||||||
this.basePath = init.AgentFolders.InstancesFolderPath;
|
this.agentFolders = init.AgentFolders;
|
||||||
|
|
||||||
|
this.instanceServices = new InstanceServices(init.ControllerConnection, init.BackupManager, new FileDownloadManager(), init.JavaRuntimeRepository);
|
||||||
this.instanceTicketManager = init.InstanceTicketManager;
|
this.instanceTicketManager = init.InstanceTicketManager;
|
||||||
this.shutdownCancellationToken = shutdownCancellationTokenSource.Token;
|
this.shutdownCancellationToken = shutdownCancellationTokenSource.Token;
|
||||||
|
|
||||||
var minecraftServerExecutables = new MinecraftServerExecutables(init.AgentFolders.ServerExecutableFolderPath);
|
|
||||||
var launchServices = new LaunchServices(minecraftServerExecutables, init.JavaRuntimeRepository);
|
|
||||||
|
|
||||||
this.instanceServices = new InstanceServices(init.ControllerConnection, init.BackupManager, launchServices);
|
|
||||||
|
|
||||||
ReceiveAndReply<ConfigureInstanceCommand, Result<ConfigureInstanceResult, InstanceActionFailure>>(ConfigureInstance);
|
ReceiveAndReply<ConfigureInstanceCommand, Result<ConfigureInstanceResult, InstanceActionFailure>>(ConfigureInstance);
|
||||||
ReceiveAndReply<LaunchInstanceCommand, Result<LaunchInstanceResult, InstanceActionFailure>>(LaunchInstance);
|
ReceiveAndReply<LaunchInstanceCommand, Result<LaunchInstanceResult, InstanceActionFailure>>(LaunchInstance);
|
||||||
ReceiveAndReply<StopInstanceCommand, Result<StopInstanceResult, InstanceActionFailure>>(StopInstance);
|
ReceiveAndReply<StopInstanceCommand, Result<StopInstanceResult, InstanceActionFailure>>(StopInstance);
|
||||||
@@ -56,15 +52,15 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
ReceiveAsync<ShutdownCommand>(Shutdown);
|
ReceiveAsync<ShutdownCommand>(Shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed record InstanceInfo(ActorRef<InstanceActor.ICommand> Actor, InstanceConfiguration Configuration, IServerLauncher Launcher);
|
private sealed record Instance(ActorRef<InstanceActor.ICommand> Actor, InstanceInfo Info, InstanceProperties Properties, InstanceLaunchRecipe? LaunchRecipe, InstanceStopRecipe StopRecipe);
|
||||||
|
|
||||||
public interface ICommand;
|
public interface ICommand;
|
||||||
|
|
||||||
public sealed record ConfigureInstanceCommand(Guid InstanceGuid, InstanceConfiguration Configuration, InstanceLaunchProperties LaunchProperties, bool LaunchNow, bool AlwaysReportStatus) : ICommand, ICanReply<Result<ConfigureInstanceResult, InstanceActionFailure>>;
|
public sealed record ConfigureInstanceCommand(Guid InstanceGuid, InstanceInfo InstanceInfo, InstanceLaunchRecipe? LaunchRecipe, bool LaunchNow, InstanceStopRecipe StopRecipe, bool AlwaysReportStatus) : ICommand, ICanReply<Result<ConfigureInstanceResult, InstanceActionFailure>>;
|
||||||
|
|
||||||
public sealed record LaunchInstanceCommand(Guid InstanceGuid) : ICommand, ICanReply<Result<LaunchInstanceResult, InstanceActionFailure>>;
|
public sealed record LaunchInstanceCommand(Guid InstanceGuid) : ICommand, ICanReply<Result<LaunchInstanceResult, InstanceActionFailure>>;
|
||||||
|
|
||||||
public sealed record StopInstanceCommand(Guid InstanceGuid, MinecraftStopStrategy StopStrategy) : ICommand, ICanReply<Result<StopInstanceResult, InstanceActionFailure>>;
|
public sealed record StopInstanceCommand(Guid InstanceGuid, InstanceStopRecipe StopRecipe) : ICommand, ICanReply<Result<StopInstanceResult, InstanceActionFailure>>;
|
||||||
|
|
||||||
public sealed record SendCommandToInstanceCommand(Guid InstanceGuid, string Command) : ICommand, ICanReply<Result<SendCommandToInstanceResult, InstanceActionFailure>>;
|
public sealed record SendCommandToInstanceCommand(Guid InstanceGuid, string Command) : ICommand, ICanReply<Result<SendCommandToInstanceResult, InstanceActionFailure>>;
|
||||||
|
|
||||||
@@ -72,41 +68,18 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
|
|
||||||
private Result<ConfigureInstanceResult, InstanceActionFailure> ConfigureInstance(ConfigureInstanceCommand command) {
|
private Result<ConfigureInstanceResult, InstanceActionFailure> ConfigureInstance(ConfigureInstanceCommand command) {
|
||||||
var instanceGuid = command.InstanceGuid;
|
var instanceGuid = command.InstanceGuid;
|
||||||
var configuration = command.Configuration;
|
var instanceInfo = command.InstanceInfo;
|
||||||
|
var launchRecipe = command.LaunchRecipe;
|
||||||
var instanceFolder = Path.Combine(basePath, instanceGuid.ToString());
|
var stopRecipe = command.StopRecipe;
|
||||||
Directories.Create(instanceFolder, Chmod.URWX_GRX);
|
|
||||||
|
|
||||||
var heapMegabytes = configuration.MemoryAllocation.InMegabytes;
|
|
||||||
var jvmProperties = new JvmProperties(
|
|
||||||
InitialHeapMegabytes: heapMegabytes / 2,
|
|
||||||
MaximumHeapMegabytes: heapMegabytes
|
|
||||||
);
|
|
||||||
|
|
||||||
var properties = new InstanceProperties(
|
|
||||||
instanceGuid,
|
|
||||||
configuration.JavaRuntimeGuid,
|
|
||||||
jvmProperties,
|
|
||||||
configuration.JvmArguments,
|
|
||||||
instanceFolder,
|
|
||||||
configuration.MinecraftVersion,
|
|
||||||
new ServerProperties(configuration.ServerPort, configuration.RconPort),
|
|
||||||
command.LaunchProperties
|
|
||||||
);
|
|
||||||
|
|
||||||
IServerLauncher launcher = configuration.MinecraftServerKind switch {
|
|
||||||
MinecraftServerKind.Vanilla => new VanillaLauncher(properties),
|
|
||||||
MinecraftServerKind.Fabric => new FabricLauncher(properties),
|
|
||||||
_ => InvalidLauncher.Instance,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (instances.TryGetValue(instanceGuid, out var instance)) {
|
if (instances.TryGetValue(instanceGuid, out var instance)) {
|
||||||
instances[instanceGuid] = instance with {
|
instances[instanceGuid] = instance with {
|
||||||
Configuration = configuration,
|
Info = instanceInfo,
|
||||||
Launcher = launcher,
|
LaunchRecipe = launchRecipe,
|
||||||
|
StopRecipe = stopRecipe,
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.Information("Reconfigured instance \"{Name}\" (GUID {Guid}).", configuration.InstanceName, instanceGuid);
|
Logger.Information("Reconfigured instance \"{Name}\" (GUID {Guid}).", instanceInfo.InstanceName, instanceGuid);
|
||||||
|
|
||||||
if (command.AlwaysReportStatus) {
|
if (command.AlwaysReportStatus) {
|
||||||
instance.Actor.Tell(new InstanceActor.ReportInstanceStatusCommand());
|
instance.Actor.Tell(new InstanceActor.ReportInstanceStatusCommand());
|
||||||
@@ -114,14 +87,23 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var instanceLoggerName = PhantomLogger.ShortenGuid(instanceGuid) + "/" + Interlocked.Increment(ref instanceLoggerSequenceId);
|
var instanceLoggerName = PhantomLogger.ShortenGuid(instanceGuid) + "/" + Interlocked.Increment(ref instanceLoggerSequenceId);
|
||||||
|
var instanceFolder = Path.Combine(agentFolders.InstancesFolderPath, instanceGuid.ToString());
|
||||||
|
var instanceProperties = new InstanceProperties(instanceGuid, instanceFolder);
|
||||||
var instanceInit = new InstanceActor.Init(agentState, instanceGuid, instanceLoggerName, instanceServices, instanceTicketManager, shutdownCancellationToken);
|
var instanceInit = new InstanceActor.Init(agentState, instanceGuid, instanceLoggerName, instanceServices, instanceTicketManager, shutdownCancellationToken);
|
||||||
instances[instanceGuid] = instance = new InstanceInfo(Context.ActorOf(InstanceActor.Factory(instanceInit), "Instance-" + instanceGuid), configuration, launcher);
|
instances[instanceGuid] = instance = new Instance(Context.ActorOf(InstanceActor.Factory(instanceInit), "Instance-" + instanceGuid), instanceInfo, instanceProperties, launchRecipe, stopRecipe);
|
||||||
|
|
||||||
Logger.Information("Created instance \"{Name}\" (GUID {Guid}).", configuration.InstanceName, instanceGuid);
|
Logger.Information("Created instance \"{Name}\" (GUID {Guid}).", instanceInfo.InstanceName, instanceGuid);
|
||||||
|
|
||||||
instance.Actor.Tell(new InstanceActor.ReportInstanceStatusCommand());
|
instance.Actor.Tell(new InstanceActor.ReportInstanceStatusCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Directories.Create(instance.Properties.InstanceFolder, Chmod.URWX_GRX);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.Error(e, "Could not create instance folder: {Path}", instance.Properties.InstanceFolder);
|
||||||
|
return ConfigureInstanceResult.CouldNotCreateInstanceFolder;
|
||||||
|
}
|
||||||
|
|
||||||
if (command.LaunchNow) {
|
if (command.LaunchNow) {
|
||||||
LaunchInstance(new LaunchInstanceCommand(instanceGuid));
|
LaunchInstance(new LaunchInstanceCommand(instanceGuid));
|
||||||
}
|
}
|
||||||
@@ -131,17 +113,21 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
|
|
||||||
private Result<LaunchInstanceResult, InstanceActionFailure> LaunchInstance(LaunchInstanceCommand command) {
|
private Result<LaunchInstanceResult, InstanceActionFailure> LaunchInstance(LaunchInstanceCommand command) {
|
||||||
var instanceGuid = command.InstanceGuid;
|
var instanceGuid = command.InstanceGuid;
|
||||||
if (!instances.TryGetValue(instanceGuid, out var instanceInfo)) {
|
if (!instances.TryGetValue(instanceGuid, out var instance)) {
|
||||||
return InstanceActionFailure.InstanceDoesNotExist;
|
return InstanceActionFailure.InstanceDoesNotExist;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ticket = instanceTicketManager.Reserve(instanceInfo.Configuration);
|
if (instance.LaunchRecipe is not {} launchRecipe) {
|
||||||
|
return LaunchInstanceResult.InvalidConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ticket = instanceTicketManager.Reserve(instance.Info);
|
||||||
if (!ticket) {
|
if (!ticket) {
|
||||||
return ticket.Error;
|
return ticket.Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (agentState.InstancesByGuid.TryGetValue(instanceGuid, out var instance)) {
|
if (agentState.InstancesByGuid.TryGetValue(instanceGuid, out var agentInstance)) {
|
||||||
var status = instance.Status;
|
var status = agentInstance.Status;
|
||||||
if (status.IsRunning()) {
|
if (status.IsRunning()) {
|
||||||
return LaunchInstanceResult.InstanceAlreadyRunning;
|
return LaunchInstanceResult.InstanceAlreadyRunning;
|
||||||
}
|
}
|
||||||
@@ -150,7 +136,12 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
instanceInfo.Actor.Tell(new InstanceActor.LaunchInstanceCommand(instanceInfo.Configuration, instanceInfo.Launcher, ticket.Value, IsRestarting: false));
|
var pathResolver = new InstancePathResolver(agentFolders, instanceServices.JavaRuntimeRepository, instance.Properties);
|
||||||
|
var valueResolver = new InstanceValueResolver(pathResolver);
|
||||||
|
var launcher = new InstanceLauncher(instanceServices.DownloadManager, pathResolver, valueResolver, instance.Properties, launchRecipe);
|
||||||
|
|
||||||
|
instance.Actor.Tell(new InstanceActor.LaunchInstanceCommand(instance.Info, launcher, ticket.Value, IsRestarting: false));
|
||||||
|
|
||||||
return LaunchInstanceResult.LaunchInitiated;
|
return LaunchInstanceResult.LaunchInitiated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +161,7 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
instanceInfo.Actor.Tell(new InstanceActor.StopInstanceCommand(command.StopStrategy));
|
instanceInfo.Actor.Tell(new InstanceActor.StopInstanceCommand(command.StopRecipe));
|
||||||
return StopInstanceResult.StopInitiated;
|
return StopInstanceResult.StopInitiated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +183,7 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
|
|
||||||
await shutdownCancellationTokenSource.CancelAsync();
|
await shutdownCancellationTokenSource.CancelAsync();
|
||||||
|
|
||||||
await Task.WhenAll(instances.Values.Select(static instance => instance.Actor.Stop(new InstanceActor.ShutdownCommand())));
|
await Task.WhenAll(instances.Values.Select(static instance => instance.Actor.Stop(new InstanceActor.ShutdownCommand(instance.StopRecipe))));
|
||||||
instances.Clear();
|
instances.Clear();
|
||||||
|
|
||||||
shutdownCancellationTokenSource.Dispose();
|
shutdownCancellationTokenSource.Dispose();
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Phantom.Agent.Services.Instances;
|
||||||
|
|
||||||
|
sealed record InstanceProperties(
|
||||||
|
Guid InstanceGuid,
|
||||||
|
string InstanceFolder
|
||||||
|
);
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
using Phantom.Agent.Minecraft.Launcher;
|
using Phantom.Agent.Services.Backups;
|
||||||
using Phantom.Agent.Services.Backups;
|
using Phantom.Agent.Services.Downloads;
|
||||||
|
using Phantom.Agent.Services.Java;
|
||||||
using Phantom.Agent.Services.Rpc;
|
using Phantom.Agent.Services.Rpc;
|
||||||
|
|
||||||
namespace Phantom.Agent.Services.Instances;
|
namespace Phantom.Agent.Services.Instances;
|
||||||
|
|
||||||
sealed record InstanceServices(ControllerConnection ControllerConnection, BackupManager BackupManager, LaunchServices LaunchServices);
|
sealed record InstanceServices(
|
||||||
|
ControllerConnection ControllerConnection,
|
||||||
|
BackupManager BackupManager,
|
||||||
|
FileDownloadManager DownloadManager,
|
||||||
|
JavaRuntimeRepository JavaRuntimeRepository
|
||||||
|
);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
using Phantom.Agent.Services.Rpc;
|
using System.Collections.Immutable;
|
||||||
|
using Phantom.Agent.Services.Rpc;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
using Phantom.Common.Data.Agent;
|
using Phantom.Common.Data.Agent;
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Agent.Instance;
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
using Phantom.Common.Messages.Agent.ToController;
|
using Phantom.Common.Messages.Agent.ToController;
|
||||||
using Phantom.Utils.Logging;
|
using Phantom.Utils.Logging;
|
||||||
@@ -18,17 +19,15 @@ sealed class InstanceTicketManager(AgentInfo agentInfo, ControllerConnection con
|
|||||||
private readonly HashSet<ushort> usedPorts = [];
|
private readonly HashSet<ushort> usedPorts = [];
|
||||||
private RamAllocationUnits usedMemory = new ();
|
private RamAllocationUnits usedMemory = new ();
|
||||||
|
|
||||||
public Result<Ticket, LaunchInstanceResult> Reserve(InstanceConfiguration configuration) {
|
public Result<Ticket, LaunchInstanceResult> Reserve(InstanceInfo info) {
|
||||||
var memoryAllocation = configuration.MemoryAllocation;
|
var memoryAllocation = info.MemoryAllocation;
|
||||||
var serverPort = configuration.ServerPort;
|
|
||||||
var rconPort = configuration.RconPort;
|
|
||||||
|
|
||||||
if (!agentInfo.AllowedServerPorts.Contains(serverPort)) {
|
if (!agentInfo.AllowedServerPorts.Contains(info.ServerPort)) {
|
||||||
return LaunchInstanceResult.ServerPortNotAllowed;
|
return LaunchInstanceResult.ServerPortNotAllowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!agentInfo.AllowedRconPorts.Contains(rconPort)) {
|
if (info.AdditionalPorts.Any(port => !agentInfo.AllowedAdditionalPorts.Contains(port))) {
|
||||||
return LaunchInstanceResult.RconPortNotAllowed;
|
return LaunchInstanceResult.AdditionalPortNotAllowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
lock (this) {
|
lock (this) {
|
||||||
@@ -40,23 +39,23 @@ sealed class InstanceTicketManager(AgentInfo agentInfo, ControllerConnection con
|
|||||||
return LaunchInstanceResult.MemoryLimitExceeded;
|
return LaunchInstanceResult.MemoryLimitExceeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usedPorts.Contains(serverPort)) {
|
if (usedPorts.Contains(info.ServerPort)) {
|
||||||
return LaunchInstanceResult.ServerPortAlreadyInUse;
|
return LaunchInstanceResult.ServerPortAlreadyInUse;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usedPorts.Contains(rconPort)) {
|
if (info.AdditionalPorts.Any(port => usedPorts.Contains(port))) {
|
||||||
return LaunchInstanceResult.RconPortAlreadyInUse;
|
return LaunchInstanceResult.AdditionalPortAlreadyInUse;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ticket = new Ticket(Guid.NewGuid(), memoryAllocation, serverPort, rconPort);
|
var ticket = new Ticket(Guid.NewGuid(), memoryAllocation, info.ServerPort, info.AdditionalPorts);
|
||||||
|
|
||||||
activeTicketGuids.Add(ticket.TicketGuid);
|
activeTicketGuids.Add(ticket.TicketGuid);
|
||||||
usedMemory += memoryAllocation;
|
usedMemory += memoryAllocation;
|
||||||
usedPorts.Add(serverPort);
|
usedPorts.Add(ticket.ServerPort);
|
||||||
usedPorts.Add(rconPort);
|
usedPorts.UnionWith(ticket.AdditionalPorts);
|
||||||
|
|
||||||
RefreshAgentStatus();
|
RefreshAgentStatus();
|
||||||
Logger.Debug("Reserved ticket {TicketGuid} (server port {ServerPort}, rcon port {RconPort}, memory allocation {MemoryAllocation} MB).", ticket.TicketGuid, ticket.ServerPort, ticket.RconPort, ticket.MemoryAllocation.InMegabytes);
|
Logger.Debug("Reserved ticket {TicketGuid} (server port {ServerPort}, additional ports [{AdditionalPorts}], memory allocation {MemoryAllocation} MB).", ticket.TicketGuid, ticket.ServerPort, string.Join(", ", ticket.AdditionalPorts), ticket.MemoryAllocation.InMegabytes);
|
||||||
|
|
||||||
return ticket;
|
return ticket;
|
||||||
}
|
}
|
||||||
@@ -76,10 +75,10 @@ sealed class InstanceTicketManager(AgentInfo agentInfo, ControllerConnection con
|
|||||||
|
|
||||||
usedMemory -= ticket.MemoryAllocation;
|
usedMemory -= ticket.MemoryAllocation;
|
||||||
usedPorts.Remove(ticket.ServerPort);
|
usedPorts.Remove(ticket.ServerPort);
|
||||||
usedPorts.Remove(ticket.RconPort);
|
usedPorts.ExceptWith(ticket.AdditionalPorts);
|
||||||
|
|
||||||
RefreshAgentStatus();
|
RefreshAgentStatus();
|
||||||
Logger.Debug("Released ticket {TicketGuid} (server port {ServerPort}, rcon port {RconPort}, memory allocation {MemoryAllocation} MB).", ticket.TicketGuid, ticket.ServerPort, ticket.RconPort, ticket.MemoryAllocation.InMegabytes);
|
Logger.Debug("Released ticket {TicketGuid} (server port {ServerPort}, additional ports [{AdditionalPorts}], memory allocation {MemoryAllocation} MB).", ticket.TicketGuid, ticket.ServerPort, string.Join(", ", ticket.AdditionalPorts), ticket.MemoryAllocation.InMegabytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,5 +92,5 @@ sealed class InstanceTicketManager(AgentInfo agentInfo, ControllerConnection con
|
|||||||
await reportStatusQueue.Shutdown(TimeSpan.FromSeconds(5));
|
await reportStatusQueue.Shutdown(TimeSpan.FromSeconds(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed record Ticket(Guid TicketGuid, RamAllocationUnits MemoryAllocation, ushort ServerPort, ushort RconPort);
|
public sealed record Ticket(Guid TicketGuid, RamAllocationUnits MemoryAllocation, ushort ServerPort, ImmutableSortedSet<ushort> AdditionalPorts);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
using Phantom.Agent.Services.Instances.State;
|
||||||
|
using Phantom.Common.Data;
|
||||||
|
using Phantom.Common.Data.Agent.Instance;
|
||||||
|
using Phantom.Common.Data.Instance;
|
||||||
|
|
||||||
|
namespace Phantom.Agent.Services.Instances.Launch;
|
||||||
|
|
||||||
|
static class InstanceLaunchProcedure {
|
||||||
|
public static async Task<InstanceRunningState?> Run(InstanceContext context, InstanceInfo info, InstanceLauncher launcher, InstanceTicketManager ticketManager, InstanceTicketManager.Ticket ticket, Action<IInstanceStatus?> reportStatus, CancellationToken cancellationToken) {
|
||||||
|
context.Logger.Information("Session starting...");
|
||||||
|
|
||||||
|
Result<InstanceProcess, InstanceLaunchFailReason> result;
|
||||||
|
|
||||||
|
if (ticketManager.IsValid(ticket)) {
|
||||||
|
try {
|
||||||
|
result = await LaunchInstance(context, launcher, reportStatus, cancellationToken);
|
||||||
|
} catch (OperationCanceledException) {
|
||||||
|
reportStatus(InstanceStatus.NotRunning);
|
||||||
|
return null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
context.Logger.Error(e, "Caught exception while launching instance.");
|
||||||
|
result = InstanceLaunchFailReason.UnknownError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
context.Logger.Error("Attempted to launch instance with an invalid ticket!");
|
||||||
|
result = InstanceLaunchFailReason.UnknownError;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
reportStatus(InstanceStatus.Running);
|
||||||
|
context.ReportEvent(InstanceEvent.LaunchSucceeded);
|
||||||
|
return new InstanceRunningState(context, info, launcher, ticket, result.Value, cancellationToken);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reportStatus(InstanceStatus.Failed(result.Error));
|
||||||
|
context.ReportEvent(new InstanceLaunchFailedEvent(result.Error));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task<Result<InstanceProcess, InstanceLaunchFailReason>> LaunchInstance(InstanceContext context, InstanceLauncher launcher, Action<IInstanceStatus?> reportStatus, CancellationToken cancellationToken) {
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
switch (await launcher.Launch(context.Logger, reportStatus, cancellationToken)) {
|
||||||
|
case InstanceLaunchResult.Success launchSuccess:
|
||||||
|
return launchSuccess.Process;
|
||||||
|
|
||||||
|
case InstanceLaunchResult.CouldNotPrepareServerInstance:
|
||||||
|
context.Logger.Error("Session failed to launch, could not prepare server instance.");
|
||||||
|
return InstanceLaunchFailReason.CouldNotPrepareServerInstance;
|
||||||
|
|
||||||
|
case InstanceLaunchResult.CouldNotFindServerExecutable:
|
||||||
|
context.Logger.Error("Session failed to launch, could not find server executable.");
|
||||||
|
return InstanceLaunchFailReason.CouldNotFindServerExecutable;
|
||||||
|
|
||||||
|
case InstanceLaunchResult.CouldNotStartServerExecutable:
|
||||||
|
context.Logger.Error("Session failed to launch, could not start server executable.");
|
||||||
|
return InstanceLaunchFailReason.CouldNotStartServerExecutable;
|
||||||
|
|
||||||
|
default:
|
||||||
|
context.Logger.Error("Session failed to launch.");
|
||||||
|
return InstanceLaunchFailReason.UnknownError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using Phantom.Agent.Services.Instances.State;
|
||||||
|
|
||||||
|
namespace Phantom.Agent.Services.Instances.Launch;
|
||||||
|
|
||||||
|
abstract record InstanceLaunchResult {
|
||||||
|
private InstanceLaunchResult() {}
|
||||||
|
|
||||||
|
public sealed record Success(InstanceProcess Process) : InstanceLaunchResult;
|
||||||
|
|
||||||
|
public sealed record CouldNotPrepareServerInstance : InstanceLaunchResult;
|
||||||
|
|
||||||
|
public sealed record CouldNotFindServerExecutable : InstanceLaunchResult;
|
||||||
|
|
||||||
|
public sealed record CouldNotStartServerExecutable : InstanceLaunchResult;
|
||||||
|
}
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
using System.Collections.Immutable;
|
||||||
|
using Phantom.Agent.Services.Downloads;
|
||||||
|
using Phantom.Agent.Services.Instances.State;
|
||||||
|
using Phantom.Agent.Services.Java;
|
||||||
|
using Phantom.Common.Data.Agent;
|
||||||
|
using Phantom.Common.Data.Agent.Instance;
|
||||||
|
using Phantom.Common.Data.Agent.Instance.Launch;
|
||||||
|
using Phantom.Common.Data.Instance;
|
||||||
|
using Phantom.Utils.Processes;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
|
namespace Phantom.Agent.Services.Instances.Launch;
|
||||||
|
|
||||||
|
sealed class InstanceLauncher(
|
||||||
|
FileDownloadManager downloadManager,
|
||||||
|
IInstancePathResolver pathResolver,
|
||||||
|
IInstanceValueResolver valueResolver,
|
||||||
|
InstanceProperties instanceProperties,
|
||||||
|
InstanceLaunchRecipe launchRecipe
|
||||||
|
) {
|
||||||
|
public IInstanceValueResolver ValueResolver => valueResolver;
|
||||||
|
|
||||||
|
public async Task<InstanceLaunchResult> Launch(ILogger logger, Action<IInstanceStatus?> reportStatus, CancellationToken cancellationToken) {
|
||||||
|
string? executablePath = launchRecipe.Executable.Resolve(pathResolver);
|
||||||
|
if (executablePath == null) {
|
||||||
|
logger.Error("Could not resolve server executable path: {Path}", launchRecipe.Executable);
|
||||||
|
return new InstanceLaunchResult.CouldNotFindServerExecutable();
|
||||||
|
}
|
||||||
|
|
||||||
|
var stepExecutor = new StepExecutor(logger, downloadManager, pathResolver, reportStatus, cancellationToken);
|
||||||
|
if (!await RunPreparationSteps(logger, stepExecutor)) {
|
||||||
|
return new InstanceLaunchResult.CouldNotPrepareServerInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
var processConfigurator = new ProcessConfigurator {
|
||||||
|
FileName = executablePath,
|
||||||
|
WorkingDirectory = instanceProperties.InstanceFolder,
|
||||||
|
RedirectInput = true,
|
||||||
|
UseShellExecute = false,
|
||||||
|
};
|
||||||
|
|
||||||
|
var processArguments = processConfigurator.ArgumentList;
|
||||||
|
|
||||||
|
foreach (IInstanceValue value in launchRecipe.Arguments) {
|
||||||
|
if (value.Resolve(valueResolver) is {} resolved) {
|
||||||
|
processArguments.Add(resolved);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logger.Error("Could not resolve server executable argument: {Value}", value);
|
||||||
|
return new InstanceLaunchResult.CouldNotPrepareServerInstance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var process = processConfigurator.CreateProcess();
|
||||||
|
var instanceProcess = new InstanceProcess(instanceProperties, process);
|
||||||
|
|
||||||
|
try {
|
||||||
|
process.Start();
|
||||||
|
} catch (Exception launchException) {
|
||||||
|
logger.Error(launchException, "Caught exception launching the server process.");
|
||||||
|
|
||||||
|
try {
|
||||||
|
process.Kill();
|
||||||
|
} catch (Exception killException) {
|
||||||
|
logger.Error(killException, "Caught exception trying to kill the server process after a failed launch.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new InstanceLaunchResult.CouldNotStartServerExecutable();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new InstanceLaunchResult.Success(instanceProcess);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<bool> RunPreparationSteps(ILogger logger, StepExecutor stepExecutor) {
|
||||||
|
var steps = launchRecipe.Preparation;
|
||||||
|
|
||||||
|
for (int stepIndex = 0; stepIndex < steps.Length; stepIndex++) {
|
||||||
|
var step = steps[stepIndex];
|
||||||
|
try {
|
||||||
|
if (await step.Run(stepExecutor)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} catch (OperationCanceledException) {
|
||||||
|
throw;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.Error(e, "Failed preparation step {StepIndex} out of {StepCount}: {StepName}", stepIndex, steps.Length, step.GetType().Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class StepExecutor(ILogger logger, FileDownloadManager downloadManager, IInstancePathResolver pathResolver, Action<IInstanceStatus?> reportStatus, CancellationToken cancellationToken) : IInstanceLaunchStepExecutor<bool> {
|
||||||
|
public async Task<bool> DownloadFile(FileDownloadInfo downloadInfo, IInstancePath path) {
|
||||||
|
string? filePath = path.Resolve(pathResolver);
|
||||||
|
if (filePath == null) {
|
||||||
|
logger.Error("Could not resolve download file path: {Path}", path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte? lastDownloadProgress = null;
|
||||||
|
|
||||||
|
void OnDownloadProgress(object? sender, DownloadProgressEventArgs args) {
|
||||||
|
byte? progress = args.TotalBytes is not {} totalBytes ? null : (byte) Math.Min(args.DownloadedBytes * 100 / totalBytes, val2: 100);
|
||||||
|
|
||||||
|
if (lastDownloadProgress != progress) {
|
||||||
|
lastDownloadProgress = progress;
|
||||||
|
reportStatus(InstanceStatus.Downloading(progress));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reportStatus(InstanceStatus.Downloading(null));
|
||||||
|
|
||||||
|
if (await downloadManager.DownloadAndGetPath(downloadInfo, filePath, OnDownloadProgress, cancellationToken) == null) {
|
||||||
|
logger.Error("Could not download file: {Url}", downloadInfo.Url);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
reportStatus(null);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> EditPropertiesFile(InstancePath.Local path, string comment, ImmutableDictionary<string, string> newValues) {
|
||||||
|
string? filePath = path.Resolve(pathResolver);
|
||||||
|
if (filePath == null) {
|
||||||
|
logger.Error("Could not resolve properties file path: {Path}", path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var editor = new JavaPropertiesFileEditor();
|
||||||
|
editor.SetAll(newValues);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await editor.EditOrCreate(filePath, comment, cancellationToken);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.Error(e, "Could not edit properties file: {Path}", filePath);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using System.Buffers;
|
||||||
|
using System.Collections.Immutable;
|
||||||
|
using Phantom.Agent.Services.Java;
|
||||||
|
using Phantom.Common.Data.Agent.Instance;
|
||||||
|
|
||||||
|
namespace Phantom.Agent.Services.Instances.Launch;
|
||||||
|
|
||||||
|
sealed class InstancePathResolver(AgentFolders agentFolders, JavaRuntimeRepository javaRuntimeRepository, InstanceProperties instanceProperties) : IInstancePathResolver {
|
||||||
|
public string? Global(ImmutableArray<string> segments) {
|
||||||
|
return ValidateAndCombinePath(agentFolders.ServerExecutableFolderPath, segments);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? Local(ImmutableArray<string> segments) {
|
||||||
|
return ValidateAndCombinePath(instanceProperties.InstanceFolder, segments);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? Runtime(Guid guid) {
|
||||||
|
return javaRuntimeRepository.TryGetByGuid(guid, out var runtime) ? runtime.ExecutablePath : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly SearchValues<char> InvalidPathPartChars = SearchValues.Create([
|
||||||
|
Path.DirectorySeparatorChar,
|
||||||
|
Path.AltDirectorySeparatorChar,
|
||||||
|
..Path.GetInvalidPathChars(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
private string? ValidateAndCombinePath(string basePath, ImmutableArray<string> pathSegments) {
|
||||||
|
string path = basePath;
|
||||||
|
|
||||||
|
foreach (string segment in pathSegments) {
|
||||||
|
if (segment == "." || segment == ".." || segment.ContainsAny(InvalidPathPartChars) || Path.IsPathRooted(segment)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
path = Path.Combine(path, segment);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Path.GetFullPath(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using Phantom.Common.Data.Agent.Instance;
|
||||||
|
|
||||||
|
namespace Phantom.Agent.Services.Instances.Launch;
|
||||||
|
|
||||||
|
sealed class InstanceValueResolver(IInstancePathResolver pathResolver) : IInstanceValueResolver {
|
||||||
|
public string? Path(IInstancePath value) {
|
||||||
|
return value.Resolve(pathResolver);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
using Phantom.Agent.Minecraft.Instance;
|
|
||||||
using Phantom.Agent.Minecraft.Launcher;
|
|
||||||
using Phantom.Agent.Minecraft.Server;
|
|
||||||
using Phantom.Common.Data;
|
|
||||||
using Phantom.Common.Data.Instance;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Services.Instances.State;
|
|
||||||
|
|
||||||
static class InstanceLaunchProcedure {
|
|
||||||
public static async Task<InstanceRunningState?> Run(InstanceContext context, InstanceConfiguration configuration, IServerLauncher launcher, InstanceTicketManager ticketManager, InstanceTicketManager.Ticket ticket, Action<IInstanceStatus> reportStatus, CancellationToken cancellationToken) {
|
|
||||||
context.Logger.Information("Session starting...");
|
|
||||||
|
|
||||||
Result<InstanceProcess, InstanceLaunchFailReason> result;
|
|
||||||
|
|
||||||
if (ticketManager.IsValid(ticket)) {
|
|
||||||
try {
|
|
||||||
result = await LaunchInstance(context, launcher, reportStatus, cancellationToken);
|
|
||||||
} catch (OperationCanceledException) {
|
|
||||||
reportStatus(InstanceStatus.NotRunning);
|
|
||||||
return null;
|
|
||||||
} catch (Exception e) {
|
|
||||||
context.Logger.Error(e, "Caught exception while launching instance.");
|
|
||||||
result = InstanceLaunchFailReason.UnknownError;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
context.Logger.Error("Attempted to launch instance with an invalid ticket!");
|
|
||||||
result = InstanceLaunchFailReason.UnknownError;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result) {
|
|
||||||
reportStatus(InstanceStatus.Running);
|
|
||||||
context.ReportEvent(InstanceEvent.LaunchSucceeded);
|
|
||||||
return new InstanceRunningState(context, configuration, launcher, ticket, result.Value, cancellationToken);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
reportStatus(InstanceStatus.Failed(result.Error));
|
|
||||||
context.ReportEvent(new InstanceLaunchFailedEvent(result.Error));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task<Result<InstanceProcess, InstanceLaunchFailReason>> LaunchInstance(InstanceContext context, IServerLauncher launcher, Action<IInstanceStatus> reportStatus, CancellationToken cancellationToken) {
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
|
|
||||||
byte lastDownloadProgress = byte.MaxValue;
|
|
||||||
|
|
||||||
void OnDownloadProgress(object? sender, DownloadProgressEventArgs args) {
|
|
||||||
byte progress = (byte) Math.Min(args.DownloadedBytes * 100 / args.TotalBytes, val2: 100);
|
|
||||||
|
|
||||||
if (lastDownloadProgress != progress) {
|
|
||||||
lastDownloadProgress = progress;
|
|
||||||
reportStatus(InstanceStatus.Downloading(progress));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (await launcher.Launch(context.Logger, context.Services.LaunchServices, OnDownloadProgress, cancellationToken)) {
|
|
||||||
case LaunchResult.Success launchSuccess:
|
|
||||||
return launchSuccess.Process;
|
|
||||||
|
|
||||||
case LaunchResult.InvalidJavaRuntime:
|
|
||||||
context.Logger.Error("Session failed to launch, invalid Java runtime.");
|
|
||||||
return InstanceLaunchFailReason.JavaRuntimeNotFound;
|
|
||||||
|
|
||||||
case LaunchResult.CouldNotDownloadMinecraftServer:
|
|
||||||
context.Logger.Error("Session failed to launch, could not download Minecraft server.");
|
|
||||||
return InstanceLaunchFailReason.CouldNotDownloadMinecraftServer;
|
|
||||||
|
|
||||||
case LaunchResult.CouldNotPrepareMinecraftServerLauncher:
|
|
||||||
context.Logger.Error("Session failed to launch, could not prepare Minecraft server launcher.");
|
|
||||||
return InstanceLaunchFailReason.CouldNotPrepareMinecraftServerLauncher;
|
|
||||||
|
|
||||||
case LaunchResult.CouldNotConfigureMinecraftServer:
|
|
||||||
context.Logger.Error("Session failed to launch, could not configure Minecraft server.");
|
|
||||||
return InstanceLaunchFailReason.CouldNotConfigureMinecraftServer;
|
|
||||||
|
|
||||||
case LaunchResult.CouldNotStartMinecraftServer:
|
|
||||||
context.Logger.Error("Session failed to launch, could not start Minecraft server.");
|
|
||||||
return InstanceLaunchFailReason.CouldNotStartMinecraftServer;
|
|
||||||
|
|
||||||
default:
|
|
||||||
context.Logger.Error("Session failed to launch.");
|
|
||||||
return InstanceLaunchFailReason.UnknownError;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using Phantom.Agent.Minecraft.Instance;
|
using Phantom.Agent.Services.Games;
|
||||||
using Phantom.Agent.Minecraft.Server;
|
|
||||||
using Phantom.Agent.Services.Rpc;
|
using Phantom.Agent.Services.Rpc;
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
using Phantom.Common.Messages.Agent.ToController;
|
using Phantom.Common.Messages.Agent.ToController;
|
||||||
@@ -60,8 +59,8 @@ sealed class InstancePlayerCountTracker : CancellableBackgroundTask {
|
|||||||
|
|
||||||
private async Task<InstancePlayerCounts?> TryGetPlayerCounts() {
|
private async Task<InstancePlayerCounts?> TryGetPlayerCounts() {
|
||||||
try {
|
try {
|
||||||
return await ServerStatusProtocol.GetPlayerCounts(serverPort, CancellationToken);
|
return await MinecraftServerStatusProtocol.GetPlayerCounts(serverPort, CancellationToken);
|
||||||
} catch (ServerStatusProtocol.ProtocolException e) {
|
} catch (MinecraftServerStatusProtocol.ProtocolException e) {
|
||||||
Logger.Error("{Message}", e.Message);
|
Logger.Error("{Message}", e.Message);
|
||||||
return null;
|
return null;
|
||||||
} catch (SocketException e) {
|
} catch (SocketException e) {
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
using Phantom.Utils.Processes;
|
using Phantom.Utils.Processes;
|
||||||
using Phantom.Utils.Tasks;
|
using Phantom.Utils.Tasks;
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Instance;
|
namespace Phantom.Agent.Services.Instances.State;
|
||||||
|
|
||||||
public sealed class InstanceProcess : IDisposable {
|
sealed class InstanceProcess : IDisposable {
|
||||||
public InstanceProperties InstanceProperties { get; }
|
public InstanceProperties InstanceProperties { get; }
|
||||||
|
|
||||||
private readonly RingBuffer<string> outputBuffer = new (100);
|
private readonly RingBuffer<string> outputBuffer = new (100);
|
||||||
@@ -27,6 +27,15 @@ public sealed class InstanceProcess : IDisposable {
|
|||||||
await process.StandardInput.WriteLineAsync(command.AsMemory(), cancellationToken);
|
await process.StandardInput.WriteLineAsync(command.AsMemory(), cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> TrySendCommand(string command, TimeSpan timeout, CancellationToken cancellationToken) {
|
||||||
|
try {
|
||||||
|
await SendCommand(command, cancellationToken).WaitAsync(timeout, cancellationToken);
|
||||||
|
return true;
|
||||||
|
} catch (TimeoutException) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void AddOutputListener(EventHandler<string> listener, uint maxLinesToReadFromHistory = uint.MaxValue) {
|
public void AddOutputListener(EventHandler<string> listener, uint maxLinesToReadFromHistory = uint.MaxValue) {
|
||||||
OutputEvent += listener;
|
OutputEvent += listener;
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using Phantom.Agent.Minecraft.Instance;
|
using Phantom.Agent.Services.Backups;
|
||||||
using Phantom.Agent.Minecraft.Launcher;
|
using Phantom.Agent.Services.Instances.Launch;
|
||||||
using Phantom.Agent.Services.Backups;
|
using Phantom.Common.Data.Agent.Instance;
|
||||||
using Phantom.Common.Data.Backups;
|
using Phantom.Common.Data.Backups;
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
@@ -11,11 +11,12 @@ sealed class InstanceRunningState : IDisposable {
|
|||||||
public InstanceTicketManager.Ticket Ticket { get; }
|
public InstanceTicketManager.Ticket Ticket { get; }
|
||||||
public InstanceProcess Process { get; }
|
public InstanceProcess Process { get; }
|
||||||
|
|
||||||
|
internal IInstanceValueResolver ValueResolver => launcher.ValueResolver;
|
||||||
internal bool IsStopping { get; set; }
|
internal bool IsStopping { get; set; }
|
||||||
|
|
||||||
private readonly InstanceContext context;
|
private readonly InstanceContext context;
|
||||||
private readonly InstanceConfiguration configuration;
|
private readonly InstanceInfo info;
|
||||||
private readonly IServerLauncher launcher;
|
private readonly InstanceLauncher launcher;
|
||||||
private readonly CancellationToken cancellationToken;
|
private readonly CancellationToken cancellationToken;
|
||||||
|
|
||||||
private readonly InstanceLogSender logSender;
|
private readonly InstanceLogSender logSender;
|
||||||
@@ -24,16 +25,16 @@ sealed class InstanceRunningState : IDisposable {
|
|||||||
|
|
||||||
private bool isDisposed;
|
private bool isDisposed;
|
||||||
|
|
||||||
public InstanceRunningState(InstanceContext context, InstanceConfiguration configuration, IServerLauncher launcher, InstanceTicketManager.Ticket ticket, InstanceProcess process, CancellationToken cancellationToken) {
|
public InstanceRunningState(InstanceContext context, InstanceInfo info, InstanceLauncher launcher, InstanceTicketManager.Ticket ticket, InstanceProcess process, CancellationToken cancellationToken) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.configuration = configuration;
|
this.info = info;
|
||||||
this.launcher = launcher;
|
this.launcher = launcher;
|
||||||
this.Ticket = ticket;
|
this.Ticket = ticket;
|
||||||
this.Process = process;
|
this.Process = process;
|
||||||
this.cancellationToken = cancellationToken;
|
this.cancellationToken = cancellationToken;
|
||||||
|
|
||||||
this.logSender = new InstanceLogSender(context.Services.ControllerConnection, context.InstanceGuid, context.ShortName);
|
this.logSender = new InstanceLogSender(context.Services.ControllerConnection, context.InstanceGuid, context.ShortName);
|
||||||
this.playerCountTracker = new InstancePlayerCountTracker(context, process, configuration.ServerPort);
|
this.playerCountTracker = new InstancePlayerCountTracker(context, process, info.ServerPort);
|
||||||
|
|
||||||
this.backupScheduler = new BackupScheduler(context, playerCountTracker);
|
this.backupScheduler = new BackupScheduler(context, playerCountTracker);
|
||||||
this.backupScheduler.BackupCompleted += OnScheduledBackupCompleted;
|
this.backupScheduler.BackupCompleted += OnScheduledBackupCompleted;
|
||||||
@@ -74,7 +75,7 @@ sealed class InstanceRunningState : IDisposable {
|
|||||||
else {
|
else {
|
||||||
context.Logger.Information("Session ended unexpectedly, restarting...");
|
context.Logger.Information("Session ended unexpectedly, restarting...");
|
||||||
context.ReportEvent(InstanceEvent.Crashed);
|
context.ReportEvent(InstanceEvent.Crashed);
|
||||||
context.Actor.Tell(new InstanceActor.LaunchInstanceCommand(configuration, launcher, Ticket, IsRestarting: true));
|
context.Actor.Tell(new InstanceActor.LaunchInstanceCommand(info, launcher, Ticket, IsRestarting: true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,38 +1,50 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Phantom.Agent.Minecraft.Command;
|
using Phantom.Common.Data.Agent.Instance;
|
||||||
using Phantom.Agent.Minecraft.Instance;
|
using Phantom.Common.Data.Agent.Instance.Stop;
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
using Phantom.Common.Data.Minecraft;
|
using Serilog;
|
||||||
|
|
||||||
namespace Phantom.Agent.Services.Instances.State;
|
namespace Phantom.Agent.Services.Instances.State;
|
||||||
|
|
||||||
static class InstanceStopProcedure {
|
static class InstanceStopProcedure {
|
||||||
private static readonly ushort[] Stops = [60, 30, 10, 5, 4, 3, 2, 1, 0];
|
public static async Task<bool> Run(InstanceContext context, InstanceStopRecipe stopRecipe, InstanceRunningState runningState, Action<IInstanceStatus> reportStatus, CancellationToken cancellationToken) {
|
||||||
|
var logger = context.Logger;
|
||||||
public static async Task<bool> Run(InstanceContext context, MinecraftStopStrategy stopStrategy, InstanceRunningState runningState, Action<IInstanceStatus> reportStatus, CancellationToken cancellationToken) {
|
|
||||||
var process = runningState.Process;
|
var stopCommand = stopRecipe.StopCommand.Resolve(runningState.ValueResolver);
|
||||||
|
if (stopCommand == null) {
|
||||||
|
logger.Error("Could not resolve stop command");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
runningState.IsStopping = true;
|
runningState.IsStopping = true;
|
||||||
|
|
||||||
var seconds = stopStrategy.Seconds;
|
bool continueStopping = false;
|
||||||
if (seconds > 0) {
|
try {
|
||||||
try {
|
var stepExecutor = new StepExecutor(logger, runningState.ValueResolver, runningState.Process, cancellationToken);
|
||||||
await CountDownWithAnnouncements(context, process, seconds, cancellationToken);
|
continueStopping = await RunPreparationSteps(context, stopRecipe, stepExecutor);
|
||||||
} catch (OperationCanceledException) {
|
} finally {
|
||||||
|
if (!continueStopping) {
|
||||||
runningState.IsStopping = false;
|
runningState.IsStopping = false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!continueStopping) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Too late to cancel the stop procedure now.
|
// Too late to cancel the stop procedure now.
|
||||||
runningState.OnStopInitiated();
|
runningState.OnStopInitiated();
|
||||||
|
|
||||||
if (!process.HasEnded) {
|
if (!runningState.Process.HasEnded) {
|
||||||
context.Logger.Information("Session stopping now.");
|
logger.Information("Sending stop command...");
|
||||||
await DoStop(context, process);
|
await TrySendStopCommand(context, runningState.Process, stopCommand);
|
||||||
|
|
||||||
|
logger.Information("Waiting for session to end...");
|
||||||
|
await WaitForSessionToEnd(context, runningState.Process);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
context.Logger.Information("Session stopped.");
|
logger.Information("Session stopped.");
|
||||||
reportStatus(InstanceStatus.NotRunning);
|
reportStatus(InstanceStatus.NotRunning);
|
||||||
context.ReportEvent(InstanceEvent.Stopped);
|
context.ReportEvent(InstanceEvent.Stopped);
|
||||||
}
|
}
|
||||||
@@ -40,39 +52,51 @@ static class InstanceStopProcedure {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task CountDownWithAnnouncements(InstanceContext context, InstanceProcess process, ushort seconds, CancellationToken cancellationToken) {
|
private static async Task<bool> RunPreparationSteps(InstanceContext context, InstanceStopRecipe stopRecipe, StepExecutor executor) {
|
||||||
context.Logger.Information("Session stopping in {Seconds} seconds.", seconds);
|
var steps = stopRecipe.Preparation;
|
||||||
|
|
||||||
foreach (var stop in Stops) {
|
for (int stepIndex = 0; stepIndex < steps.Length; stepIndex++) {
|
||||||
// TODO change to event-based cancellation
|
var step = steps[stepIndex];
|
||||||
if (process.HasEnded) {
|
try {
|
||||||
return;
|
if (await step.Run(executor)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} catch (OperationCanceledException) {
|
||||||
|
throw;
|
||||||
|
} catch (Exception e) {
|
||||||
|
context.Logger.Error(e, "Failed preparation step {StepIndex} out of {StepCount}: {StepName}", stepIndex, steps.Length, step.GetType().Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seconds > stop) {
|
return false;
|
||||||
await process.SendCommand(GetCountDownAnnouncementCommand(seconds), cancellationToken);
|
}
|
||||||
await Task.Delay(TimeSpan.FromSeconds(seconds - stop), cancellationToken);
|
|
||||||
seconds = stop;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class StepExecutor(ILogger logger, IInstanceValueResolver valueResolver, InstanceProcess process, CancellationToken cancellationToken) : IInstanceStopStepExecutor<bool> {
|
||||||
|
public async Task<bool> Wait(TimeSpan duration) {
|
||||||
|
await Task.Delay(duration, cancellationToken);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> SendToStandardInput(IInstanceValue line) {
|
||||||
|
string? command = line.Resolve(valueResolver);
|
||||||
|
if (command == null) {
|
||||||
|
logger.Error("Could not resolve standard input line: {Value}", line);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the process can't process standard input, wait a bit but don't block or fail the whole stop procedure.
|
||||||
|
await process.TrySendCommand(command, TimeSpan.FromMilliseconds(500), cancellationToken);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetCountDownAnnouncementCommand(ushort seconds) {
|
private static async Task TrySendStopCommand(InstanceContext context, InstanceProcess process, string command) {
|
||||||
return MinecraftCommand.Say("Server shutting down in " + seconds + (seconds == 1 ? " second." : " seconds."));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task DoStop(InstanceContext context, InstanceProcess process) {
|
|
||||||
context.Logger.Information("Sending stop command...");
|
|
||||||
await TrySendStopCommand(context, process);
|
|
||||||
|
|
||||||
context.Logger.Information("Waiting for session to end...");
|
|
||||||
await WaitForSessionToEnd(context, process);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task TrySendStopCommand(InstanceContext context, InstanceProcess process) {
|
|
||||||
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
||||||
try {
|
try {
|
||||||
await process.SendCommand(MinecraftCommand.Stop, timeout.Token);
|
await process.SendCommand(command, timeout.Token);
|
||||||
} catch (OperationCanceledException) {
|
} catch (OperationCanceledException) {
|
||||||
// Ignore.
|
// Ignore.
|
||||||
} catch (ObjectDisposedException e) when (e.ObjectName == typeof(Process).FullName && process.HasEnded) {
|
} catch (ObjectDisposedException e) when (e.ObjectName == typeof(Process).FullName && process.HasEnded) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Phantom.Agent.Minecraft.Java;
|
namespace Phantom.Agent.Services.Java;
|
||||||
|
|
||||||
sealed class JavaPropertiesFileEditor {
|
sealed class JavaPropertiesFileEditor {
|
||||||
private readonly Dictionary<string, string> overriddenProperties = new ();
|
private readonly Dictionary<string, string> overriddenProperties = new ();
|
||||||
@@ -7,6 +7,12 @@ sealed class JavaPropertiesFileEditor {
|
|||||||
overriddenProperties[key] = value;
|
overriddenProperties[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetAll(IDictionary<string, string> values) {
|
||||||
|
foreach ((string key, string value) in values) {
|
||||||
|
Set(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task EditOrCreate(string filePath, string comment, CancellationToken cancellationToken) {
|
public async Task EditOrCreate(string filePath, string comment, CancellationToken cancellationToken) {
|
||||||
if (File.Exists(filePath)) {
|
if (File.Exists(filePath)) {
|
||||||
string tmpFilePath = filePath + ".tmp";
|
string tmpFilePath = filePath + ".tmp";
|
||||||
@@ -4,7 +4,7 @@ using System.Runtime.CompilerServices;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Phantom.Utils.Collections;
|
using Phantom.Utils.Collections;
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Java;
|
namespace Phantom.Agent.Services.Java;
|
||||||
|
|
||||||
static class JavaPropertiesStream {
|
static class JavaPropertiesStream {
|
||||||
internal static readonly Encoding Encoding = Encoding.GetEncoding("ISO-8859-1");
|
internal static readonly Encoding Encoding = Encoding.GetEncoding("ISO-8859-1");
|
||||||
@@ -30,7 +30,7 @@ static class JavaPropertiesStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Reader(string path) {
|
public Reader(string path) {
|
||||||
this.reader = new StreamReader(path, Encoding, detectEncodingFromByteOrderMarks: false, CreateFileStreamOptions(FileMode.Open, FileAccess.Read));
|
this.reader = new StreamReader(path, Encoding, detectEncodingFromByteOrderMarks: true, CreateFileStreamOptions(FileMode.Open, FileAccess.Read));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async IAsyncEnumerable<KeyValuePair<string, string>> ReadProperties([EnumeratorCancellation] CancellationToken cancellationToken) {
|
public async IAsyncEnumerable<KeyValuePair<string, string>> ReadProperties([EnumeratorCancellation] CancellationToken cancellationToken) {
|
||||||
@@ -6,7 +6,7 @@ using Phantom.Utils.IO;
|
|||||||
using Phantom.Utils.Logging;
|
using Phantom.Utils.Logging;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Java;
|
namespace Phantom.Agent.Services.Java;
|
||||||
|
|
||||||
public sealed class JavaRuntimeDiscovery {
|
public sealed class JavaRuntimeDiscovery {
|
||||||
private static readonly ILogger Logger = PhantomLogger.Create(nameof(JavaRuntimeDiscovery));
|
private static readonly ILogger Logger = PhantomLogger.Create(nameof(JavaRuntimeDiscovery));
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
using Phantom.Common.Data.Java;
|
using Phantom.Common.Data.Java;
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Java;
|
namespace Phantom.Agent.Services.Java;
|
||||||
|
|
||||||
sealed record JavaRuntimeExecutable(string ExecutablePath, JavaRuntime Runtime);
|
sealed record JavaRuntimeExecutable(string ExecutablePath, JavaRuntime Runtime);
|
||||||
@@ -3,7 +3,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using Phantom.Common.Data.Java;
|
using Phantom.Common.Data.Java;
|
||||||
using Phantom.Utils.Cryptography;
|
using Phantom.Utils.Cryptography;
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Java;
|
namespace Phantom.Agent.Services.Java;
|
||||||
|
|
||||||
public sealed class JavaRuntimeRepository {
|
public sealed class JavaRuntimeRepository {
|
||||||
private readonly ImmutableDictionary<Guid, JavaRuntimeExecutable> runtimesByGuid;
|
private readonly ImmutableDictionary<Guid, JavaRuntimeExecutable> runtimesByGuid;
|
||||||
@@ -5,9 +5,12 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<InternalsVisibleTo Include="Phantom.Agent.Services.Tests" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Common\Phantom.Common.Messages.Agent\Phantom.Common.Messages.Agent.csproj" />
|
<ProjectReference Include="..\..\Common\Phantom.Common.Messages.Agent\Phantom.Common.Messages.Agent.csproj" />
|
||||||
<ProjectReference Include="..\Phantom.Agent.Minecraft\Phantom.Agent.Minecraft.csproj" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public sealed class ControllerMessageHandlerActor : ReceiveActor<IMessageToAgent
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Result<ConfigureInstanceResult, InstanceActionFailure>> HandleConfigureInstance(ConfigureInstanceMessage message) {
|
private async Task<Result<ConfigureInstanceResult, InstanceActionFailure>> HandleConfigureInstance(ConfigureInstanceMessage message) {
|
||||||
return await agent.InstanceManager.Request(new InstanceManagerActor.ConfigureInstanceCommand(message.InstanceGuid, message.Configuration, message.LaunchProperties, message.LaunchNow, AlwaysReportStatus: false));
|
return await agent.InstanceManager.Request(new InstanceManagerActor.ConfigureInstanceCommand(message.InstanceGuid, message.Info, message.LaunchRecipe, message.LaunchNow, message.StopRecipe, AlwaysReportStatus: false));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Result<LaunchInstanceResult, InstanceActionFailure>> HandleLaunchInstance(LaunchInstanceMessage message) {
|
private async Task<Result<LaunchInstanceResult, InstanceActionFailure>> HandleLaunchInstance(LaunchInstanceMessage message) {
|
||||||
@@ -34,7 +34,7 @@ public sealed class ControllerMessageHandlerActor : ReceiveActor<IMessageToAgent
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Result<StopInstanceResult, InstanceActionFailure>> HandleStopInstance(StopInstanceMessage message) {
|
private async Task<Result<StopInstanceResult, InstanceActionFailure>> HandleStopInstance(StopInstanceMessage message) {
|
||||||
return await agent.InstanceManager.Request(new InstanceManagerActor.StopInstanceCommand(message.InstanceGuid, message.StopStrategy));
|
return await agent.InstanceManager.Request(new InstanceManagerActor.StopInstanceCommand(message.InstanceGuid, message.StopRecipe));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Result<SendCommandToInstanceResult, InstanceActionFailure>> HandleSendCommandToInstance(SendCommandToInstanceMessage message) {
|
private async Task<Result<SendCommandToInstanceResult, InstanceActionFailure>> HandleSendCommandToInstance(SendCommandToInstanceMessage message) {
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Utils\Phantom.Utils\Phantom.Utils.csproj" />
|
<ProjectReference Include="..\..\Utils\Phantom.Utils\Phantom.Utils.csproj" />
|
||||||
<ProjectReference Include="..\Phantom.Agent.Minecraft\Phantom.Agent.Minecraft.csproj" />
|
|
||||||
<ProjectReference Include="..\Phantom.Agent.Services\Phantom.Agent.Services.csproj" />
|
<ProjectReference Include="..\Phantom.Agent.Services\Phantom.Agent.Services.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Phantom.Agent;
|
using Phantom.Agent;
|
||||||
using Phantom.Agent.Minecraft.Java;
|
|
||||||
using Phantom.Agent.Services;
|
using Phantom.Agent.Services;
|
||||||
|
using Phantom.Agent.Services.Java;
|
||||||
using Phantom.Agent.Services.Rpc;
|
using Phantom.Agent.Services.Rpc;
|
||||||
using Phantom.Common.Data.Agent;
|
using Phantom.Common.Data.Agent;
|
||||||
using Phantom.Common.Messages.Agent;
|
using Phantom.Common.Messages.Agent;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Phantom.Agent.Minecraft.Java;
|
using Phantom.Agent.Services.Java;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
using Phantom.Utils.Logging;
|
using Phantom.Utils.Logging;
|
||||||
using Phantom.Utils.Runtime;
|
using Phantom.Utils.Runtime;
|
||||||
@@ -14,7 +14,7 @@ sealed record Variables(
|
|||||||
ushort MaxInstances,
|
ushort MaxInstances,
|
||||||
RamAllocationUnits MaxMemory,
|
RamAllocationUnits MaxMemory,
|
||||||
AllowedPorts AllowedServerPorts,
|
AllowedPorts AllowedServerPorts,
|
||||||
AllowedPorts AllowedRconPorts,
|
AllowedPorts AllowedAdditionalPorts,
|
||||||
ushort MaxConcurrentBackupCompressionTasks
|
ushort MaxConcurrentBackupCompressionTasks
|
||||||
) {
|
) {
|
||||||
private static Variables LoadOrThrow() {
|
private static Variables LoadOrThrow() {
|
||||||
@@ -30,7 +30,7 @@ sealed record Variables(
|
|||||||
(ushort) EnvironmentVariables.GetInteger("MAX_INSTANCES", min: 1, max: 10000).Require,
|
(ushort) EnvironmentVariables.GetInteger("MAX_INSTANCES", min: 1, max: 10000).Require,
|
||||||
EnvironmentVariables.GetString("MAX_MEMORY").MapParse(RamAllocationUnits.FromString).Require,
|
EnvironmentVariables.GetString("MAX_MEMORY").MapParse(RamAllocationUnits.FromString).Require,
|
||||||
EnvironmentVariables.GetString("ALLOWED_SERVER_PORTS").MapParse(AllowedPorts.FromString).Require,
|
EnvironmentVariables.GetString("ALLOWED_SERVER_PORTS").MapParse(AllowedPorts.FromString).Require,
|
||||||
EnvironmentVariables.GetString("ALLOWED_RCON_PORTS").MapParse(AllowedPorts.FromString).Require,
|
EnvironmentVariables.GetString("ALLOWED_ADDITIONAL_PORTS").MapParse(AllowedPorts.FromString).Require,
|
||||||
(ushort) EnvironmentVariables.GetInteger("MAX_CONCURRENT_BACKUP_COMPRESSION_TASKS", min: 1, max: 10000).WithDefault(1)
|
(ushort) EnvironmentVariables.GetInteger("MAX_CONCURRENT_BACKUP_COMPRESSION_TASKS", min: 1, max: 10000).WithDefault(1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ sealed record Variables(
|
|||||||
try {
|
try {
|
||||||
return LoadOrThrow();
|
return LoadOrThrow();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
PhantomLogger.Root.Fatal("{}", e.Message);
|
PhantomLogger.Root.Fatal("{Error}", e.Message);
|
||||||
throw StopProcedureException.Instance;
|
throw StopProcedureException.Instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ public sealed partial record AgentInfo(
|
|||||||
[property: MemoryPackOrder(2)] ushort MaxInstances,
|
[property: MemoryPackOrder(2)] ushort MaxInstances,
|
||||||
[property: MemoryPackOrder(3)] RamAllocationUnits MaxMemory,
|
[property: MemoryPackOrder(3)] RamAllocationUnits MaxMemory,
|
||||||
[property: MemoryPackOrder(4)] AllowedPorts AllowedServerPorts,
|
[property: MemoryPackOrder(4)] AllowedPorts AllowedServerPorts,
|
||||||
[property: MemoryPackOrder(5)] AllowedPorts AllowedRconPorts
|
[property: MemoryPackOrder(5)] AllowedPorts AllowedAdditionalPorts
|
||||||
);
|
);
|
||||||
25
Common/Phantom.Common.Data.Agent/FileDownloadInfo.cs
Normal file
25
Common/Phantom.Common.Data.Agent/FileDownloadInfo.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using MemoryPack;
|
||||||
|
using Phantom.Utils.Cryptography;
|
||||||
|
|
||||||
|
namespace Phantom.Common.Data.Agent;
|
||||||
|
|
||||||
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
|
public sealed partial class FileDownloadInfo {
|
||||||
|
[MemoryPackOrder(0)]
|
||||||
|
public string Url { get; }
|
||||||
|
|
||||||
|
[MemoryPackOrder(1)]
|
||||||
|
[MemoryPackInclude]
|
||||||
|
private readonly string? hash;
|
||||||
|
|
||||||
|
[MemoryPackIgnore]
|
||||||
|
public Sha1String? Hash => hash == null ? null : Sha1String.FromString(hash);
|
||||||
|
|
||||||
|
public FileDownloadInfo(string url, Sha1String? hash = null) : this(url, hash?.ToString()) {}
|
||||||
|
|
||||||
|
[MemoryPackConstructor]
|
||||||
|
private FileDownloadInfo(string url, string? hash) {
|
||||||
|
this.Url = url;
|
||||||
|
this.hash = hash;
|
||||||
|
}
|
||||||
|
}
|
||||||
53
Common/Phantom.Common.Data.Agent/Instance/IInstancePath.cs
Normal file
53
Common/Phantom.Common.Data.Agent/Instance/IInstancePath.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using System.Collections.Immutable;
|
||||||
|
using MemoryPack;
|
||||||
|
|
||||||
|
namespace Phantom.Common.Data.Agent.Instance;
|
||||||
|
|
||||||
|
[MemoryPackable]
|
||||||
|
[MemoryPackUnion(tag: 0, typeof(InstancePath.Global))]
|
||||||
|
[MemoryPackUnion(tag: 1, typeof(InstancePath.Local))]
|
||||||
|
[MemoryPackUnion(tag: 2, typeof(InstancePath.Runtime))]
|
||||||
|
public partial interface IInstancePath {
|
||||||
|
string? Resolve(IInstancePathResolver resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static partial class InstancePath {
|
||||||
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
|
public sealed partial record Global(
|
||||||
|
[property: MemoryPackOrder(0)] ImmutableArray<string> Segments
|
||||||
|
) : IInstancePath {
|
||||||
|
public string? Resolve(IInstancePathResolver resolver) {
|
||||||
|
return resolver.Global(Segments);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return "Global[" + string.Join(separator: '/', Segments) + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
|
public sealed partial record Local(
|
||||||
|
[property: MemoryPackOrder(0)] ImmutableArray<string> Segments
|
||||||
|
) : IInstancePath {
|
||||||
|
public string? Resolve(IInstancePathResolver resolver) {
|
||||||
|
return resolver.Local(Segments);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return "Local[" + string.Join(separator: '/', Segments) + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
|
public sealed partial record Runtime(
|
||||||
|
[property: MemoryPackOrder(0)] Guid Guid
|
||||||
|
) : IInstancePath {
|
||||||
|
public string? Resolve(IInstancePathResolver resolver) {
|
||||||
|
return resolver.Runtime(Guid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return "Runtime[" + Guid + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Collections.Immutable;
|
||||||
|
|
||||||
|
namespace Phantom.Common.Data.Agent.Instance;
|
||||||
|
|
||||||
|
public interface IInstancePathResolver {
|
||||||
|
string? Global(ImmutableArray<string> segments);
|
||||||
|
string? Local(ImmutableArray<string> segments);
|
||||||
|
string? Runtime(Guid guid);
|
||||||
|
}
|
||||||
59
Common/Phantom.Common.Data.Agent/Instance/IInstanceValue.cs
Normal file
59
Common/Phantom.Common.Data.Agent/Instance/IInstanceValue.cs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
using System.Collections.Immutable;
|
||||||
|
using System.Text;
|
||||||
|
using MemoryPack;
|
||||||
|
|
||||||
|
namespace Phantom.Common.Data.Agent.Instance;
|
||||||
|
|
||||||
|
[MemoryPackable]
|
||||||
|
[MemoryPackUnion(tag: 0, typeof(InstanceValues.Concatenation))]
|
||||||
|
[MemoryPackUnion(tag: 1, typeof(InstanceValues.Text))]
|
||||||
|
[MemoryPackUnion(tag: 2, typeof(InstanceValues.Path))]
|
||||||
|
public partial interface IInstanceValue {
|
||||||
|
string? Resolve(IInstanceValueResolver resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static partial class InstanceValues {
|
||||||
|
[MemoryPackable]
|
||||||
|
public sealed partial record Concatenation(ImmutableArray<IInstanceValue> Values) : IInstanceValue {
|
||||||
|
public string? Resolve(IInstanceValueResolver resolver) {
|
||||||
|
var result = new StringBuilder();
|
||||||
|
|
||||||
|
foreach (IInstanceValue value in Values) {
|
||||||
|
if (value.Resolve(resolver) is {} resolved) {
|
||||||
|
result.Append(resolved);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return "Concatenation[" + string.Join(",", Values) + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemoryPackable]
|
||||||
|
public sealed partial record Text(string Value) : IInstanceValue {
|
||||||
|
public string Resolve(IInstanceValueResolver resolver) {
|
||||||
|
return Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return "Text[" + Value + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemoryPackable]
|
||||||
|
public sealed partial record Path(IInstancePath Value) : IInstanceValue {
|
||||||
|
public string? Resolve(IInstanceValueResolver resolver) {
|
||||||
|
return resolver.Path(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return "Path[" + Value + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
namespace Phantom.Common.Data.Agent.Instance;
|
||||||
|
|
||||||
|
public interface IInstanceValueResolver {
|
||||||
|
string? Path(IInstancePath value);
|
||||||
|
}
|
||||||
12
Common/Phantom.Common.Data.Agent/Instance/InstanceInfo.cs
Normal file
12
Common/Phantom.Common.Data.Agent/Instance/InstanceInfo.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections.Immutable;
|
||||||
|
using MemoryPack;
|
||||||
|
|
||||||
|
namespace Phantom.Common.Data.Agent.Instance;
|
||||||
|
|
||||||
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
|
public sealed partial record InstanceInfo(
|
||||||
|
[property: MemoryPackOrder(0)] string InstanceName,
|
||||||
|
[property: MemoryPackOrder(1)] ushort ServerPort,
|
||||||
|
[property: MemoryPackOrder(2)] ImmutableSortedSet<ushort> AdditionalPorts,
|
||||||
|
[property: MemoryPackOrder(3)] RamAllocationUnits MemoryAllocation
|
||||||
|
);
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using System.Collections.Immutable;
|
||||||
|
using MemoryPack;
|
||||||
|
|
||||||
|
namespace Phantom.Common.Data.Agent.Instance.Launch;
|
||||||
|
|
||||||
|
[MemoryPackable]
|
||||||
|
[MemoryPackUnion(tag: 0, typeof(InstanceLaunchStep.DownloadFile))]
|
||||||
|
[MemoryPackUnion(tag: 1, typeof(InstanceLaunchStep.EditPropertiesFile))]
|
||||||
|
public partial interface IInstanceLaunchStep {
|
||||||
|
Task<TResult> Run<TResult>(IInstanceLaunchStepExecutor<TResult> executor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static partial class InstanceLaunchStep {
|
||||||
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
|
public sealed partial record DownloadFile(
|
||||||
|
[property: MemoryPackOrder(0)] FileDownloadInfo DownloadInfo,
|
||||||
|
[property: MemoryPackOrder(1)] IInstancePath Path
|
||||||
|
) : IInstanceLaunchStep {
|
||||||
|
public Task<TResult> Run<TResult>(IInstanceLaunchStepExecutor<TResult> executor) {
|
||||||
|
return executor.DownloadFile(DownloadInfo, Path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
|
public sealed partial record EditPropertiesFile(
|
||||||
|
[property: MemoryPackOrder(0)] InstancePath.Local Path,
|
||||||
|
[property: MemoryPackOrder(1)] string Comment,
|
||||||
|
[property: MemoryPackOrder(2)] ImmutableDictionary<string, string> NewValues
|
||||||
|
) : IInstanceLaunchStep {
|
||||||
|
public Task<TResult> Run<TResult>(IInstanceLaunchStepExecutor<TResult> executor) {
|
||||||
|
return executor.EditPropertiesFile(Path, Comment, NewValues);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using System.Collections.Immutable;
|
||||||
|
|
||||||
|
namespace Phantom.Common.Data.Agent.Instance.Launch;
|
||||||
|
|
||||||
|
public interface IInstanceLaunchStepExecutor<TResult> {
|
||||||
|
Task<TResult> DownloadFile(FileDownloadInfo downloadInfo, IInstancePath path);
|
||||||
|
Task<TResult> EditPropertiesFile(InstancePath.Local path, string comment, ImmutableDictionary<string, string> newValues);
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.Immutable;
|
||||||
|
using MemoryPack;
|
||||||
|
|
||||||
|
namespace Phantom.Common.Data.Agent.Instance.Launch;
|
||||||
|
|
||||||
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
|
public sealed partial record InstanceLaunchRecipe(
|
||||||
|
[property: MemoryPackOrder(0)] ImmutableArray<IInstanceLaunchStep> Preparation,
|
||||||
|
[property: MemoryPackOrder(1)] IInstancePath Executable,
|
||||||
|
[property: MemoryPackOrder(2)] ImmutableArray<IInstanceValue> Arguments
|
||||||
|
);
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Phantom.Common.Data.Agent.Instance.Stop;
|
||||||
|
|
||||||
|
public interface IInstanceStopStepExecutor<TResult> {
|
||||||
|
Task<TResult> Wait(TimeSpan duration);
|
||||||
|
Task<TResult> SendToStandardInput(IInstanceValue line);
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using MemoryPack;
|
||||||
|
|
||||||
|
namespace Phantom.Common.Data.Agent.Instance.Stop;
|
||||||
|
|
||||||
|
[MemoryPackable]
|
||||||
|
[MemoryPackUnion(tag: 0, typeof(InstanceStopStep.Wait))]
|
||||||
|
[MemoryPackUnion(tag: 1, typeof(InstanceStopStep.SendToStandardInput))]
|
||||||
|
public partial interface IInstanceStopStep {
|
||||||
|
Task<TResult> Run<TResult>(IInstanceStopStepExecutor<TResult> executor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static partial class InstanceStopStep {
|
||||||
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
|
public sealed partial record Wait(
|
||||||
|
[property: MemoryPackOrder(0)] TimeSpan Duration
|
||||||
|
) : IInstanceStopStep {
|
||||||
|
public Task<TResult> Run<TResult>(IInstanceStopStepExecutor<TResult> executor) {
|
||||||
|
return executor.Wait(Duration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
|
public sealed partial record SendToStandardInput(
|
||||||
|
[property: MemoryPackOrder(0)] IInstanceValue Line
|
||||||
|
) : IInstanceStopStep {
|
||||||
|
public Task<TResult> Run<TResult>(IInstanceStopStepExecutor<TResult> executor) {
|
||||||
|
return executor.SendToStandardInput(Line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Collections.Immutable;
|
||||||
|
using MemoryPack;
|
||||||
|
|
||||||
|
namespace Phantom.Common.Data.Agent.Instance.Stop;
|
||||||
|
|
||||||
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
|
public sealed partial record InstanceStopRecipe(
|
||||||
|
[property: MemoryPackOrder(0)] ImmutableArray<IInstanceStopStep> Preparation,
|
||||||
|
[property: MemoryPackOrder(1)] IInstanceValue StopCommand
|
||||||
|
);
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MemoryPack" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Phantom.Common.Data\Phantom.Common.Data.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
using Phantom.Common.Data.Agent;
|
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Web.Agent;
|
namespace Phantom.Common.Data.Web.Agent;
|
||||||
|
|
||||||
@@ -15,30 +14,4 @@ public sealed partial record Agent(
|
|||||||
) {
|
) {
|
||||||
[MemoryPackIgnore]
|
[MemoryPackIgnore]
|
||||||
public RamAllocationUnits? AvailableMemory => RuntimeInfo.MaxMemory - Stats?.RunningInstanceMemory;
|
public RamAllocationUnits? AvailableMemory => RuntimeInfo.MaxMemory - Stats?.RunningInstanceMemory;
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
|
||||||
public sealed partial record Update(
|
|
||||||
[property: MemoryPackOrder(0)] Optional<AgentConfiguration> Configuration,
|
|
||||||
[property: MemoryPackOrder(1)] Optional<ImmutableArray<byte>> ConnectionKey,
|
|
||||||
[property: MemoryPackOrder(2)] Optional<AgentRuntimeInfo> RuntimeInfo,
|
|
||||||
[property: MemoryPackOrder(3)] OptionalNullable<AgentStats> Stats,
|
|
||||||
[property: MemoryPackOrder(4)] Optional<IAgentConnectionStatus> ConnectionStatus
|
|
||||||
) {
|
|
||||||
public Update Merge(Update newer) => new (
|
|
||||||
newer.Configuration.Or(Configuration),
|
|
||||||
newer.ConnectionKey.Or(ConnectionKey),
|
|
||||||
newer.RuntimeInfo.Or(RuntimeInfo),
|
|
||||||
newer.Stats.Or(Stats),
|
|
||||||
newer.ConnectionStatus.Or(ConnectionStatus)
|
|
||||||
);
|
|
||||||
|
|
||||||
public Agent Apply(Agent target) => new (
|
|
||||||
target.AgentGuid,
|
|
||||||
Configuration.Or(target.Configuration),
|
|
||||||
ConnectionKey.Or(target.ConnectionKey),
|
|
||||||
RuntimeInfo.Or(target.RuntimeInfo),
|
|
||||||
Stats.Or(target.Stats),
|
|
||||||
ConnectionStatus.Or(target.ConnectionStatus)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
using Phantom.Common.Data.Agent;
|
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Web.Agent;
|
namespace Phantom.Common.Data.Web.Agent;
|
||||||
|
|
||||||
@@ -9,9 +8,5 @@ public sealed partial record AgentRuntimeInfo(
|
|||||||
[property: MemoryPackOrder(1)] ushort? MaxInstances = null,
|
[property: MemoryPackOrder(1)] ushort? MaxInstances = null,
|
||||||
[property: MemoryPackOrder(2)] RamAllocationUnits? MaxMemory = null,
|
[property: MemoryPackOrder(2)] RamAllocationUnits? MaxMemory = null,
|
||||||
[property: MemoryPackOrder(3)] AllowedPorts? AllowedServerPorts = null,
|
[property: MemoryPackOrder(3)] AllowedPorts? AllowedServerPorts = null,
|
||||||
[property: MemoryPackOrder(4)] AllowedPorts? AllowedRconPorts = null
|
[property: MemoryPackOrder(4)] AllowedPorts? AllowedAdditionalPorts = null
|
||||||
) {
|
);
|
||||||
public static AgentRuntimeInfo From(AgentInfo agentInfo) {
|
|
||||||
return new AgentRuntimeInfo(new AgentVersionInfo(agentInfo.ProtocolVersion, agentInfo.BuildVersion), agentInfo.MaxInstances, agentInfo.MaxMemory, agentInfo.AllowedServerPorts, agentInfo.AllowedRconPorts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Agent;
|
namespace Phantom.Common.Data.Web.Agent;
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial record AgentStats(
|
public sealed partial record AgentStats(
|
||||||
@@ -5,19 +5,19 @@ public enum CreateOrUpdateInstanceResult : byte {
|
|||||||
Success,
|
Success,
|
||||||
InstanceNameMustNotBeEmpty,
|
InstanceNameMustNotBeEmpty,
|
||||||
InstanceMemoryMustNotBeZero,
|
InstanceMemoryMustNotBeZero,
|
||||||
MinecraftVersionDownloadInfoNotFound,
|
MinecraftVersionNotFound,
|
||||||
AgentNotFound,
|
AgentNotFound,
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CreateOrUpdateInstanceResultExtensions {
|
public static class CreateOrUpdateInstanceResultExtensions {
|
||||||
public static string ToSentence(this CreateOrUpdateInstanceResult reason) {
|
public static string ToSentence(this CreateOrUpdateInstanceResult reason) {
|
||||||
return reason switch {
|
return reason switch {
|
||||||
CreateOrUpdateInstanceResult.Success => "Success.",
|
CreateOrUpdateInstanceResult.Success => "Success.",
|
||||||
CreateOrUpdateInstanceResult.InstanceNameMustNotBeEmpty => "Instance name must not be empty.",
|
CreateOrUpdateInstanceResult.InstanceNameMustNotBeEmpty => "Instance name must not be empty.",
|
||||||
CreateOrUpdateInstanceResult.InstanceMemoryMustNotBeZero => "Memory must not be 0 MB.",
|
CreateOrUpdateInstanceResult.InstanceMemoryMustNotBeZero => "Memory must not be 0 MB.",
|
||||||
CreateOrUpdateInstanceResult.MinecraftVersionDownloadInfoNotFound => "Could not find download information for the selected Minecraft version.",
|
CreateOrUpdateInstanceResult.MinecraftVersionNotFound => "Minecraft version not found.",
|
||||||
CreateOrUpdateInstanceResult.AgentNotFound => "Agent not found.",
|
CreateOrUpdateInstanceResult.AgentNotFound => "Agent not found.",
|
||||||
_ => "Unknown error.",
|
_ => "Unknown error.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
using Phantom.Common.Data.Minecraft;
|
using Phantom.Common.Data.Web.Minecraft;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Instance;
|
namespace Phantom.Common.Data.Web.Instance;
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial record InstanceConfiguration(
|
public sealed partial record InstanceConfiguration(
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Web.Minecraft;
|
namespace Phantom.Common.Data.Web.Java;
|
||||||
|
|
||||||
public static class JvmArgumentsHelper {
|
public static class JvmArgumentsHelper {
|
||||||
public static ImmutableArray<string> Split(string arguments) {
|
public static ImmutableArray<string> Split(string arguments) {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Phantom.Common.Data.Minecraft;
|
namespace Phantom.Common.Data.Web.Minecraft;
|
||||||
|
|
||||||
public enum MinecraftServerKind : ushort {
|
public enum MinecraftServerKind : ushort {
|
||||||
Vanilla = 1,
|
Vanilla = 1,
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Minecraft;
|
namespace Phantom.Common.Data.Web.Minecraft;
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial record MinecraftVersion(
|
public sealed partial record MinecraftVersion(
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Minecraft;
|
namespace Phantom.Common.Data.Web.Minecraft;
|
||||||
|
|
||||||
public enum MinecraftVersionType : ushort {
|
public enum MinecraftVersionType : ushort {
|
||||||
Other = 0,
|
Other = 0,
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
namespace Phantom.Common.Data.Web;
|
|
||||||
|
|
||||||
public class RemoteDictionary<K, V> {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -25,7 +25,7 @@ public sealed partial record InstanceIsInvalid([property: MemoryPackOrder(0)] st
|
|||||||
public sealed partial record InstanceIsNotRunning : IInstanceStatus;
|
public sealed partial record InstanceIsNotRunning : IInstanceStatus;
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial record InstanceIsDownloading([property: MemoryPackOrder(0)] byte Progress) : IInstanceStatus;
|
public sealed partial record InstanceIsDownloading([property: MemoryPackOrder(0)] byte? Progress) : IInstanceStatus;
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial record InstanceIsLaunching : IInstanceStatus;
|
public sealed partial record InstanceIsLaunching : IInstanceStatus;
|
||||||
@@ -55,7 +55,7 @@ public static class InstanceStatus {
|
|||||||
public static readonly IInstanceStatus Stopping = new InstanceIsStopping();
|
public static readonly IInstanceStatus Stopping = new InstanceIsStopping();
|
||||||
|
|
||||||
public static IInstanceStatus Invalid(string reason) => new InstanceIsInvalid(reason);
|
public static IInstanceStatus Invalid(string reason) => new InstanceIsInvalid(reason);
|
||||||
public static IInstanceStatus Downloading(byte progress) => new InstanceIsDownloading(progress);
|
public static IInstanceStatus Downloading(byte? progress) => new InstanceIsDownloading(progress);
|
||||||
public static IInstanceStatus Failed(InstanceLaunchFailReason reason) => new InstanceIsFailed(reason);
|
public static IInstanceStatus Failed(InstanceLaunchFailReason reason) => new InstanceIsFailed(reason);
|
||||||
|
|
||||||
public static bool IsLaunching(this IInstanceStatus status) {
|
public static bool IsLaunching(this IInstanceStatus status) {
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
namespace Phantom.Common.Data.Instance;
|
namespace Phantom.Common.Data.Instance;
|
||||||
|
|
||||||
public enum InstanceLaunchFailReason : byte {
|
public enum InstanceLaunchFailReason : byte {
|
||||||
UnknownError = 0,
|
UnknownError = 0,
|
||||||
JavaRuntimeNotFound = 5,
|
CouldNotPrepareServerInstance = 1,
|
||||||
CouldNotDownloadMinecraftServer = 6,
|
CouldNotFindServerExecutable = 2,
|
||||||
CouldNotConfigureMinecraftServer = 7,
|
CouldNotStartServerExecutable = 3,
|
||||||
CouldNotPrepareMinecraftServerLauncher = 8,
|
|
||||||
CouldNotStartMinecraftServer = 9,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
using MemoryPack;
|
|
||||||
using Phantom.Common.Data.Minecraft;
|
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Instance;
|
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
|
||||||
public sealed partial record InstanceLaunchProperties(
|
|
||||||
[property: MemoryPackOrder(0)] FileDownloadInfo? ServerDownloadInfo
|
|
||||||
);
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
using MemoryPack;
|
|
||||||
using Phantom.Utils.Cryptography;
|
|
||||||
using Phantom.Utils.IO;
|
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Minecraft;
|
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
|
||||||
public sealed partial class FileDownloadInfo {
|
|
||||||
[MemoryPackOrder(0)]
|
|
||||||
public string DownloadUrl { get; }
|
|
||||||
|
|
||||||
[MemoryPackOrder(1)]
|
|
||||||
[MemoryPackInclude]
|
|
||||||
private readonly string hash;
|
|
||||||
|
|
||||||
[MemoryPackIgnore]
|
|
||||||
public Sha1String Hash => Sha1String.FromString(hash);
|
|
||||||
|
|
||||||
[MemoryPackOrder(2)]
|
|
||||||
public FileSize Size { get; }
|
|
||||||
|
|
||||||
public FileDownloadInfo(string downloadUrl, Sha1String hash, FileSize size) : this(downloadUrl, hash.ToString(), size) {}
|
|
||||||
|
|
||||||
[MemoryPackConstructor]
|
|
||||||
private FileDownloadInfo(string downloadUrl, string hash, FileSize size) {
|
|
||||||
this.DownloadUrl = downloadUrl;
|
|
||||||
this.hash = hash;
|
|
||||||
this.Size = size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
using MemoryPack;
|
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Minecraft;
|
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
|
||||||
public sealed partial record MinecraftStopStrategy(
|
|
||||||
[property: MemoryPackOrder(0)] ushort Seconds
|
|
||||||
) {
|
|
||||||
public static MinecraftStopStrategy Instant => new (0);
|
|
||||||
}
|
|
||||||
@@ -3,47 +3,8 @@
|
|||||||
namespace Phantom.Common.Data;
|
namespace Phantom.Common.Data;
|
||||||
|
|
||||||
[MemoryPackable]
|
[MemoryPackable]
|
||||||
public readonly partial struct Optional<T> {
|
public readonly partial record struct Optional<T>(T? Value) {
|
||||||
[MemoryPackOrder(0)]
|
public static implicit operator Optional<T>(T? value) {
|
||||||
public bool HasValue { get; }
|
|
||||||
|
|
||||||
[MemoryPackOrder(1)]
|
|
||||||
public T Value {
|
|
||||||
get {
|
|
||||||
if (HasValue) {
|
|
||||||
return field!;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[MemoryPackIgnore]
|
|
||||||
public T? ValueOrDefault => HasValue ? Value : default;
|
|
||||||
|
|
||||||
public Optional() : this(hasValue: false, value: default) {}
|
|
||||||
public Optional(T value) : this(hasValue: true, value) {}
|
|
||||||
|
|
||||||
[MemoryPackConstructor]
|
|
||||||
private Optional(bool hasValue, T? value) {
|
|
||||||
this.HasValue = hasValue;
|
|
||||||
this.Value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<R> Map<R>(Func<T, R> func) {
|
|
||||||
return HasValue ? new Optional<R>(func(Value)) : new Optional<R>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Or(T fallbackValue) {
|
|
||||||
return HasValue ? Value : fallbackValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<T> Or(Optional<T> fallbackOptional) {
|
|
||||||
return HasValue ? Value : fallbackOptional;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static implicit operator Optional<T>(T value) {
|
|
||||||
return new Optional<T>(value);
|
return new Optional<T>(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
using MemoryPack;
|
|
||||||
|
|
||||||
namespace Phantom.Common.Data;
|
|
||||||
|
|
||||||
[MemoryPackable]
|
|
||||||
public readonly partial struct OptionalNullable<T> {
|
|
||||||
[MemoryPackOrder(0)]
|
|
||||||
public bool HasValue { get; }
|
|
||||||
|
|
||||||
[MemoryPackOrder(1)]
|
|
||||||
public T? Value {
|
|
||||||
get {
|
|
||||||
if (HasValue) {
|
|
||||||
return field;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public OptionalNullable() : this(hasValue: false, value: default) {}
|
|
||||||
public OptionalNullable(T? value) : this(hasValue: true, value) {}
|
|
||||||
|
|
||||||
[MemoryPackConstructor]
|
|
||||||
private OptionalNullable(bool hasValue, T? value) {
|
|
||||||
this.HasValue = hasValue;
|
|
||||||
this.Value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T? Or(T? fallbackValue) {
|
|
||||||
return HasValue ? Value : fallbackValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OptionalNullable<T> Or(OptionalNullable<T> fallbackOptional) {
|
|
||||||
return HasValue ? Value : fallbackOptional;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static implicit operator OptionalNullable<T>(T? value) {
|
|
||||||
return new OptionalNullable<T>(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
namespace Phantom.Common.Data.Replies;
|
namespace Phantom.Common.Data.Replies;
|
||||||
|
|
||||||
public enum ConfigureInstanceResult : byte {
|
public enum ConfigureInstanceResult : byte {
|
||||||
Success,
|
Success = 0,
|
||||||
|
CouldNotCreateInstanceFolder = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ConfigureInstanceResultExtensions {
|
public static class ConfigureInstanceResultExtensions {
|
||||||
public static string ToSentence(this ConfigureInstanceResult reason) {
|
public static string ToSentence(this ConfigureInstanceResult reason) {
|
||||||
return reason switch {
|
return reason switch {
|
||||||
ConfigureInstanceResult.Success => "Success.",
|
ConfigureInstanceResult.Success => "Success.",
|
||||||
_ => "Unknown error.",
|
ConfigureInstanceResult.CouldNotCreateInstanceFolder => "Could not create instance folder.",
|
||||||
|
_ => "Unknown error.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
namespace Phantom.Common.Data.Replies;
|
namespace Phantom.Common.Data.Replies;
|
||||||
|
|
||||||
public enum LaunchInstanceResult : byte {
|
public enum LaunchInstanceResult : byte {
|
||||||
LaunchInitiated = 1,
|
LaunchInitiated = 1,
|
||||||
InstanceAlreadyLaunching = 2,
|
InstanceAlreadyLaunching = 2,
|
||||||
InstanceAlreadyRunning = 3,
|
InstanceAlreadyRunning = 3,
|
||||||
InstanceLimitExceeded = 4,
|
InstanceLimitExceeded = 4,
|
||||||
MemoryLimitExceeded = 5,
|
MemoryLimitExceeded = 5,
|
||||||
ServerPortNotAllowed = 6,
|
ServerPortNotAllowed = 6,
|
||||||
ServerPortAlreadyInUse = 7,
|
ServerPortAlreadyInUse = 7,
|
||||||
RconPortNotAllowed = 8,
|
AdditionalPortNotAllowed = 8,
|
||||||
RconPortAlreadyInUse = 9,
|
AdditionalPortAlreadyInUse = 9,
|
||||||
|
InvalidConfiguration = 10,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
using Phantom.Utils.Monads;
|
|
||||||
using Phantom.Utils.Result;
|
using Phantom.Utils.Result;
|
||||||
|
|
||||||
namespace Phantom.Common.Data;
|
namespace Phantom.Common.Data;
|
||||||
@@ -25,9 +24,6 @@ public sealed partial class Result<TValue, TError> {
|
|||||||
[MemoryPackIgnore]
|
[MemoryPackIgnore]
|
||||||
public TError Error => !hasValue ? error! : throw new InvalidOperationException("Attempted to get error from a success result.");
|
public TError Error => !hasValue ? error! : throw new InvalidOperationException("Attempted to get error from a success result.");
|
||||||
|
|
||||||
[MemoryPackIgnore]
|
|
||||||
public Either<TValue, TError> AsEither => hasValue ? Either.Left(value!) : Either.Right(error!);
|
|
||||||
|
|
||||||
private Result(bool hasValue, TValue? value, TError? error) {
|
private Result(bool hasValue, TValue? value, TError? error) {
|
||||||
this.hasValue = hasValue;
|
this.hasValue = hasValue;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
@@ -38,6 +34,11 @@ public sealed partial class Result<TValue, TError> {
|
|||||||
return hasValue && EqualityComparer<TValue>.Default.Equals(value, expectedValue);
|
return hasValue && EqualityComparer<TValue>.Default.Equals(value, expectedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[return: NotNullIfNotNull(nameof(valueIfError))]
|
||||||
|
public TValue? OrElse(TValue? valueIfError) {
|
||||||
|
return hasValue ? Value : valueIfError;
|
||||||
|
}
|
||||||
|
|
||||||
public TOutput Into<TOutput>(Func<TValue, TOutput> valueConverter, Func<TError, TOutput> errorConverter) {
|
public TOutput Into<TOutput>(Func<TValue, TOutput> valueConverter, Func<TError, TOutput> errorConverter) {
|
||||||
return hasValue ? valueConverter(value!) : errorConverter(error!);
|
return hasValue ? valueConverter(value!) : errorConverter(error!);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Phantom.Common.Data\Phantom.Common.Data.csproj" />
|
<ProjectReference Include="..\Phantom.Common.Data.Agent\Phantom.Common.Data.Agent.csproj" />
|
||||||
<ProjectReference Include="..\..\Utils\Phantom.Utils.Logging\Phantom.Utils.Logging.csproj" />
|
<ProjectReference Include="..\..\Utils\Phantom.Utils.Logging\Phantom.Utils.Logging.csproj" />
|
||||||
<ProjectReference Include="..\..\Utils\Phantom.Utils.Rpc\Phantom.Utils.Rpc.csproj" />
|
<ProjectReference Include="..\..\Utils\Phantom.Utils.Rpc\Phantom.Utils.Rpc.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Agent.Instance;
|
||||||
|
using Phantom.Common.Data.Agent.Instance.Launch;
|
||||||
|
using Phantom.Common.Data.Agent.Instance.Stop;
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
using Phantom.Utils.Actor;
|
using Phantom.Utils.Actor;
|
||||||
|
|
||||||
@@ -9,7 +11,8 @@ namespace Phantom.Common.Messages.Agent.ToAgent;
|
|||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial record ConfigureInstanceMessage(
|
public sealed partial record ConfigureInstanceMessage(
|
||||||
[property: MemoryPackOrder(0)] Guid InstanceGuid,
|
[property: MemoryPackOrder(0)] Guid InstanceGuid,
|
||||||
[property: MemoryPackOrder(1)] InstanceConfiguration Configuration,
|
[property: MemoryPackOrder(1)] InstanceInfo Info,
|
||||||
[property: MemoryPackOrder(2)] InstanceLaunchProperties LaunchProperties,
|
[property: MemoryPackOrder(2)] InstanceLaunchRecipe? LaunchRecipe,
|
||||||
[property: MemoryPackOrder(3)] bool LaunchNow = false
|
[property: MemoryPackOrder(3)] bool LaunchNow,
|
||||||
|
[property: MemoryPackOrder(4)] InstanceStopRecipe StopRecipe
|
||||||
) : IMessageToAgent, ICanReply<Result<ConfigureInstanceResult, InstanceActionFailure>>;
|
) : IMessageToAgent, ICanReply<Result<ConfigureInstanceResult, InstanceActionFailure>>;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
using Phantom.Common.Data.Minecraft;
|
using Phantom.Common.Data.Agent.Instance.Stop;
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
using Phantom.Utils.Actor;
|
using Phantom.Utils.Actor;
|
||||||
|
|
||||||
@@ -9,5 +9,5 @@ namespace Phantom.Common.Messages.Agent.ToAgent;
|
|||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial record StopInstanceMessage(
|
public sealed partial record StopInstanceMessage(
|
||||||
[property: MemoryPackOrder(0)] Guid InstanceGuid,
|
[property: MemoryPackOrder(0)] Guid InstanceGuid,
|
||||||
[property: MemoryPackOrder(1)] MinecraftStopStrategy StopStrategy
|
[property: MemoryPackOrder(1)] InstanceStopRecipe StopRecipe
|
||||||
) : IMessageToAgent, ICanReply<Result<StopInstanceResult, InstanceActionFailure>>;
|
) : IMessageToAgent, ICanReply<Result<StopInstanceResult, InstanceActionFailure>>;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
using Phantom.Common.Data.Instance;
|
|
||||||
using Phantom.Common.Data.Web.Instance;
|
using Phantom.Common.Data.Web.Instance;
|
||||||
using Phantom.Common.Data.Web.Users;
|
using Phantom.Common.Data.Web.Users;
|
||||||
using Phantom.Utils.Actor;
|
using Phantom.Utils.Actor;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
using Phantom.Common.Data.Minecraft;
|
using Phantom.Common.Data.Web.Minecraft;
|
||||||
using Phantom.Utils.Actor;
|
using Phantom.Utils.Actor;
|
||||||
|
|
||||||
namespace Phantom.Common.Messages.Web.ToController;
|
namespace Phantom.Common.Messages.Web.ToController;
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user