mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2026-03-01 05:07:53 +01:00
Compare commits
3 Commits
aed342d17a
...
wip-recipe
| Author | SHA1 | Date | |
|---|---|---|---|
|
da206aacb2
|
|||
|
4ad9534d27
|
|||
|
2c63c1d7e0
|
@@ -13,7 +13,7 @@ static class MinecraftServerStatusProtocol {
|
||||
await tcpClient.ConnectAsync(IPAddress.Loopback, serverPort, cancellationToken);
|
||||
var tcpStream = tcpClient.GetStream();
|
||||
|
||||
// https://wiki.vg/Server_List_Ping
|
||||
// https://minecraft.wiki/w/Java_Edition_protocol/Server_List_Ping
|
||||
tcpStream.WriteByte(0xFE);
|
||||
await tcpStream.FlushAsync(cancellationToken);
|
||||
|
||||
|
||||
@@ -26,7 +26,18 @@ sealed class InstanceLauncher(
|
||||
}
|
||||
|
||||
var stepExecutor = new StepExecutor(logger, downloadManager, pathResolver, reportStatus, cancellationToken);
|
||||
if (!await RunPreparationSteps(logger, 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 (Exception e) {
|
||||
logger.Error(e, "Failed preparation step {StepIndex} out of {StepCount}: {StepName}", stepIndex, steps.Length, step.GetType().Name);
|
||||
}
|
||||
|
||||
return new InstanceLaunchResult.CouldNotPrepareServerInstance();
|
||||
}
|
||||
|
||||
@@ -69,27 +80,6 @@ sealed class InstanceLauncher(
|
||||
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);
|
||||
|
||||
@@ -61,7 +61,7 @@ sealed class InstancePlayerCountTracker : CancellableBackgroundTask {
|
||||
try {
|
||||
return await MinecraftServerStatusProtocol.GetPlayerCounts(serverPort, CancellationToken);
|
||||
} catch (MinecraftServerStatusProtocol.ProtocolException e) {
|
||||
Logger.Error("{Message}", e.Message);
|
||||
Logger.Error("Could not check online player count due to protocol error: {Message}", e.Message);
|
||||
return null;
|
||||
} catch (SocketException e) {
|
||||
bool waitingForServerStart = e.SocketErrorCode == SocketError.ConnectionRefused && WaitingForFirstDetection;
|
||||
|
||||
@@ -11,6 +11,10 @@ using Phantom.Utils.Collections;
|
||||
namespace Phantom.Controller.Minecraft;
|
||||
|
||||
public sealed partial class MinecraftLaunchRecipes(MinecraftVersions minecraftVersions) {
|
||||
private static readonly ImmutableDictionary<string, string> Eula = ImmutableDictionary.From([
|
||||
("eula", "true"),
|
||||
]);
|
||||
|
||||
public async Task<Result<InstanceLaunchRecipe, MinecraftLaunchRecipeCreationFailReason>> Create(InstanceConfiguration configuration, CancellationToken cancellationToken) {
|
||||
string minecraftVersion = configuration.MinecraftVersion;
|
||||
|
||||
@@ -64,10 +68,6 @@ public sealed partial class MinecraftLaunchRecipes(MinecraftVersions minecraftVe
|
||||
return SanitizePathRegex().IsMatch(path) ? SanitizePathRegex().Replace(path, "_") : path;
|
||||
}
|
||||
|
||||
private static readonly ImmutableDictionary<string, string> Eula = ImmutableDictionary.From([
|
||||
("eula", "true"),
|
||||
]);
|
||||
|
||||
private static ImmutableDictionary<string, string> ServerProperties(InstanceConfiguration configuration) {
|
||||
return ImmutableDictionary.From([
|
||||
("server-port", configuration.ServerPort.ToString()),
|
||||
|
||||
Reference in New Issue
Block a user