1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2026-03-01 05:07:53 +01:00

2 Commits

Author SHA1 Message Date
c996a9eaf1 wip 2026-02-22 07:11:05 +01:00
acb5a4daf8 Introduce instance launch recipes 2026-02-22 07:10:46 +01:00
46 changed files with 155 additions and 155 deletions

View File

@@ -1,9 +1,9 @@
using System.Collections.Immutable;
using NUnit.Framework;
using Phantom.Agent.Services.Java;
using Phantom.Agent.Minecraft.Java;
using Phantom.Utils.Collections;
namespace Phantom.Agent.Services.Tests.Java;
namespace Phantom.Agent.Minecraft.Tests.Java;
[TestFixture]
public sealed class JavaPropertiesStreamTests {

View File

@@ -17,7 +17,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Phantom.Agent.Services\Phantom.Agent.Services.csproj" />
<ProjectReference Include="..\Phantom.Agent.Minecraft\Phantom.Agent.Minecraft.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,6 @@
namespace Phantom.Agent.Services.Games;
namespace Phantom.Agent.Minecraft.Command;
static class MinecraftCommand {
public static class MinecraftCommand {
public const string SaveOn = "save-on";
public const string SaveOff = "save-off";
public const string Stop = "stop";

View File

@@ -2,9 +2,9 @@
using Phantom.Utils.Processes;
using Phantom.Utils.Tasks;
namespace Phantom.Agent.Services.Instances.State;
namespace Phantom.Agent.Minecraft.Instance;
sealed class InstanceProcess : IDisposable {
public sealed class InstanceProcess : IDisposable {
public InstanceProperties InstanceProperties { get; }
private readonly RingBuffer<string> outputBuffer = new (100);

View File

@@ -0,0 +1,6 @@
namespace Phantom.Agent.Minecraft.Instance;
public sealed record InstanceProperties(
Guid InstanceGuid,
string InstanceFolder
);

View File

@@ -1,4 +1,4 @@
namespace Phantom.Agent.Services.Java;
namespace Phantom.Agent.Minecraft.Java;
sealed class JavaPropertiesFileEditor {
private readonly Dictionary<string, string> overriddenProperties = new ();

View File

@@ -4,7 +4,7 @@ using System.Runtime.CompilerServices;
using System.Text;
using Phantom.Utils.Collections;
namespace Phantom.Agent.Services.Java;
namespace Phantom.Agent.Minecraft.Java;
static class JavaPropertiesStream {
internal static readonly Encoding Encoding = Encoding.GetEncoding("ISO-8859-1");

View File

@@ -6,7 +6,7 @@ using Phantom.Utils.IO;
using Phantom.Utils.Logging;
using Serilog;
namespace Phantom.Agent.Services.Java;
namespace Phantom.Agent.Minecraft.Java;
public sealed class JavaRuntimeDiscovery {
private static readonly ILogger Logger = PhantomLogger.Create(nameof(JavaRuntimeDiscovery));

View File

@@ -0,0 +1,5 @@
using Phantom.Common.Data.Java;
namespace Phantom.Agent.Minecraft.Java;
public sealed record JavaRuntimeExecutable(string ExecutablePath, JavaRuntime Runtime);

View File

@@ -3,7 +3,7 @@ using System.Diagnostics.CodeAnalysis;
using Phantom.Common.Data.Java;
using Phantom.Utils.Cryptography;
namespace Phantom.Agent.Services.Java;
namespace Phantom.Agent.Minecraft.Java;
public sealed class JavaRuntimeRepository {
private readonly ImmutableDictionary<Guid, JavaRuntimeExecutable> runtimesByGuid;
@@ -25,7 +25,7 @@ public sealed class JavaRuntimeRepository {
.ToImmutableArray();
}
internal bool TryGetByGuid(Guid guid, [MaybeNullWhen(false)] out JavaRuntimeExecutable runtime) {
public bool TryGetByGuid(Guid guid, [MaybeNullWhen(false)] out JavaRuntimeExecutable runtime) {
return runtimesByGuid.TryGetValue(guid, out runtime);
}

View File

@@ -1,7 +1,7 @@
using System.Collections.Immutable;
using Phantom.Agent.Services.Downloads;
using Phantom.Agent.Services.Instances.State;
using Phantom.Agent.Services.Java;
using Phantom.Agent.Minecraft.Instance;
using Phantom.Agent.Minecraft.Java;
using Phantom.Agent.Minecraft.Server;
using Phantom.Common.Data.Agent;
using Phantom.Common.Data.Agent.Instance;
using Phantom.Common.Data.Agent.Instance.Launch;
@@ -9,36 +9,33 @@ using Phantom.Common.Data.Instance;
using Phantom.Utils.Processes;
using Serilog;
namespace Phantom.Agent.Services.Instances.Launch;
namespace Phantom.Agent.Minecraft.Launcher;
sealed class InstanceLauncher(
public sealed class InstanceLauncher(
FileDownloadManager downloadManager,
IInstancePathResolver pathResolver,
IInstanceValueResolver valueResolver,
InstanceProperties instanceProperties,
InstanceLaunchRecipe launchRecipe
) {
public async Task<InstanceLaunchResult> Launch(ILogger logger, Action<IInstanceStatus?> reportStatus, CancellationToken cancellationToken) {
public async Task<LaunchResult> 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();
logger.Error("Could not resolve server executable path");
return new LaunchResult.CouldNotFindServerExecutable();
}
var stepExecutor = new StepExecutor(logger, downloadManager, pathResolver, reportStatus, cancellationToken);
var stepExecutor = new StepExecutor(downloadManager, pathResolver, reportStatus, cancellationToken);
var steps = launchRecipe.Preparation;
for (int stepIndex = 0; stepIndex < steps.Length; stepIndex++) {
var step = steps[stepIndex];
try {
if (await step.Run(stepExecutor)) {
continue;
}
await step.Run(stepExecutor);
} catch (Exception e) {
logger.Error(e, "Failed preparation step {StepIndex} out of {StepCount}: {StepName}", stepIndex, steps.Length, step.GetType().Name);
logger.Error(e, "Failed preparation step {StepIndex} out of {StepCount}: {Step}", stepIndex, steps.Length, step.GetType().Name);
return new LaunchResult.CouldNotPrepareServerInstance();
}
return new InstanceLaunchResult.CouldNotPrepareServerInstance();
}
var processConfigurator = new ProcessConfigurator {
@@ -50,13 +47,13 @@ sealed class InstanceLauncher(
var processArguments = processConfigurator.ArgumentList;
foreach (IInstanceValue value in launchRecipe.Arguments) {
foreach (var 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();
return new LaunchResult.CouldNotPrepareServerInstance();
}
}
@@ -74,18 +71,18 @@ sealed class InstanceLauncher(
logger.Error(killException, "Caught exception trying to kill the server process after a failed launch.");
}
return new InstanceLaunchResult.CouldNotStartServerExecutable();
return new LaunchResult.CouldNotStartServerExecutable();
}
return new InstanceLaunchResult.Success(instanceProcess);
return new LaunchResult.Success(instanceProcess);
}
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) {
private sealed class StepExecutor(FileDownloadManager downloadManager, IInstancePathResolver pathResolver, Action<IInstanceStatus?> reportStatus, CancellationToken cancellationToken) : IInstanceLaunchStepExecutor {
public async Task 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;
// TODO avoid exc
throw new FileNotFoundException("Could not resolve path");
}
byte? lastDownloadProgress = null;
@@ -100,32 +97,21 @@ sealed class InstanceLauncher(
}
if (await downloadManager.DownloadAndGetPath(downloadInfo, filePath, OnDownloadProgress, cancellationToken) == null) {
logger.Error("Could not download file: {Url}", downloadInfo.Url);
return false;
throw new FileNotFoundException("Could not download file");
}
reportStatus(null);
return true;
}
public async Task<bool> EditPropertiesFile(InstancePath.Local path, string comment, ImmutableDictionary<string, string> newValues) {
public async Task 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;
throw new FileNotFoundException("Could not resolve path");
}
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;
await editor.EditOrCreate(filePath, comment, cancellationToken);
}
}
}

View File

@@ -0,0 +1,15 @@
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 CouldNotPrepareServerInstance : LaunchResult;
public sealed record CouldNotFindServerExecutable : LaunchResult;
public sealed record CouldNotStartServerExecutable : LaunchResult;
}

View File

@@ -0,0 +1,18 @@
<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.Agent\Phantom.Common.Data.Agent.csproj" />
<ProjectReference Include="..\..\Utils\Phantom.Utils\Phantom.Utils.csproj" />
<ProjectReference Include="..\..\Utils\Phantom.Utils.Logging\Phantom.Utils.Logging.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,6 @@
namespace Phantom.Agent.Services.Downloads;
namespace Phantom.Agent.Minecraft.Server;
sealed class DownloadProgressEventArgs : EventArgs {
public sealed class DownloadProgressEventArgs : EventArgs {
public ulong DownloadedBytes { get; }
public ulong? TotalBytes { get; }

View File

@@ -1,3 +1,3 @@
namespace Phantom.Agent.Services.Downloads;
namespace Phantom.Agent.Minecraft.Server;
sealed record FileDownloadListener(EventHandler<DownloadProgressEventArgs> DownloadProgressEventHandler, CancellationToken CancellationToken);

View File

@@ -3,14 +3,14 @@ using Phantom.Utils.IO;
using Phantom.Utils.Logging;
using Serilog;
namespace Phantom.Agent.Services.Downloads;
namespace Phantom.Agent.Minecraft.Server;
sealed class FileDownloadManager {
public 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) {
internal async Task<string?> DownloadAndGetPath(FileDownloadInfo fileDownloadInfo, string filePath, EventHandler<DownloadProgressEventArgs> progressEventHandler, CancellationToken cancellationToken) {
var fileInfo = new FileInfo(filePath);
if (fileInfo.Exists) {
return filePath;

View File

@@ -7,7 +7,7 @@ using Phantom.Utils.Net;
using Phantom.Utils.Runtime;
using Serilog;
namespace Phantom.Agent.Services.Downloads;
namespace Phantom.Agent.Minecraft.Server;
sealed class FileDownloader {
private static readonly ILogger Logger = PhantomLogger.Create<FileDownloader>();
@@ -103,7 +103,7 @@ sealed class FileDownloader {
}
private static async Task DownloadFile(string filePath, FileDownloadInfo fileDownloadInfo, DownloadProgressCallback progressCallback, CancellationToken cancellationToken) {
string downloadUrl = fileDownloadInfo.Url;
string downloadUrl = fileDownloadInfo.DownloadUrl;
DownloadResult result;
try {

View File

@@ -5,15 +5,15 @@ using System.Net.Sockets;
using System.Text;
using Phantom.Common.Data.Instance;
namespace Phantom.Agent.Services.Games;
namespace Phantom.Agent.Minecraft.Server;
static class MinecraftServerStatusProtocol {
public static class ServerStatusProtocol {
public static async Task<InstancePlayerCounts> GetPlayerCounts(ushort serverPort, CancellationToken cancellationToken) {
using var tcpClient = new TcpClient();
await tcpClient.ConnectAsync(IPAddress.Loopback, serverPort, cancellationToken);
var tcpStream = tcpClient.GetStream();
// https://minecraft.wiki/w/Java_Edition_protocol/Server_List_Ping
// https://wiki.vg/Server_List_Ping
tcpStream.WriteByte(0xFE);
await tcpStream.FlushAsync(cancellationToken);

View File

@@ -1,7 +1,7 @@
using Akka.Actor;
using Phantom.Agent.Minecraft.Java;
using Phantom.Agent.Services.Backups;
using Phantom.Agent.Services.Instances;
using Phantom.Agent.Services.Java;
using Phantom.Agent.Services.Rpc;
using Phantom.Common.Data.Agent;
using Phantom.Utils.Actor;

View File

@@ -1,7 +1,7 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Formats.Tar;
using Phantom.Agent.Services.Instances;
using Phantom.Agent.Minecraft.Instance;
using Phantom.Common.Data.Backups;
using Phantom.Utils.IO;
using Phantom.Utils.Logging;

View File

@@ -1,4 +1,4 @@
using Phantom.Agent.Services.Instances.State;
using Phantom.Agent.Minecraft.Instance;
using Phantom.Common.Data.Backups;
using Phantom.Utils.Logging;
using Serilog;

View File

@@ -1,7 +1,7 @@
using System.Collections.Immutable;
using System.Text.RegularExpressions;
using Phantom.Agent.Services.Games;
using Phantom.Agent.Services.Instances.State;
using Phantom.Agent.Minecraft.Command;
using Phantom.Agent.Minecraft.Instance;
using Phantom.Utils.Tasks;
using Serilog;

View File

@@ -1,5 +1,5 @@
using Phantom.Agent.Services.Backups;
using Phantom.Agent.Services.Instances.Launch;
using Phantom.Agent.Minecraft.Launcher;
using Phantom.Agent.Services.Backups;
using Phantom.Agent.Services.Instances.State;
using Phantom.Agent.Services.Rpc;
using Phantom.Common.Data.Agent.Instance;

View File

@@ -1,7 +1,8 @@
using Phantom.Agent.Services.Backups;
using Phantom.Agent.Services.Downloads;
using Phantom.Agent.Services.Instances.Launch;
using Phantom.Agent.Services.Java;
using Phantom.Agent.Minecraft.Instance;
using Phantom.Agent.Minecraft.Java;
using Phantom.Agent.Minecraft.Launcher;
using Phantom.Agent.Minecraft.Server;
using Phantom.Agent.Services.Backups;
using Phantom.Agent.Services.Rpc;
using Phantom.Common.Data;
using Phantom.Common.Data.Agent.Instance;

View File

@@ -1,9 +1,10 @@
using System.Buffers;
using System.Collections.Immutable;
using Phantom.Agent.Services.Java;
using Phantom.Agent.Minecraft.Instance;
using Phantom.Agent.Minecraft.Java;
using Phantom.Common.Data.Agent.Instance;
namespace Phantom.Agent.Services.Instances.Launch;
namespace Phantom.Agent.Services.Instances;
sealed class InstancePathResolver(AgentFolders agentFolders, JavaRuntimeRepository javaRuntimeRepository, InstanceProperties instanceProperties) : IInstancePathResolver {
public string? Global(ImmutableArray<string> segments) {

View File

@@ -1,6 +0,0 @@
namespace Phantom.Agent.Services.Instances;
sealed record InstanceProperties(
Guid InstanceGuid,
string InstanceFolder
);

View File

@@ -1,6 +1,6 @@
using Phantom.Agent.Services.Backups;
using Phantom.Agent.Services.Downloads;
using Phantom.Agent.Services.Java;
using Phantom.Agent.Minecraft.Java;
using Phantom.Agent.Minecraft.Server;
using Phantom.Agent.Services.Backups;
using Phantom.Agent.Services.Rpc;
namespace Phantom.Agent.Services.Instances;

View File

@@ -1,6 +1,6 @@
using Phantom.Common.Data.Agent.Instance;
namespace Phantom.Agent.Services.Instances.Launch;
namespace Phantom.Agent.Services.Instances;
sealed class InstanceValueResolver(IInstancePathResolver pathResolver) : IInstanceValueResolver {
public string? Path(IInstancePath value) {

View File

@@ -1,15 +0,0 @@
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;
}

View File

@@ -1,9 +1,10 @@
using Phantom.Agent.Services.Instances.State;
using Phantom.Agent.Minecraft.Instance;
using Phantom.Agent.Minecraft.Launcher;
using Phantom.Common.Data;
using Phantom.Common.Data.Agent.Instance;
using Phantom.Common.Data.Instance;
namespace Phantom.Agent.Services.Instances.Launch;
namespace Phantom.Agent.Services.Instances.State;
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) {
@@ -43,18 +44,18 @@ static class InstanceLaunchProcedure {
cancellationToken.ThrowIfCancellationRequested();
switch (await launcher.Launch(context.Logger, reportStatus, cancellationToken)) {
case InstanceLaunchResult.Success launchSuccess:
case LaunchResult.Success launchSuccess:
return launchSuccess.Process;
case InstanceLaunchResult.CouldNotPrepareServerInstance:
case LaunchResult.CouldNotPrepareServerInstance:
context.Logger.Error("Session failed to launch, could not prepare server instance.");
return InstanceLaunchFailReason.CouldNotPrepareServerInstance;
case InstanceLaunchResult.CouldNotFindServerExecutable:
case LaunchResult.CouldNotFindServerExecutable:
context.Logger.Error("Session failed to launch, could not find server executable.");
return InstanceLaunchFailReason.CouldNotFindServerExecutable;
case InstanceLaunchResult.CouldNotStartServerExecutable:
case LaunchResult.CouldNotStartServerExecutable:
context.Logger.Error("Session failed to launch, could not start server executable.");
return InstanceLaunchFailReason.CouldNotStartServerExecutable;

View File

@@ -1,5 +1,6 @@
using System.Net.Sockets;
using Phantom.Agent.Services.Games;
using Phantom.Agent.Minecraft.Instance;
using Phantom.Agent.Minecraft.Server;
using Phantom.Agent.Services.Rpc;
using Phantom.Common.Data.Instance;
using Phantom.Common.Messages.Agent.ToController;
@@ -59,9 +60,9 @@ sealed class InstancePlayerCountTracker : CancellableBackgroundTask {
private async Task<InstancePlayerCounts?> TryGetPlayerCounts() {
try {
return await MinecraftServerStatusProtocol.GetPlayerCounts(serverPort, CancellationToken);
} catch (MinecraftServerStatusProtocol.ProtocolException e) {
Logger.Error("Could not check online player count due to protocol error: {Message}", e.Message);
return await ServerStatusProtocol.GetPlayerCounts(serverPort, CancellationToken);
} catch (ServerStatusProtocol.ProtocolException e) {
Logger.Error("{Message}", e.Message);
return null;
} catch (SocketException e) {
bool waitingForServerStart = e.SocketErrorCode == SocketError.ConnectionRefused && WaitingForFirstDetection;

View File

@@ -1,5 +1,6 @@
using Phantom.Agent.Services.Backups;
using Phantom.Agent.Services.Instances.Launch;
using Phantom.Agent.Minecraft.Instance;
using Phantom.Agent.Minecraft.Launcher;
using Phantom.Agent.Services.Backups;
using Phantom.Common.Data.Agent.Instance;
using Phantom.Common.Data.Backups;
using Phantom.Common.Data.Instance;

View File

@@ -1,5 +1,6 @@
using System.Diagnostics;
using Phantom.Agent.Services.Games;
using Phantom.Agent.Minecraft.Command;
using Phantom.Agent.Minecraft.Instance;
using Phantom.Common.Data.Instance;
using Phantom.Common.Data.Minecraft;

View File

@@ -1,5 +0,0 @@
using Phantom.Common.Data.Java;
namespace Phantom.Agent.Services.Java;
sealed record JavaRuntimeExecutable(string ExecutablePath, JavaRuntime Runtime);

View File

@@ -5,12 +5,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<InternalsVisibleTo Include="Phantom.Agent.Services.Tests" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Common\Phantom.Common.Messages.Agent\Phantom.Common.Messages.Agent.csproj" />
<ProjectReference Include="..\Phantom.Agent.Minecraft\Phantom.Agent.Minecraft.csproj" />
</ItemGroup>
</Project>

View File

@@ -12,6 +12,7 @@
<ItemGroup>
<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" />
</ItemGroup>

View File

@@ -1,7 +1,7 @@
using System.Reflection;
using Phantom.Agent;
using Phantom.Agent.Minecraft.Java;
using Phantom.Agent.Services;
using Phantom.Agent.Services.Java;
using Phantom.Agent.Services.Rpc;
using Phantom.Common.Data.Agent;
using Phantom.Common.Messages.Agent;

View File

@@ -1,4 +1,4 @@
using Phantom.Agent.Services.Java;
using Phantom.Agent.Minecraft.Java;
using Phantom.Common.Data;
using Phantom.Utils.Logging;
using Phantom.Utils.Runtime;

View File

@@ -6,7 +6,7 @@ namespace Phantom.Common.Data.Agent;
[MemoryPackable(GenerateType.VersionTolerant)]
public sealed partial class FileDownloadInfo {
[MemoryPackOrder(0)]
public string Url { get; }
public string DownloadUrl { get; }
[MemoryPackOrder(1)]
[MemoryPackInclude]
@@ -15,11 +15,11 @@ public sealed partial class FileDownloadInfo {
[MemoryPackIgnore]
public Sha1String? Hash => hash == null ? null : Sha1String.FromString(hash);
public FileDownloadInfo(string url, Sha1String? hash = null) : this(url, hash?.ToString()) {}
public FileDownloadInfo(string downloadUrl, Sha1String? hash = null) : this(downloadUrl, hash?.ToString()) {}
[MemoryPackConstructor]
private FileDownloadInfo(string url, string? hash) {
this.Url = url;
private FileDownloadInfo(string downloadUrl, string? hash) {
this.DownloadUrl = downloadUrl;
this.hash = hash;
}
}

View File

@@ -21,7 +21,7 @@ public static partial class InstancePath {
}
public override string ToString() {
return "Global[" + string.Join(separator: '/', Segments) + "]";
return string.Join(separator: '/', Segments);
}
}
@@ -34,7 +34,7 @@ public static partial class InstancePath {
}
public override string ToString() {
return "Local[" + string.Join(separator: '/', Segments) + "]";
return string.Join(separator: '/', Segments);
}
}
@@ -45,9 +45,5 @@ public static partial class InstancePath {
public string? Resolve(IInstancePathResolver resolver) {
return resolver.Runtime(Guid);
}
public override string ToString() {
return "Runtime[" + Guid + "]";
}
}
}

View File

@@ -29,10 +29,6 @@ public static partial class InstanceValues {
return result.ToString();
}
public override string ToString() {
return "Concatenation[" + string.Join(",", Values) + "]";
}
}
[MemoryPackable]
@@ -40,10 +36,6 @@ public static partial class InstanceValues {
public string Resolve(IInstanceValueResolver resolver) {
return Value;
}
public override string ToString() {
return "Text[" + Value + "]";
}
}
[MemoryPackable]
@@ -51,9 +43,5 @@ public static partial class InstanceValues {
public string? Resolve(IInstanceValueResolver resolver) {
return resolver.Path(Value);
}
public override string ToString() {
return "Path[" + Value + "]";
}
}
}

View File

@@ -7,7 +7,7 @@ namespace Phantom.Common.Data.Agent.Instance.Launch;
[MemoryPackUnion(tag: 0, typeof(InstanceLaunchStep.DownloadFile))]
[MemoryPackUnion(tag: 1, typeof(InstanceLaunchStep.EditPropertiesFile))]
public partial interface IInstanceLaunchStep {
Task<TResult> Run<TResult>(IInstanceLaunchStepExecutor<TResult> executor);
Task Run(IInstanceLaunchStepExecutor executor);
}
public static partial class InstanceLaunchStep {
@@ -16,7 +16,7 @@ public static partial class InstanceLaunchStep {
[property: MemoryPackOrder(0)] FileDownloadInfo DownloadInfo,
[property: MemoryPackOrder(1)] IInstancePath Path
) : IInstanceLaunchStep {
public Task<TResult> Run<TResult>(IInstanceLaunchStepExecutor<TResult> executor) {
public Task Run(IInstanceLaunchStepExecutor executor) {
return executor.DownloadFile(DownloadInfo, Path);
}
}
@@ -27,7 +27,7 @@ public static partial class InstanceLaunchStep {
[property: MemoryPackOrder(1)] string Comment,
[property: MemoryPackOrder(2)] ImmutableDictionary<string, string> NewValues
) : IInstanceLaunchStep {
public Task<TResult> Run<TResult>(IInstanceLaunchStepExecutor<TResult> executor) {
public Task Run(IInstanceLaunchStepExecutor executor) {
return executor.EditPropertiesFile(Path, Comment, NewValues);
}
}

View File

@@ -1,8 +1,9 @@
using System.Collections.Immutable;
using Phantom.Common.Data.Minecraft;
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);
public interface IInstanceLaunchStepExecutor {
Task DownloadFile(FileDownloadInfo downloadInfo, IInstancePath path);
Task EditPropertiesFile(InstancePath.Local path, string comment, ImmutableDictionary<string, string> newValues);
}

View File

@@ -53,8 +53,8 @@ public sealed partial class MinecraftLaunchRecipes(MinecraftVersions minecraftVe
return new InstanceLaunchRecipe(steps.ToImmutable(), new InstancePath.Runtime(configuration.JavaRuntimeGuid), [
..configuration.JvmArguments.Select(static arg => new InstanceValues.Text(arg)),
..additionalJvmArguments,
new InstanceValues.Text($"-Xms{initialHeapSizeMegabytes}M"),
new InstanceValues.Text($"-Xmx{maximumHeapSizeMegabvtes}M"),
new InstanceValues.Text("-Xms" + initialHeapSizeMegabytes + "M"),
new InstanceValues.Text("-Xmx" + maximumHeapSizeMegabvtes + "M"),
new InstanceValues.Text("-jar"),
new InstanceValues.Path(serverExecutableFilePath),
new InstanceValues.Text("-nogui"),

View File

@@ -47,7 +47,7 @@ public sealed class MinecraftVersions : IDisposable {
Logger.Information("Refreshed Minecraft {Version} server executable cache, no file found.", version);
}
else {
Logger.Information("Refreshed Minecraft {Version} server executable cache, found file: {Url}.", version, info.Url);
Logger.Information("Refreshed Minecraft {Version} server executable cache, found file: {Url}.", version, info.DownloadUrl);
}
return info;

View File

@@ -18,7 +18,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Web", "Web", "{92B26F48-235
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Phantom.Agent", "Agent\Phantom.Agent\Phantom.Agent.csproj", "{418BE1BF-9F63-4B46-B4E4-DF64C3B3DDA7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Phantom.Agent.Services.Tests", "Agent\Phantom.Agent.Services.Tests\Phantom.Agent.Services.Tests.csproj", "{065FFFA0-DFF4-43DB-AB3D-B92EE9848DDB}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Phantom.Agent.Minecraft", "Agent\Phantom.Agent.Minecraft\Phantom.Agent.Minecraft.csproj", "{9FE000D0-91AC-4CB4-8956-91CCC0270015}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Phantom.Agent.Minecraft.Tests", "Agent\Phantom.Agent.Minecraft.Tests\Phantom.Agent.Minecraft.Tests.csproj", "{065FFFA0-DFF4-43DB-AB3D-B92EE9848DDB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Phantom.Agent.Services", "Agent\Phantom.Agent.Services\Phantom.Agent.Services.csproj", "{AEE8B77E-AB07-423F-9981-8CD829ACB834}"
EndProject
@@ -74,6 +76,10 @@ Global
{418BE1BF-9F63-4B46-B4E4-DF64C3B3DDA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{418BE1BF-9F63-4B46-B4E4-DF64C3B3DDA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{418BE1BF-9F63-4B46-B4E4-DF64C3B3DDA7}.Release|Any CPU.Build.0 = Release|Any CPU
{9FE000D0-91AC-4CB4-8956-91CCC0270015}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9FE000D0-91AC-4CB4-8956-91CCC0270015}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9FE000D0-91AC-4CB4-8956-91CCC0270015}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9FE000D0-91AC-4CB4-8956-91CCC0270015}.Release|Any CPU.Build.0 = Release|Any CPU
{065FFFA0-DFF4-43DB-AB3D-B92EE9848DDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{065FFFA0-DFF4-43DB-AB3D-B92EE9848DDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{065FFFA0-DFF4-43DB-AB3D-B92EE9848DDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -165,6 +171,7 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{418BE1BF-9F63-4B46-B4E4-DF64C3B3DDA7} = {F5878792-64C8-4ECF-A075-66341FF97127}
{9FE000D0-91AC-4CB4-8956-91CCC0270015} = {F5878792-64C8-4ECF-A075-66341FF97127}
{065FFFA0-DFF4-43DB-AB3D-B92EE9848DDB} = {94C1E464-3F91-49EA-99FF-3A3082C54CE8}
{AEE8B77E-AB07-423F-9981-8CD829ACB834} = {F5878792-64C8-4ECF-A075-66341FF97127}
{6C3DB1E5-F695-4D70-8F3A-78C2957274BE} = {01CB1A81-8950-471C-BFDF-F135FDDB2C18}