mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2026-03-01 05:07:53 +01:00
Compare commits
2 Commits
wip-recipe
...
2689e07194
| Author | SHA1 | Date | |
|---|---|---|---|
|
2689e07194
|
|||
|
a5f8872561
|
@@ -13,7 +13,7 @@ static class MinecraftServerStatusProtocol {
|
||||
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);
|
||||
|
||||
|
||||
@@ -26,18 +26,7 @@ sealed class InstanceLauncher(
|
||||
}
|
||||
|
||||
var stepExecutor = new StepExecutor(logger, 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;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.Error(e, "Failed preparation step {StepIndex} out of {StepCount}: {StepName}", stepIndex, steps.Length, step.GetType().Name);
|
||||
}
|
||||
|
||||
if (!await RunPreparationSteps(logger, stepExecutor)) {
|
||||
return new InstanceLaunchResult.CouldNotPrepareServerInstance();
|
||||
}
|
||||
|
||||
@@ -80,6 +69,27 @@ 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("Could not check online player count due to protocol error: {Message}", e.Message);
|
||||
Logger.Error("{Message}", e.Message);
|
||||
return null;
|
||||
} catch (SocketException e) {
|
||||
bool waitingForServerStart = e.SocketErrorCode == SocketError.ConnectionRefused && WaitingForFirstDetection;
|
||||
|
||||
Reference in New Issue
Block a user