mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2026-03-01 05:07:53 +01:00
Compare commits
2 Commits
main
...
2689e07194
| Author | SHA1 | Date | |
|---|---|---|---|
|
2689e07194
|
|||
|
a5f8872561
|
@@ -79,7 +79,6 @@ public sealed class AgentRegistrationHandler {
|
|||||||
configureInstanceMessage.Info,
|
configureInstanceMessage.Info,
|
||||||
configureInstanceMessage.LaunchRecipe,
|
configureInstanceMessage.LaunchRecipe,
|
||||||
configureInstanceMessage.LaunchNow,
|
configureInstanceMessage.LaunchNow,
|
||||||
configureInstanceMessage.StopRecipe,
|
|
||||||
AlwaysReportStatus: true
|
AlwaysReportStatus: true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Phantom.Common.Data.Agent;
|
|||||||
using Phantom.Utils.Cryptography;
|
using Phantom.Utils.Cryptography;
|
||||||
using Phantom.Utils.IO;
|
using Phantom.Utils.IO;
|
||||||
using Phantom.Utils.Logging;
|
using Phantom.Utils.Logging;
|
||||||
|
using Phantom.Utils.Net;
|
||||||
using Phantom.Utils.Runtime;
|
using Phantom.Utils.Runtime;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
@@ -110,7 +111,7 @@ sealed class FileDownloader {
|
|||||||
var response = await httpClient.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
var response = await httpClient.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
FileSize? fileSize = response.Content.Headers.ContentLength is {} length and >= 0 ? new FileSize((ulong) length) : null;
|
FileSize? fileSize = response.Headers.ContentLength;
|
||||||
ulong? fileSizeBytes = fileSize?.Bytes;
|
ulong? fileSizeBytes = fileSize?.Bytes;
|
||||||
|
|
||||||
Logger.Information("Downloading {Url} ({Size})...", downloadUrl, FormatFileSize(fileSize));
|
Logger.Information("Downloading {Url} ({Size})...", downloadUrl, FormatFileSize(fileSize));
|
||||||
|
|||||||
@@ -3,6 +3,11 @@
|
|||||||
static class MinecraftCommand {
|
static class MinecraftCommand {
|
||||||
public const string SaveOn = "save-on";
|
public const string SaveOn = "save-on";
|
||||||
public const string SaveOff = "save-off";
|
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) {
|
public static string SaveAll(bool flush) {
|
||||||
return flush ? "save-all flush" : "save-all";
|
return flush ? "save-all flush" : "save-all";
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ 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;
|
||||||
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;
|
||||||
@@ -85,7 +85,7 @@ sealed class InstanceActor : ReceiveActor<InstanceActor.ICommand> {
|
|||||||
|
|
||||||
public sealed record LaunchInstanceCommand(InstanceInfo Info, InstanceLauncher 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(InstanceStopRecipe StopRecipe) : ICommand;
|
public sealed record StopInstanceCommand(MinecraftStopStrategy StopStrategy) : ICommand;
|
||||||
|
|
||||||
public sealed record SendCommandToInstanceCommand(string Command) : ICommand, ICanReply<SendCommandToInstanceResult>;
|
public sealed record SendCommandToInstanceCommand(string Command) : ICommand, ICanReply<SendCommandToInstanceResult>;
|
||||||
|
|
||||||
@@ -93,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(InstanceStopRecipe StopRecipe) : ICommand;
|
public sealed record ShutdownCommand : ICommand;
|
||||||
|
|
||||||
private void ReportInstanceStatus(ReportInstanceStatusCommand command) {
|
private void ReportInstanceStatus(ReportInstanceStatusCommand command) {
|
||||||
ReportCurrentStatus();
|
ReportCurrentStatus();
|
||||||
@@ -125,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.StopRecipe, runningState, SetAndReportStatus, shutdownCancellationToken)) {
|
if (await InstanceStopProcedure.Run(context, command.StopStrategy, runningState, SetAndReportStatus, shutdownCancellationToken)) {
|
||||||
instanceTicketManager.Release(runningState.Ticket);
|
instanceTicketManager.Release(runningState.Ticket);
|
||||||
TransitionState(null);
|
TransitionState(null);
|
||||||
}
|
}
|
||||||
@@ -167,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(command.StopRecipe));
|
await StopInstance(new StopInstanceCommand(MinecraftStopStrategy.Instant));
|
||||||
await actorCancellationTokenSource.CancelAsync();
|
await actorCancellationTokenSource.CancelAsync();
|
||||||
|
|
||||||
await Task.WhenAll(
|
await Task.WhenAll(
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ 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;
|
||||||
using Phantom.Common.Data.Agent.Instance.Launch;
|
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;
|
||||||
@@ -52,15 +52,15 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
ReceiveAsync<ShutdownCommand>(Shutdown);
|
ReceiveAsync<ShutdownCommand>(Shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed record Instance(ActorRef<InstanceActor.ICommand> Actor, InstanceInfo Info, InstanceProperties Properties, InstanceLaunchRecipe? LaunchRecipe, InstanceStopRecipe StopRecipe);
|
private sealed record Instance(ActorRef<InstanceActor.ICommand> Actor, InstanceInfo Info, InstanceProperties Properties, InstanceLaunchRecipe? LaunchRecipe);
|
||||||
|
|
||||||
public interface ICommand;
|
public interface ICommand;
|
||||||
|
|
||||||
public sealed record ConfigureInstanceCommand(Guid InstanceGuid, InstanceInfo InstanceInfo, InstanceLaunchRecipe? LaunchRecipe, bool LaunchNow, InstanceStopRecipe StopRecipe, bool AlwaysReportStatus) : ICommand, ICanReply<Result<ConfigureInstanceResult, InstanceActionFailure>>;
|
public sealed record ConfigureInstanceCommand(Guid InstanceGuid, InstanceInfo InstanceInfo, InstanceLaunchRecipe? LaunchRecipe, bool LaunchNow, 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, InstanceStopRecipe StopRecipe) : ICommand, ICanReply<Result<StopInstanceResult, InstanceActionFailure>>;
|
public sealed record StopInstanceCommand(Guid InstanceGuid, MinecraftStopStrategy StopStrategy) : 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>>;
|
||||||
|
|
||||||
@@ -70,13 +70,11 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
var instanceGuid = command.InstanceGuid;
|
var instanceGuid = command.InstanceGuid;
|
||||||
var instanceInfo = command.InstanceInfo;
|
var instanceInfo = command.InstanceInfo;
|
||||||
var launchRecipe = command.LaunchRecipe;
|
var launchRecipe = command.LaunchRecipe;
|
||||||
var stopRecipe = command.StopRecipe;
|
|
||||||
|
|
||||||
if (instances.TryGetValue(instanceGuid, out var instance)) {
|
if (instances.TryGetValue(instanceGuid, out var instance)) {
|
||||||
instances[instanceGuid] = instance with {
|
instances[instanceGuid] = instance with {
|
||||||
Info = instanceInfo,
|
Info = instanceInfo,
|
||||||
LaunchRecipe = launchRecipe,
|
LaunchRecipe = launchRecipe,
|
||||||
StopRecipe = stopRecipe,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.Information("Reconfigured instance \"{Name}\" (GUID {Guid}).", instanceInfo.InstanceName, instanceGuid);
|
Logger.Information("Reconfigured instance \"{Name}\" (GUID {Guid}).", instanceInfo.InstanceName, instanceGuid);
|
||||||
@@ -90,7 +88,7 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
var instanceFolder = Path.Combine(agentFolders.InstancesFolderPath, instanceGuid.ToString());
|
var instanceFolder = Path.Combine(agentFolders.InstancesFolderPath, instanceGuid.ToString());
|
||||||
var instanceProperties = new InstanceProperties(instanceGuid, instanceFolder);
|
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 Instance(Context.ActorOf(InstanceActor.Factory(instanceInit), "Instance-" + instanceGuid), instanceInfo, instanceProperties, launchRecipe, stopRecipe);
|
instances[instanceGuid] = instance = new Instance(Context.ActorOf(InstanceActor.Factory(instanceInit), "Instance-" + instanceGuid), instanceInfo, instanceProperties, launchRecipe);
|
||||||
|
|
||||||
Logger.Information("Created instance \"{Name}\" (GUID {Guid}).", instanceInfo.InstanceName, instanceGuid);
|
Logger.Information("Created instance \"{Name}\" (GUID {Guid}).", instanceInfo.InstanceName, instanceGuid);
|
||||||
|
|
||||||
@@ -161,7 +159,7 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
instanceInfo.Actor.Tell(new InstanceActor.StopInstanceCommand(command.StopRecipe));
|
instanceInfo.Actor.Tell(new InstanceActor.StopInstanceCommand(command.StopStrategy));
|
||||||
return StopInstanceResult.StopInitiated;
|
return StopInstanceResult.StopInitiated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +181,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(instance.StopRecipe))));
|
await Task.WhenAll(instances.Values.Select(static instance => instance.Actor.Stop(new InstanceActor.ShutdownCommand())));
|
||||||
instances.Clear();
|
instances.Clear();
|
||||||
|
|
||||||
shutdownCancellationTokenSource.Dispose();
|
shutdownCancellationTokenSource.Dispose();
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ sealed class InstanceLauncher(
|
|||||||
InstanceProperties instanceProperties,
|
InstanceProperties instanceProperties,
|
||||||
InstanceLaunchRecipe launchRecipe
|
InstanceLaunchRecipe launchRecipe
|
||||||
) {
|
) {
|
||||||
public IInstanceValueResolver ValueResolver => valueResolver;
|
|
||||||
|
|
||||||
public async Task<InstanceLaunchResult> Launch(ILogger logger, Action<IInstanceStatus?> reportStatus, CancellationToken cancellationToken) {
|
public async Task<InstanceLaunchResult> Launch(ILogger logger, Action<IInstanceStatus?> reportStatus, CancellationToken cancellationToken) {
|
||||||
string? executablePath = launchRecipe.Executable.Resolve(pathResolver);
|
string? executablePath = launchRecipe.Executable.Resolve(pathResolver);
|
||||||
if (executablePath == null) {
|
if (executablePath == null) {
|
||||||
@@ -111,8 +109,6 @@ sealed class InstanceLauncher(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reportStatus(InstanceStatus.Downloading(null));
|
|
||||||
|
|
||||||
if (await downloadManager.DownloadAndGetPath(downloadInfo, filePath, OnDownloadProgress, cancellationToken) == null) {
|
if (await downloadManager.DownloadAndGetPath(downloadInfo, filePath, OnDownloadProgress, cancellationToken) == null) {
|
||||||
logger.Error("Could not download file: {Url}", downloadInfo.Url);
|
logger.Error("Could not download file: {Url}", downloadInfo.Url);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -27,15 +27,6 @@ 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;
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ 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;
|
||||||
|
|||||||
@@ -1,50 +1,37 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Phantom.Common.Data.Agent.Instance;
|
using Phantom.Agent.Services.Games;
|
||||||
using Phantom.Common.Data.Agent.Instance.Stop;
|
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
using Serilog;
|
using Phantom.Common.Data.Minecraft;
|
||||||
|
|
||||||
namespace Phantom.Agent.Services.Instances.State;
|
namespace Phantom.Agent.Services.Instances.State;
|
||||||
|
|
||||||
static class InstanceStopProcedure {
|
static class InstanceStopProcedure {
|
||||||
public static async Task<bool> Run(InstanceContext context, InstanceStopRecipe stopRecipe, InstanceRunningState runningState, Action<IInstanceStatus> reportStatus, CancellationToken cancellationToken) {
|
private static readonly ushort[] Stops = [60, 30, 10, 5, 4, 3, 2, 1, 0];
|
||||||
var logger = context.Logger;
|
|
||||||
|
public static async Task<bool> Run(InstanceContext context, MinecraftStopStrategy stopStrategy, InstanceRunningState runningState, Action<IInstanceStatus> reportStatus, CancellationToken cancellationToken) {
|
||||||
var stopCommand = stopRecipe.StopCommand.Resolve(runningState.ValueResolver);
|
var process = runningState.Process;
|
||||||
if (stopCommand == null) {
|
|
||||||
logger.Error("Could not resolve stop command");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
runningState.IsStopping = true;
|
runningState.IsStopping = true;
|
||||||
|
|
||||||
bool continueStopping = false;
|
var seconds = stopStrategy.Seconds;
|
||||||
try {
|
if (seconds > 0) {
|
||||||
var stepExecutor = new StepExecutor(logger, runningState.ValueResolver, runningState.Process, cancellationToken);
|
try {
|
||||||
continueStopping = await RunPreparationSteps(context, stopRecipe, stepExecutor);
|
await CountDownWithAnnouncements(context, process, seconds, cancellationToken);
|
||||||
} finally {
|
} catch (OperationCanceledException) {
|
||||||
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 (!runningState.Process.HasEnded) {
|
if (!process.HasEnded) {
|
||||||
logger.Information("Sending stop command...");
|
context.Logger.Information("Session stopping now.");
|
||||||
await TrySendStopCommand(context, runningState.Process, stopCommand);
|
await DoStop(context, process);
|
||||||
|
|
||||||
logger.Information("Waiting for session to end...");
|
|
||||||
await WaitForSessionToEnd(context, runningState.Process);
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
logger.Information("Session stopped.");
|
context.Logger.Information("Session stopped.");
|
||||||
reportStatus(InstanceStatus.NotRunning);
|
reportStatus(InstanceStatus.NotRunning);
|
||||||
context.ReportEvent(InstanceEvent.Stopped);
|
context.ReportEvent(InstanceEvent.Stopped);
|
||||||
}
|
}
|
||||||
@@ -52,51 +39,39 @@ static class InstanceStopProcedure {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<bool> RunPreparationSteps(InstanceContext context, InstanceStopRecipe stopRecipe, StepExecutor executor) {
|
private static async Task CountDownWithAnnouncements(InstanceContext context, InstanceProcess process, ushort seconds, CancellationToken cancellationToken) {
|
||||||
var steps = stopRecipe.Preparation;
|
context.Logger.Information("Session stopping in {Seconds} seconds.", seconds);
|
||||||
|
|
||||||
for (int stepIndex = 0; stepIndex < steps.Length; stepIndex++) {
|
foreach (var stop in Stops) {
|
||||||
var step = steps[stepIndex];
|
// TODO change to event-based cancellation
|
||||||
try {
|
if (process.HasEnded) {
|
||||||
if (await step.Run(executor)) {
|
return;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
if (seconds > stop) {
|
||||||
}
|
await process.SendCommand(GetCountDownAnnouncementCommand(seconds), cancellationToken);
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(seconds - stop), cancellationToken);
|
||||||
return true;
|
seconds = stop;
|
||||||
}
|
|
||||||
|
|
||||||
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 async Task TrySendStopCommand(InstanceContext context, InstanceProcess process, string command) {
|
private static string GetCountDownAnnouncementCommand(ushort seconds) {
|
||||||
|
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(command, timeout.Token);
|
await process.SendCommand(MinecraftCommand.Stop, 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) {
|
||||||
|
|||||||
@@ -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.Info, message.LaunchRecipe, message.LaunchNow, message.StopRecipe, AlwaysReportStatus: false));
|
return await agent.InstanceManager.Request(new InstanceManagerActor.ConfigureInstanceCommand(message.InstanceGuid, message.Info, message.LaunchRecipe, message.LaunchNow, 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.StopRecipe));
|
return await agent.InstanceManager.Request(new InstanceManagerActor.StopInstanceCommand(message.InstanceGuid, message.StopStrategy));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Result<SendCommandToInstanceResult, InstanceActionFailure>> HandleSendCommandToInstance(SendCommandToInstanceMessage message) {
|
private async Task<Result<SendCommandToInstanceResult, InstanceActionFailure>> HandleSendCommandToInstance(SendCommandToInstanceMessage message) {
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Phantom.Common.Data.Agent.Instance.Stop;
|
|
||||||
|
|
||||||
public interface IInstanceStopStepExecutor<TResult> {
|
|
||||||
Task<TResult> Wait(TimeSpan duration);
|
|
||||||
Task<TResult> SendToStandardInput(IInstanceValue line);
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
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
|
|
||||||
);
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Web.Java;
|
namespace Phantom.Common.Data.Web.Minecraft;
|
||||||
|
|
||||||
public static class JvmArgumentsHelper {
|
public static class JvmArgumentsHelper {
|
||||||
public static ImmutableArray<string> Split(string arguments) {
|
public static ImmutableArray<string> Split(string arguments) {
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
using Phantom.Common.Data.Agent.Instance;
|
using Phantom.Common.Data.Agent.Instance;
|
||||||
using Phantom.Common.Data.Agent.Instance.Launch;
|
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;
|
||||||
|
|
||||||
@@ -13,6 +12,5 @@ public sealed partial record ConfigureInstanceMessage(
|
|||||||
[property: MemoryPackOrder(0)] Guid InstanceGuid,
|
[property: MemoryPackOrder(0)] Guid InstanceGuid,
|
||||||
[property: MemoryPackOrder(1)] InstanceInfo Info,
|
[property: MemoryPackOrder(1)] InstanceInfo Info,
|
||||||
[property: MemoryPackOrder(2)] InstanceLaunchRecipe? LaunchRecipe,
|
[property: MemoryPackOrder(2)] InstanceLaunchRecipe? LaunchRecipe,
|
||||||
[property: MemoryPackOrder(3)] bool LaunchNow,
|
[property: MemoryPackOrder(3)] bool LaunchNow = false
|
||||||
[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.Agent.Instance.Stop;
|
using Phantom.Common.Data.Minecraft;
|
||||||
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)] InstanceStopRecipe StopRecipe
|
[property: MemoryPackOrder(1)] MinecraftStopStrategy StopStrategy
|
||||||
) : IMessageToAgent, ICanReply<Result<StopInstanceResult, InstanceActionFailure>>;
|
) : IMessageToAgent, ICanReply<Result<StopInstanceResult, InstanceActionFailure>>;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
|
using Phantom.Common.Data.Minecraft;
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
using Phantom.Common.Data.Web.Users;
|
using Phantom.Common.Data.Web.Users;
|
||||||
using Phantom.Utils.Actor;
|
using Phantom.Utils.Actor;
|
||||||
@@ -12,5 +13,5 @@ public sealed partial record StopInstanceMessage(
|
|||||||
[property: MemoryPackOrder(0)] ImmutableArray<byte> AuthToken,
|
[property: MemoryPackOrder(0)] ImmutableArray<byte> AuthToken,
|
||||||
[property: MemoryPackOrder(1)] Guid AgentGuid,
|
[property: MemoryPackOrder(1)] Guid AgentGuid,
|
||||||
[property: MemoryPackOrder(2)] Guid InstanceGuid,
|
[property: MemoryPackOrder(2)] Guid InstanceGuid,
|
||||||
[property: MemoryPackOrder(3)] ushort AfterSeconds
|
[property: MemoryPackOrder(3)] MinecraftStopStrategy StopStrategy
|
||||||
) : IMessageToController, ICanReply<Result<StopInstanceResult, UserInstanceActionFailure>>;
|
) : IMessageToController, ICanReply<Result<StopInstanceResult, UserInstanceActionFailure>>;
|
||||||
|
|||||||
@@ -87,8 +87,10 @@ sealed partial class AuditLogRepository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InstanceStopped(Guid instanceGuid) {
|
public void InstanceStopped(Guid instanceGuid, int stopInSeconds) {
|
||||||
AddItem(AuditLogEventType.InstanceStopped, instanceGuid.ToString());
|
AddItem(AuditLogEventType.InstanceStopped, instanceGuid.ToString(), new Dictionary<string, object?> {
|
||||||
|
{ "stop_in_seconds", stopInSeconds.ToString() },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
using System.Collections.Immutable;
|
|
||||||
using Phantom.Common.Data.Agent.Instance;
|
|
||||||
using Phantom.Common.Data.Agent.Instance.Stop;
|
|
||||||
|
|
||||||
namespace Phantom.Controller.Minecraft;
|
|
||||||
|
|
||||||
public sealed partial class MinecraftInstanceRecipes {
|
|
||||||
private static readonly ushort[] Stops = [60, 30, 10, 5, 4, 3, 2, 1];
|
|
||||||
private static readonly IInstanceValue StopCommand = new InstanceValues.Text("stop");
|
|
||||||
|
|
||||||
private static InstanceValues.Text SayCommand(string message) {
|
|
||||||
return new InstanceValues.Text($"say {message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static InstanceValues.Text SayCountDownAnnouncementCommand(ushort seconds) {
|
|
||||||
return SayCommand("Server shutting down in " + seconds + (seconds == 1 ? " second." : " seconds."));
|
|
||||||
}
|
|
||||||
|
|
||||||
public InstanceStopRecipe Stop(ushort afterSeconds) {
|
|
||||||
var steps = ImmutableArray.CreateBuilder<IInstanceStopStep>();
|
|
||||||
|
|
||||||
if (afterSeconds > 0) {
|
|
||||||
steps.Add(new InstanceStopStep.SendToStandardInput(SayCountDownAnnouncementCommand(afterSeconds)));
|
|
||||||
|
|
||||||
int remainingSeconds = afterSeconds;
|
|
||||||
|
|
||||||
for (int stopIndex = Array.FindIndex(Stops, stop => stop < afterSeconds); stopIndex != -1 && stopIndex < Stops.Length; stopIndex++) {
|
|
||||||
ushort currentStop = Stops[stopIndex];
|
|
||||||
|
|
||||||
steps.Add(new InstanceStopStep.Wait(TimeSpan.FromSeconds(remainingSeconds - currentStop)));
|
|
||||||
steps.Add(new InstanceStopStep.SendToStandardInput(SayCountDownAnnouncementCommand(currentStop)));
|
|
||||||
|
|
||||||
remainingSeconds = currentStop;
|
|
||||||
}
|
|
||||||
|
|
||||||
steps.Add(new InstanceStopStep.Wait(TimeSpan.FromSeconds(remainingSeconds)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new InstanceStopRecipe(steps.ToImmutable(), StopCommand);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,8 +10,12 @@ using Phantom.Utils.Collections;
|
|||||||
|
|
||||||
namespace Phantom.Controller.Minecraft;
|
namespace Phantom.Controller.Minecraft;
|
||||||
|
|
||||||
public sealed partial class MinecraftInstanceRecipes(MinecraftVersions minecraftVersions) {
|
public sealed partial class MinecraftLaunchRecipes(MinecraftVersions minecraftVersions) {
|
||||||
public async Task<Result<InstanceLaunchRecipe, MinecraftLaunchRecipeCreationFailReason>> Launch(InstanceConfiguration configuration, CancellationToken cancellationToken) {
|
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;
|
string minecraftVersion = configuration.MinecraftVersion;
|
||||||
|
|
||||||
var serverExecutableInfo = await minecraftVersions.GetServerExecutableInfo(minecraftVersion, cancellationToken);
|
var serverExecutableInfo = await minecraftVersions.GetServerExecutableInfo(minecraftVersion, cancellationToken);
|
||||||
@@ -64,10 +68,6 @@ public sealed partial class MinecraftInstanceRecipes(MinecraftVersions minecraft
|
|||||||
return SanitizePathRegex().IsMatch(path) ? SanitizePathRegex().Replace(path, "_") : path;
|
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) {
|
private static ImmutableDictionary<string, string> ServerProperties(InstanceConfiguration configuration) {
|
||||||
return ImmutableDictionary.From([
|
return ImmutableDictionary.From([
|
||||||
("server-port", configuration.ServerPort.ToString()),
|
("server-port", configuration.ServerPort.ToString()),
|
||||||
@@ -5,10 +5,11 @@ using Phantom.Common.Data;
|
|||||||
using Phantom.Common.Data.Agent.Instance.Launch;
|
using Phantom.Common.Data.Agent.Instance.Launch;
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
using Phantom.Common.Data.Java;
|
using Phantom.Common.Data.Java;
|
||||||
|
using Phantom.Common.Data.Minecraft;
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
using Phantom.Common.Data.Web.Agent;
|
using Phantom.Common.Data.Web.Agent;
|
||||||
using Phantom.Common.Data.Web.Instance;
|
using Phantom.Common.Data.Web.Instance;
|
||||||
using Phantom.Common.Data.Web.Java;
|
using Phantom.Common.Data.Web.Minecraft;
|
||||||
using Phantom.Common.Messages.Agent;
|
using Phantom.Common.Messages.Agent;
|
||||||
using Phantom.Common.Messages.Agent.ToAgent;
|
using Phantom.Common.Messages.Agent.ToAgent;
|
||||||
using Phantom.Controller.Database;
|
using Phantom.Controller.Database;
|
||||||
@@ -40,7 +41,7 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
|
|||||||
AgentRuntimeInfo AgentRuntimeInfo,
|
AgentRuntimeInfo AgentRuntimeInfo,
|
||||||
AgentConnectionKeys AgentConnectionKeys,
|
AgentConnectionKeys AgentConnectionKeys,
|
||||||
ControllerState ControllerState,
|
ControllerState ControllerState,
|
||||||
MinecraftInstanceRecipes MinecraftInstanceRecipes,
|
MinecraftLaunchRecipes LaunchRecipes,
|
||||||
IDbContextProvider DbProvider,
|
IDbContextProvider DbProvider,
|
||||||
CancellationToken CancellationToken
|
CancellationToken CancellationToken
|
||||||
);
|
);
|
||||||
@@ -53,7 +54,7 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
|
|||||||
|
|
||||||
private readonly AgentConnectionKeys agentConnectionKeys;
|
private readonly AgentConnectionKeys agentConnectionKeys;
|
||||||
private readonly ControllerState controllerState;
|
private readonly ControllerState controllerState;
|
||||||
private readonly MinecraftInstanceRecipes minecraftInstanceRecipes;
|
private readonly MinecraftLaunchRecipes launchRecipes;
|
||||||
private readonly IDbContextProvider dbProvider;
|
private readonly IDbContextProvider dbProvider;
|
||||||
private readonly CancellationToken cancellationToken;
|
private readonly CancellationToken cancellationToken;
|
||||||
|
|
||||||
@@ -94,7 +95,7 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
|
|||||||
private AgentActor(Init init) {
|
private AgentActor(Init init) {
|
||||||
this.agentConnectionKeys = init.AgentConnectionKeys;
|
this.agentConnectionKeys = init.AgentConnectionKeys;
|
||||||
this.controllerState = init.ControllerState;
|
this.controllerState = init.ControllerState;
|
||||||
this.minecraftInstanceRecipes = init.MinecraftInstanceRecipes;
|
this.launchRecipes = init.LaunchRecipes;
|
||||||
this.dbProvider = init.DbProvider;
|
this.dbProvider = init.DbProvider;
|
||||||
this.cancellationToken = init.CancellationToken;
|
this.cancellationToken = init.CancellationToken;
|
||||||
|
|
||||||
@@ -189,9 +190,8 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
|
|||||||
var configurationMessages = ImmutableArray.CreateBuilder<ConfigureInstanceMessage>();
|
var configurationMessages = ImmutableArray.CreateBuilder<ConfigureInstanceMessage>();
|
||||||
|
|
||||||
foreach (var (instanceGuid, instanceConfiguration, _, _, launchAutomatically) in instanceDataByGuid.Values.ToImmutableArray()) {
|
foreach (var (instanceGuid, instanceConfiguration, _, _, launchAutomatically) in instanceDataByGuid.Values.ToImmutableArray()) {
|
||||||
var launchRecipe = await minecraftInstanceRecipes.Launch(instanceConfiguration, cancellationToken);
|
var launchRecipe = await launchRecipes.Create(instanceConfiguration, cancellationToken);
|
||||||
var stopRecipe = minecraftInstanceRecipes.Stop(0);
|
var configurationMessage = new ConfigureInstanceMessage(instanceGuid, instanceConfiguration.AsInfo, launchRecipe.OrElse(null), launchAutomatically);
|
||||||
var configurationMessage = new ConfigureInstanceMessage(instanceGuid, instanceConfiguration.AsInfo, launchRecipe.OrElse(null), launchAutomatically, stopRecipe);
|
|
||||||
configurationMessages.Add(configurationMessage);
|
configurationMessages.Add(configurationMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +226,7 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
|
|||||||
|
|
||||||
public sealed record LaunchInstanceCommand(Guid LoggedInUserGuid, Guid InstanceGuid) : ICommand, ICanReply<Result<LaunchInstanceResult, InstanceActionFailure>>;
|
public sealed record LaunchInstanceCommand(Guid LoggedInUserGuid, Guid InstanceGuid) : ICommand, ICanReply<Result<LaunchInstanceResult, InstanceActionFailure>>;
|
||||||
|
|
||||||
public sealed record StopInstanceCommand(Guid LoggedInUserGuid, Guid InstanceGuid, ushort AfterSeconds) : ICommand, ICanReply<Result<StopInstanceResult, InstanceActionFailure>>;
|
public sealed record StopInstanceCommand(Guid LoggedInUserGuid, Guid InstanceGuid, MinecraftStopStrategy StopStrategy) : ICommand, ICanReply<Result<StopInstanceResult, InstanceActionFailure>>;
|
||||||
|
|
||||||
public sealed record SendCommandToInstanceCommand(Guid LoggedInUserGuid, Guid InstanceGuid, string Command) : ICommand, ICanReply<Result<SendCommandToInstanceResult, InstanceActionFailure>>;
|
public sealed record SendCommandToInstanceCommand(Guid LoggedInUserGuid, Guid InstanceGuid, string Command) : ICommand, ICanReply<Result<SendCommandToInstanceResult, InstanceActionFailure>>;
|
||||||
|
|
||||||
@@ -341,7 +341,7 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
|
|||||||
return Task.FromResult<Result<CreateOrUpdateInstanceResult, InstanceActionFailure>>(CreateOrUpdateInstanceResult.InstanceMemoryMustNotBeZero);
|
return Task.FromResult<Result<CreateOrUpdateInstanceResult, InstanceActionFailure>>(CreateOrUpdateInstanceResult.InstanceMemoryMustNotBeZero);
|
||||||
}
|
}
|
||||||
|
|
||||||
return minecraftInstanceRecipes.Launch(instanceConfiguration, cancellationToken)
|
return launchRecipes.Create(instanceConfiguration, cancellationToken)
|
||||||
.ContinueOnActor(CreateOrUpdateInstance1, command)
|
.ContinueOnActor(CreateOrUpdateInstance1, command)
|
||||||
.Unwrap();
|
.Unwrap();
|
||||||
}
|
}
|
||||||
@@ -362,8 +362,7 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
|
|||||||
instanceActorRef = CreateNewInstance(Instance.Offline(instanceGuid, instanceConfiguration));
|
instanceActorRef = CreateNewInstance(Instance.Offline(instanceGuid, instanceConfiguration));
|
||||||
}
|
}
|
||||||
|
|
||||||
var stopRecipe = minecraftInstanceRecipes.Stop(afterSeconds: 0);
|
var configureInstanceCommand = new InstanceActor.ConfigureInstanceCommand(command.LoggedInUserGuid, instanceGuid, instanceConfiguration, launchRecipe.Value, isCreatingInstance);
|
||||||
var configureInstanceCommand = new InstanceActor.ConfigureInstanceCommand(command.LoggedInUserGuid, instanceGuid, instanceConfiguration, launchRecipe.Value, stopRecipe, isCreatingInstance);
|
|
||||||
|
|
||||||
return instanceActorRef.Request(configureInstanceCommand, cancellationToken)
|
return instanceActorRef.Request(configureInstanceCommand, cancellationToken)
|
||||||
.ContinueOnActor(CreateOrUpdateInstance2, configureInstanceCommand);
|
.ContinueOnActor(CreateOrUpdateInstance2, configureInstanceCommand);
|
||||||
@@ -404,8 +403,7 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Task<Result<StopInstanceResult, InstanceActionFailure>> StopInstance(StopInstanceCommand command) {
|
private Task<Result<StopInstanceResult, InstanceActionFailure>> StopInstance(StopInstanceCommand command) {
|
||||||
var stopRecipe = minecraftInstanceRecipes.Stop(command.AfterSeconds);
|
return RequestInstance<InstanceActor.StopInstanceCommand, StopInstanceResult>(command.InstanceGuid, new InstanceActor.StopInstanceCommand(command.LoggedInUserGuid, command.StopStrategy));
|
||||||
return RequestInstance<InstanceActor.StopInstanceCommand, StopInstanceResult>(command.InstanceGuid, new InstanceActor.StopInstanceCommand(command.LoggedInUserGuid, stopRecipe));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task<Result<SendCommandToInstanceResult, InstanceActionFailure>> SendMinecraftCommand(SendCommandToInstanceCommand command) {
|
private Task<Result<SendCommandToInstanceResult, InstanceActionFailure>> SendMinecraftCommand(SendCommandToInstanceCommand command) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ sealed class AgentManager(
|
|||||||
IActorRefFactory actorSystem,
|
IActorRefFactory actorSystem,
|
||||||
AgentConnectionKeys agentConnectionKeys,
|
AgentConnectionKeys agentConnectionKeys,
|
||||||
ControllerState controllerState,
|
ControllerState controllerState,
|
||||||
MinecraftInstanceRecipes minecraftInstanceRecipes,
|
MinecraftLaunchRecipes launchRecipes,
|
||||||
IDbContextProvider dbProvider,
|
IDbContextProvider dbProvider,
|
||||||
CancellationToken cancellationToken
|
CancellationToken cancellationToken
|
||||||
) {
|
) {
|
||||||
@@ -42,7 +42,7 @@ sealed class AgentManager(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private bool AddAgent(Guid? loggedInUserGuid, Guid agentGuid, AgentConfiguration configuration, AuthSecret authSecret, AgentRuntimeInfo runtimeInfo) {
|
private bool AddAgent(Guid? loggedInUserGuid, Guid agentGuid, AgentConfiguration configuration, AuthSecret authSecret, AgentRuntimeInfo runtimeInfo) {
|
||||||
var init = new AgentActor.Init(loggedInUserGuid, agentGuid, configuration, authSecret, runtimeInfo, agentConnectionKeys, controllerState, minecraftInstanceRecipes, dbProvider, cancellationToken);
|
var init = new AgentActor.Init(loggedInUserGuid, agentGuid, configuration, authSecret, runtimeInfo, agentConnectionKeys, controllerState, launchRecipes, dbProvider, cancellationToken);
|
||||||
var name = "Agent:" + agentGuid;
|
var name = "Agent:" + agentGuid;
|
||||||
return agentsByAgentGuid.TryAdd(agentGuid, actorSystem.ActorOf(AgentActor.Factory(init), name));
|
return agentsByAgentGuid.TryAdd(agentGuid, actorSystem.ActorOf(AgentActor.Factory(init), name));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public sealed class ControllerServices : IDisposable {
|
|||||||
|
|
||||||
private ControllerState ControllerState { get; }
|
private ControllerState ControllerState { get; }
|
||||||
private MinecraftVersions MinecraftVersions { get; }
|
private MinecraftVersions MinecraftVersions { get; }
|
||||||
private MinecraftInstanceRecipes MinecraftInstanceRecipes { get; }
|
private MinecraftLaunchRecipes LaunchRecipes { get; }
|
||||||
|
|
||||||
private AuthenticatedUserCache AuthenticatedUserCache { get; }
|
private AuthenticatedUserCache AuthenticatedUserCache { get; }
|
||||||
private UserManager UserManager { get; }
|
private UserManager UserManager { get; }
|
||||||
@@ -51,7 +51,7 @@ public sealed class ControllerServices : IDisposable {
|
|||||||
|
|
||||||
this.ControllerState = new ControllerState();
|
this.ControllerState = new ControllerState();
|
||||||
this.MinecraftVersions = new MinecraftVersions();
|
this.MinecraftVersions = new MinecraftVersions();
|
||||||
this.MinecraftInstanceRecipes = new MinecraftInstanceRecipes(MinecraftVersions);
|
this.LaunchRecipes = new MinecraftLaunchRecipes(MinecraftVersions);
|
||||||
|
|
||||||
this.AuthenticatedUserCache = new AuthenticatedUserCache();
|
this.AuthenticatedUserCache = new AuthenticatedUserCache();
|
||||||
this.UserManager = new UserManager(AuthenticatedUserCache, ControllerState, dbProvider);
|
this.UserManager = new UserManager(AuthenticatedUserCache, ControllerState, dbProvider);
|
||||||
@@ -60,7 +60,7 @@ public sealed class ControllerServices : IDisposable {
|
|||||||
this.UserLoginManager = new UserLoginManager(AuthenticatedUserCache, dbProvider);
|
this.UserLoginManager = new UserLoginManager(AuthenticatedUserCache, dbProvider);
|
||||||
this.PermissionManager = new PermissionManager(dbProvider);
|
this.PermissionManager = new PermissionManager(dbProvider);
|
||||||
|
|
||||||
this.AgentManager = new AgentManager(ActorSystem, new AgentConnectionKeys(agentCertificateThumbprint), ControllerState, MinecraftInstanceRecipes, dbProvider, cancellationToken);
|
this.AgentManager = new AgentManager(ActorSystem, new AgentConnectionKeys(agentCertificateThumbprint), ControllerState, LaunchRecipes, dbProvider, cancellationToken);
|
||||||
this.InstanceLogManager = new InstanceLogManager();
|
this.InstanceLogManager = new InstanceLogManager();
|
||||||
|
|
||||||
this.AuditLogManager = new AuditLogManager(dbProvider);
|
this.AuditLogManager = new AuditLogManager(dbProvider);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
using Phantom.Common.Data.Agent.Instance.Launch;
|
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.Common.Data.Web.Instance;
|
using Phantom.Common.Data.Web.Instance;
|
||||||
using Phantom.Common.Messages.Agent;
|
using Phantom.Common.Messages.Agent;
|
||||||
@@ -71,11 +71,11 @@ sealed class InstanceActor : ReceiveActor<InstanceActor.ICommand> {
|
|||||||
|
|
||||||
public sealed record SetPlayerCountsCommand(InstancePlayerCounts? PlayerCounts) : ICommand;
|
public sealed record SetPlayerCountsCommand(InstancePlayerCounts? PlayerCounts) : ICommand;
|
||||||
|
|
||||||
public sealed record ConfigureInstanceCommand(Guid AuditLogUserGuid, Guid InstanceGuid, InstanceConfiguration Configuration, InstanceLaunchRecipe LaunchRecipe, InstanceStopRecipe StopRecipe, bool IsCreatingInstance) : ICommand, ICanReply<Result<ConfigureInstanceResult, InstanceActionFailure>>;
|
public sealed record ConfigureInstanceCommand(Guid AuditLogUserGuid, Guid InstanceGuid, InstanceConfiguration Configuration, InstanceLaunchRecipe LaunchRecipe, bool IsCreatingInstance) : ICommand, ICanReply<Result<ConfigureInstanceResult, InstanceActionFailure>>;
|
||||||
|
|
||||||
public sealed record LaunchInstanceCommand(Guid AuditLogUserGuid) : ICommand, ICanReply<Result<LaunchInstanceResult, InstanceActionFailure>>;
|
public sealed record LaunchInstanceCommand(Guid AuditLogUserGuid) : ICommand, ICanReply<Result<LaunchInstanceResult, InstanceActionFailure>>;
|
||||||
|
|
||||||
public sealed record StopInstanceCommand(Guid AuditLogUserGuid, InstanceStopRecipe StopRecipe) : ICommand, ICanReply<Result<StopInstanceResult, InstanceActionFailure>>;
|
public sealed record StopInstanceCommand(Guid AuditLogUserGuid, MinecraftStopStrategy StopStrategy) : ICommand, ICanReply<Result<StopInstanceResult, InstanceActionFailure>>;
|
||||||
|
|
||||||
public sealed record SendCommandToInstanceCommand(Guid AuditLogUserGuid, string Command) : ICommand, ICanReply<Result<SendCommandToInstanceResult, InstanceActionFailure>>;
|
public sealed record SendCommandToInstanceCommand(Guid AuditLogUserGuid, string Command) : ICommand, ICanReply<Result<SendCommandToInstanceResult, InstanceActionFailure>>;
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ sealed class InstanceActor : ReceiveActor<InstanceActor.ICommand> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Result<ConfigureInstanceResult, InstanceActionFailure>> ConfigureInstance(ConfigureInstanceCommand command) {
|
private async Task<Result<ConfigureInstanceResult, InstanceActionFailure>> ConfigureInstance(ConfigureInstanceCommand command) {
|
||||||
var message = new ConfigureInstanceMessage(command.InstanceGuid, command.Configuration.AsInfo, command.LaunchRecipe, LaunchNow: false, command.StopRecipe);
|
var message = new ConfigureInstanceMessage(command.InstanceGuid, command.Configuration.AsInfo, command.LaunchRecipe);
|
||||||
var result = await SendInstanceActionMessage<ConfigureInstanceMessage, ConfigureInstanceResult>(message);
|
var result = await SendInstanceActionMessage<ConfigureInstanceMessage, ConfigureInstanceResult>(message);
|
||||||
|
|
||||||
if (result.Is(ConfigureInstanceResult.Success)) {
|
if (result.Is(ConfigureInstanceResult.Success)) {
|
||||||
@@ -127,12 +127,12 @@ sealed class InstanceActor : ReceiveActor<InstanceActor.ICommand> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Result<StopInstanceResult, InstanceActionFailure>> StopInstance(StopInstanceCommand command) {
|
private async Task<Result<StopInstanceResult, InstanceActionFailure>> StopInstance(StopInstanceCommand command) {
|
||||||
var message = new StopInstanceMessage(instanceGuid, command.StopRecipe);
|
var message = new StopInstanceMessage(instanceGuid, command.StopStrategy);
|
||||||
var result = await SendInstanceActionMessage<StopInstanceMessage, StopInstanceResult>(message);
|
var result = await SendInstanceActionMessage<StopInstanceMessage, StopInstanceResult>(message);
|
||||||
|
|
||||||
if (result.Is(StopInstanceResult.StopInitiated)) {
|
if (result.Is(StopInstanceResult.StopInitiated)) {
|
||||||
SetLaunchAutomatically(false);
|
SetLaunchAutomatically(false);
|
||||||
databaseStorageActor.Tell(new InstanceDatabaseStorageActor.StoreInstanceStoppedCommand(command.AuditLogUserGuid));
|
databaseStorageActor.Tell(new InstanceDatabaseStorageActor.StoreInstanceStoppedCommand(command.AuditLogUserGuid, command.StopStrategy));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Phantom.Common.Data.Web.Instance;
|
using Phantom.Common.Data.Minecraft;
|
||||||
using Phantom.Common.Data.Web.Java;
|
using Phantom.Common.Data.Web.Instance;
|
||||||
|
using Phantom.Common.Data.Web.Minecraft;
|
||||||
using Phantom.Controller.Database;
|
using Phantom.Controller.Database;
|
||||||
using Phantom.Controller.Database.Entities;
|
using Phantom.Controller.Database.Entities;
|
||||||
using Phantom.Controller.Database.Repositories;
|
using Phantom.Controller.Database.Repositories;
|
||||||
@@ -43,7 +44,7 @@ sealed class InstanceDatabaseStorageActor : ReceiveActor<InstanceDatabaseStorage
|
|||||||
|
|
||||||
public sealed record StoreInstanceLaunchedCommand(Guid AuditLogUserGuid) : ICommand;
|
public sealed record StoreInstanceLaunchedCommand(Guid AuditLogUserGuid) : ICommand;
|
||||||
|
|
||||||
public sealed record StoreInstanceStoppedCommand(Guid AuditLogUserGuid) : ICommand;
|
public sealed record StoreInstanceStoppedCommand(Guid AuditLogUserGuid, MinecraftStopStrategy StopStrategy) : ICommand;
|
||||||
|
|
||||||
public sealed record StoreInstanceCommandSentCommand(Guid AuditLogUserGuid, string Command) : ICommand;
|
public sealed record StoreInstanceCommandSentCommand(Guid AuditLogUserGuid, string Command) : ICommand;
|
||||||
|
|
||||||
@@ -99,7 +100,7 @@ sealed class InstanceDatabaseStorageActor : ReceiveActor<InstanceDatabaseStorage
|
|||||||
}
|
}
|
||||||
|
|
||||||
var auditLogWriter = new AuditLogRepository(db).Writer(command.AuditLogUserGuid);
|
var auditLogWriter = new AuditLogRepository(db).Writer(command.AuditLogUserGuid);
|
||||||
auditLogWriter.InstanceStopped(instanceGuid);
|
auditLogWriter.InstanceStopped(instanceGuid, command.StopStrategy.Seconds);
|
||||||
|
|
||||||
await db.Ctx.SaveChangesAsync(cancellationToken);
|
await db.Ctx.SaveChangesAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ sealed class WebMessageHandlerActor : ReceiveActor<IMessageToController> {
|
|||||||
userLoginManager.GetLoggedInUser(message.AuthToken),
|
userLoginManager.GetLoggedInUser(message.AuthToken),
|
||||||
Permission.ControlInstances,
|
Permission.ControlInstances,
|
||||||
message.AgentGuid,
|
message.AgentGuid,
|
||||||
loggedInUserGuid => new AgentActor.StopInstanceCommand(loggedInUserGuid, message.InstanceGuid, message.AfterSeconds)
|
loggedInUserGuid => new AgentActor.StopInstanceCommand(loggedInUserGuid, message.InstanceGuid, message.StopStrategy)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
21
Utils/Phantom.Utils/Net/HttpHeadersExtensions.cs
Normal file
21
Utils/Phantom.Utils/Net/HttpHeadersExtensions.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System.Net.Http.Headers;
|
||||||
|
using Phantom.Utils.IO;
|
||||||
|
|
||||||
|
namespace Phantom.Utils.Net;
|
||||||
|
|
||||||
|
public static class HttpHeadersExtensions {
|
||||||
|
private const string ContentLength = "Content-Length";
|
||||||
|
|
||||||
|
extension(HttpResponseHeaders headers) {
|
||||||
|
public FileSize? ContentLength {
|
||||||
|
get {
|
||||||
|
if (!headers.TryGetValues(ContentLength, out var values)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
string? value = values.FirstOrDefault();
|
||||||
|
return value != null && ulong.TryParse(value, out ulong result) ? new FileSize(result) : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
|
using Phantom.Common.Data.Minecraft;
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
using Phantom.Common.Data.Web.Instance;
|
using Phantom.Common.Data.Web.Instance;
|
||||||
using Phantom.Common.Data.Web.Users;
|
using Phantom.Common.Data.Web.Users;
|
||||||
@@ -55,9 +56,9 @@ public sealed class InstanceManager(ControllerConnection controllerConnection) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Result<StopInstanceResult, UserInstanceActionFailure>> StopInstance(AuthenticatedUser? authenticatedUser, Guid agentGuid, Guid instanceGuid, ushort afterSeconds, CancellationToken cancellationToken) {
|
public async Task<Result<StopInstanceResult, UserInstanceActionFailure>> StopInstance(AuthenticatedUser? authenticatedUser, Guid agentGuid, Guid instanceGuid, MinecraftStopStrategy stopStrategy, CancellationToken cancellationToken) {
|
||||||
if (authenticatedUser != null && authenticatedUser.Info.CheckPermission(Permission.ControlInstances)) {
|
if (authenticatedUser != null && authenticatedUser.Info.CheckPermission(Permission.ControlInstances)) {
|
||||||
var message = new StopInstanceMessage(authenticatedUser.Token, agentGuid, instanceGuid, afterSeconds);
|
var message = new StopInstanceMessage(authenticatedUser.Token, agentGuid, instanceGuid, stopStrategy);
|
||||||
return await controllerConnection.Send<StopInstanceMessage, Result<StopInstanceResult, UserInstanceActionFailure>>(message, cancellationToken);
|
return await controllerConnection.Send<StopInstanceMessage, Result<StopInstanceResult, UserInstanceActionFailure>>(message, cancellationToken);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
@using Phantom.Common.Data.Replies
|
@using Phantom.Common.Data.Replies
|
||||||
@using Phantom.Common.Data.Web.Agent
|
@using Phantom.Common.Data.Web.Agent
|
||||||
@using Phantom.Common.Data.Web.Instance
|
@using Phantom.Common.Data.Web.Instance
|
||||||
@using Phantom.Common.Data.Web.Java
|
|
||||||
@using Phantom.Common.Data.Web.Minecraft
|
@using Phantom.Common.Data.Web.Minecraft
|
||||||
@using Phantom.Common.Data.Web.Users
|
@using Phantom.Common.Data.Web.Users
|
||||||
@using Phantom.Common.Messages.Web.ToController
|
@using Phantom.Common.Messages.Web.ToController
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
@using System.ComponentModel.DataAnnotations
|
@using System.ComponentModel.DataAnnotations
|
||||||
|
@using Phantom.Common.Data.Minecraft
|
||||||
@using Phantom.Common.Data.Replies
|
@using Phantom.Common.Data.Replies
|
||||||
@using Phantom.Common.Data.Web.Users
|
@using Phantom.Common.Data.Web.Users
|
||||||
@using Phantom.Utils.Result
|
@using Phantom.Utils.Result
|
||||||
@@ -53,7 +54,7 @@
|
|||||||
private async Task StopInstance(EditContext context) {
|
private async Task StopInstance(EditContext context) {
|
||||||
await form.SubmitModel.StartSubmitting();
|
await form.SubmitModel.StartSubmitting();
|
||||||
|
|
||||||
var result = await InstanceManager.StopInstance(await GetAuthenticatedUser(), AgentGuid, InstanceGuid, form.StopInSeconds, CancellationToken);
|
var result = await InstanceManager.StopInstance(await GetAuthenticatedUser(), AgentGuid, InstanceGuid, new MinecraftStopStrategy(form.StopInSeconds), CancellationToken);
|
||||||
|
|
||||||
switch (result.Variant()) {
|
switch (result.Variant()) {
|
||||||
case Ok<StopInstanceResult>(StopInstanceResult.StopInitiated):
|
case Ok<StopInstanceResult>(StopInstanceResult.StopInitiated):
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
using Phantom.Common.Data.Web.Java;
|
using Phantom.Common.Data.Web.Minecraft;
|
||||||
using Phantom.Common.Data.Web.Users;
|
using Phantom.Common.Data.Web.Users;
|
||||||
|
|
||||||
namespace Phantom.Web.Utils;
|
namespace Phantom.Web.Utils;
|
||||||
|
|||||||
Reference in New Issue
Block a user