mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2026-03-01 05:07:53 +01:00
Compare commits
2 Commits
c996a9eaf1
...
1983748036
| Author | SHA1 | Date | |
|---|---|---|---|
|
1983748036
|
|||
|
03ba1407e8
|
@@ -6,7 +6,7 @@
|
|||||||
<option name="PASS_PARENT_ENVS" value="1" />
|
<option name="PASS_PARENT_ENVS" value="1" />
|
||||||
<envs>
|
<envs>
|
||||||
<env name="AGENT_KEY_FILE" value="./key" />
|
<env name="AGENT_KEY_FILE" value="./key" />
|
||||||
<env name="ALLOWED_ADDITIONAL_PORTS" value="25575,27000,27001" />
|
<env name="ALLOWED_RCON_PORTS" value="25575,27000,27001" />
|
||||||
<env name="ALLOWED_SERVER_PORTS" value="25565,26000,26001" />
|
<env name="ALLOWED_SERVER_PORTS" value="25565,26000,26001" />
|
||||||
<env name="CONTROLLER_HOST" value="localhost" />
|
<env name="CONTROLLER_HOST" value="localhost" />
|
||||||
<env name="JAVA_SEARCH_PATH" value="~/.jdks" />
|
<env name="JAVA_SEARCH_PATH" value="~/.jdks" />
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
||||||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
|
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
|
||||||
<option name="PROJECT_KIND" value="DotNetCore" />
|
<option name="PROJECT_KIND" value="DotNetCore" />
|
||||||
<option name="PROJECT_TFM" value="net10.0" />
|
<option name="PROJECT_TFM" value="net9.0" />
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="Build" />
|
<option name="Build" />
|
||||||
</method>
|
</method>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<option name="PASS_PARENT_ENVS" value="1" />
|
<option name="PASS_PARENT_ENVS" value="1" />
|
||||||
<envs>
|
<envs>
|
||||||
<env name="AGENT_KEY_FILE" value="./key" />
|
<env name="AGENT_KEY_FILE" value="./key" />
|
||||||
<env name="ALLOWED_ADDITIONAL_PORTS" value="27002-27006" />
|
<env name="ALLOWED_RCON_PORTS" value="27002-27006" />
|
||||||
<env name="ALLOWED_SERVER_PORTS" value="26002-26006" />
|
<env name="ALLOWED_SERVER_PORTS" value="26002-26006" />
|
||||||
<env name="CONTROLLER_HOST" value="localhost" />
|
<env name="CONTROLLER_HOST" value="localhost" />
|
||||||
<env name="JAVA_SEARCH_PATH" value="~/.jdks" />
|
<env name="JAVA_SEARCH_PATH" value="~/.jdks" />
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
||||||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
|
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
|
||||||
<option name="PROJECT_KIND" value="DotNetCore" />
|
<option name="PROJECT_KIND" value="DotNetCore" />
|
||||||
<option name="PROJECT_TFM" value="net10.0" />
|
<option name="PROJECT_TFM" value="net9.0" />
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="Build" />
|
<option name="Build" />
|
||||||
</method>
|
</method>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<option name="PASS_PARENT_ENVS" value="1" />
|
<option name="PASS_PARENT_ENVS" value="1" />
|
||||||
<envs>
|
<envs>
|
||||||
<env name="AGENT_KEY_FILE" value="./key" />
|
<env name="AGENT_KEY_FILE" value="./key" />
|
||||||
<env name="ALLOWED_ADDITIONAL_PORTS" value="27007" />
|
<env name="ALLOWED_RCON_PORTS" value="27007" />
|
||||||
<env name="ALLOWED_SERVER_PORTS" value="26007" />
|
<env name="ALLOWED_SERVER_PORTS" value="26007" />
|
||||||
<env name="CONTROLLER_HOST" value="localhost" />
|
<env name="CONTROLLER_HOST" value="localhost" />
|
||||||
<env name="JAVA_SEARCH_PATH" value="~/.jdks" />
|
<env name="JAVA_SEARCH_PATH" value="~/.jdks" />
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
||||||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
|
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
|
||||||
<option name="PROJECT_KIND" value="DotNetCore" />
|
<option name="PROJECT_KIND" value="DotNetCore" />
|
||||||
<option name="PROJECT_TFM" value="net10.0" />
|
<option name="PROJECT_TFM" value="net9.0" />
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="Build" />
|
<option name="Build" />
|
||||||
</method>
|
</method>
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ static class JavaPropertiesStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Reader(string path) {
|
public Reader(string path) {
|
||||||
this.reader = new StreamReader(path, Encoding, detectEncodingFromByteOrderMarks: true, CreateFileStreamOptions(FileMode.Open, FileAccess.Read));
|
this.reader = new StreamReader(path, Encoding, detectEncodingFromByteOrderMarks: false, CreateFileStreamOptions(FileMode.Open, FileAccess.Read));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async IAsyncEnumerable<KeyValuePair<string, string>> ReadProperties([EnumeratorCancellation] CancellationToken cancellationToken) {
|
public async IAsyncEnumerable<KeyValuePair<string, string>> ReadProperties([EnumeratorCancellation] CancellationToken cancellationToken) {
|
||||||
|
|||||||
25
Agent/Phantom.Agent.Minecraft/Java/JvmArgumentBuilder.cs
Normal file
25
Agent/Phantom.Agent.Minecraft/Java/JvmArgumentBuilder.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
|
namespace Phantom.Agent.Minecraft.Java;
|
||||||
|
|
||||||
|
sealed class JvmArgumentBuilder(JvmProperties basicProperties) {
|
||||||
|
private readonly List<string> customArguments = [];
|
||||||
|
|
||||||
|
public void Add(string argument) {
|
||||||
|
customArguments.Add(argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddProperty(string key, string value) {
|
||||||
|
customArguments.Add("-D" + key + "=\"" + value + "\""); // TODO test quoting?
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Build(Collection<string> target) {
|
||||||
|
foreach (var property in customArguments) {
|
||||||
|
target.Add(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
// In case of duplicate JVM arguments, typically the last one wins.
|
||||||
|
target.Add("-Xms" + basicProperties.InitialHeapMegabytes + "M");
|
||||||
|
target.Add("-Xmx" + basicProperties.MaximumHeapMegabytes + "M");
|
||||||
|
}
|
||||||
|
}
|
||||||
6
Agent/Phantom.Agent.Minecraft/Java/JvmProperties.cs
Normal file
6
Agent/Phantom.Agent.Minecraft/Java/JvmProperties.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Phantom.Agent.Minecraft.Java;
|
||||||
|
|
||||||
|
public sealed record JvmProperties(
|
||||||
|
uint InitialHeapMegabytes,
|
||||||
|
uint MaximumHeapMegabytes
|
||||||
|
);
|
||||||
@@ -2,10 +2,9 @@
|
|||||||
using Phantom.Agent.Minecraft.Instance;
|
using Phantom.Agent.Minecraft.Instance;
|
||||||
using Phantom.Agent.Minecraft.Java;
|
using Phantom.Agent.Minecraft.Java;
|
||||||
using Phantom.Agent.Minecraft.Server;
|
using Phantom.Agent.Minecraft.Server;
|
||||||
using Phantom.Common.Data.Agent;
|
|
||||||
using Phantom.Common.Data.Agent.Instance;
|
|
||||||
using Phantom.Common.Data.Agent.Instance.Launch;
|
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
|
using Phantom.Common.Data.Instance.Launch;
|
||||||
|
using Phantom.Common.Data.Minecraft;
|
||||||
using Phantom.Utils.Processes;
|
using Phantom.Utils.Processes;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
@@ -21,19 +20,19 @@ public sealed class InstanceLauncher(
|
|||||||
public async Task<LaunchResult> 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);
|
string? executablePath = launchRecipe.Executable.Resolve(pathResolver);
|
||||||
if (executablePath == null) {
|
if (executablePath == null) {
|
||||||
logger.Error("Could not resolve server executable path");
|
logger.Error("Could not resolve server executable: {Path}", launchRecipe.Executable);
|
||||||
return new LaunchResult.CouldNotFindServerExecutable();
|
return new LaunchResult.CouldNotFindServerExecutable();
|
||||||
}
|
}
|
||||||
|
|
||||||
var stepExecutor = new StepExecutor(downloadManager, pathResolver, reportStatus, cancellationToken);
|
var stepVisitor = new StepExecutor(downloadManager, pathResolver, reportStatus, cancellationToken);
|
||||||
var steps = launchRecipe.Preparation;
|
var steps = launchRecipe.Preparation;
|
||||||
|
|
||||||
for (int stepIndex = 0; stepIndex < steps.Length; stepIndex++) {
|
for (int stepIndex = 0; stepIndex < steps.Length; stepIndex++) {
|
||||||
var step = steps[stepIndex];
|
var step = steps[stepIndex];
|
||||||
try {
|
try {
|
||||||
await step.Run(stepExecutor);
|
await step.Run(stepVisitor);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.Error(e, "Failed preparation step {StepIndex} out of {StepCount}: {Step}", stepIndex, steps.Length, step.GetType().Name);
|
logger.Error(e, "Failed preparation step {StepIndex} out of {StepCount}: {Step}", stepIndex, steps.Length, step);
|
||||||
return new LaunchResult.CouldNotPrepareServerInstance();
|
return new LaunchResult.CouldNotPrepareServerInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,7 +80,6 @@ public sealed class InstanceLauncher(
|
|||||||
public async Task DownloadFile(FileDownloadInfo downloadInfo, IInstancePath path) {
|
public async Task DownloadFile(FileDownloadInfo downloadInfo, IInstancePath path) {
|
||||||
string? filePath = path.Resolve(pathResolver);
|
string? filePath = path.Resolve(pathResolver);
|
||||||
if (filePath == null) {
|
if (filePath == null) {
|
||||||
// TODO avoid exc
|
|
||||||
throw new FileNotFoundException("Could not resolve path");
|
throw new FileNotFoundException("Could not resolve path");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
Agent/Phantom.Agent.Minecraft/Launcher/ServerJarInfo.cs
Normal file
7
Agent/Phantom.Agent.Minecraft/Launcher/ServerJarInfo.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using System.Collections.Immutable;
|
||||||
|
|
||||||
|
namespace Phantom.Agent.Minecraft.Launcher;
|
||||||
|
|
||||||
|
sealed record ServerJarInfo(string FilePath, ImmutableArray<string> ExtraArgs) {
|
||||||
|
public ServerJarInfo(string filePath) : this(filePath, ImmutableArray<string>.Empty) {}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Common\Phantom.Common.Data.Agent\Phantom.Common.Data.Agent.csproj" />
|
<ProjectReference Include="..\..\Common\Phantom.Common.Data\Phantom.Common.Data.csproj" />
|
||||||
<ProjectReference Include="..\..\Utils\Phantom.Utils\Phantom.Utils.csproj" />
|
<ProjectReference Include="..\..\Utils\Phantom.Utils\Phantom.Utils.csproj" />
|
||||||
<ProjectReference Include="..\..\Utils\Phantom.Utils.Logging\Phantom.Utils.Logging.csproj" />
|
<ProjectReference Include="..\..\Utils\Phantom.Utils.Logging\Phantom.Utils.Logging.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Phantom.Common.Data.Agent;
|
using Phantom.Common.Data.Minecraft;
|
||||||
using Phantom.Utils.IO;
|
using Phantom.Utils.IO;
|
||||||
using Phantom.Utils.Logging;
|
using Phantom.Utils.Logging;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using Phantom.Common.Data.Agent;
|
using Phantom.Common.Data.Minecraft;
|
||||||
using Phantom.Utils.Cryptography;
|
using Phantom.Utils.Cryptography;
|
||||||
using Phantom.Utils.IO;
|
using Phantom.Utils.IO;
|
||||||
using Phantom.Utils.Logging;
|
using Phantom.Utils.Logging;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
using Phantom.Agent.Services.Backups;
|
using Phantom.Agent.Services.Backups;
|
||||||
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.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.Minecraft;
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ using Phantom.Agent.Minecraft.Server;
|
|||||||
using Phantom.Agent.Services.Backups;
|
using Phantom.Agent.Services.Backups;
|
||||||
using Phantom.Agent.Services.Rpc;
|
using Phantom.Agent.Services.Rpc;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
using Phantom.Common.Data.Agent.Instance;
|
|
||||||
using Phantom.Common.Data.Agent.Instance.Launch;
|
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
|
using Phantom.Common.Data.Instance.Launch;
|
||||||
using Phantom.Common.Data.Minecraft;
|
using Phantom.Common.Data.Minecraft;
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
using Phantom.Utils.Actor;
|
using Phantom.Utils.Actor;
|
||||||
@@ -57,7 +56,7 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
|
|
||||||
public interface ICommand;
|
public interface ICommand;
|
||||||
|
|
||||||
public sealed record ConfigureInstanceCommand(Guid InstanceGuid, InstanceInfo InstanceInfo, InstanceLaunchRecipe? LaunchRecipe, bool LaunchNow, bool AlwaysReportStatus) : ICommand, ICanReply<Result<ConfigureInstanceResult, InstanceActionFailure>>;
|
public sealed record ConfigureInstanceCommand(Guid InstanceGuid, InstanceInfo Info, 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>>;
|
||||||
|
|
||||||
@@ -69,7 +68,7 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
|
|
||||||
private Result<ConfigureInstanceResult, InstanceActionFailure> ConfigureInstance(ConfigureInstanceCommand command) {
|
private Result<ConfigureInstanceResult, InstanceActionFailure> ConfigureInstance(ConfigureInstanceCommand command) {
|
||||||
var instanceGuid = command.InstanceGuid;
|
var instanceGuid = command.InstanceGuid;
|
||||||
var instanceInfo = command.InstanceInfo;
|
var instanceInfo = command.Info;
|
||||||
var launchRecipe = command.LaunchRecipe;
|
var launchRecipe = command.LaunchRecipe;
|
||||||
|
|
||||||
if (instances.TryGetValue(instanceGuid, out var instance)) {
|
if (instances.TryGetValue(instanceGuid, out var instance)) {
|
||||||
@@ -86,8 +85,7 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var instanceLoggerName = PhantomLogger.ShortenGuid(instanceGuid) + "/" + Interlocked.Increment(ref instanceLoggerSequenceId);
|
var instanceLoggerName = PhantomLogger.ShortenGuid(instanceGuid) + "/" + Interlocked.Increment(ref instanceLoggerSequenceId);
|
||||||
var instanceFolder = Path.Combine(agentFolders.InstancesFolderPath, instanceGuid.ToString());
|
var instanceProperties = new InstanceProperties(instanceGuid, Path.Combine(agentFolders.InstancesFolderPath, instanceGuid.ToString()));
|
||||||
var instanceProperties = new InstanceProperties(instanceGuid, instanceFolder);
|
|
||||||
var instanceInit = new InstanceActor.Init(agentState, instanceGuid, instanceLoggerName, instanceServices, instanceTicketManager, shutdownCancellationToken);
|
var instanceInit = new InstanceActor.Init(agentState, instanceGuid, instanceLoggerName, instanceServices, instanceTicketManager, shutdownCancellationToken);
|
||||||
instances[instanceGuid] = instance = new Instance(Context.ActorOf(InstanceActor.Factory(instanceInit), "Instance-" + instanceGuid), instanceInfo, instanceProperties, launchRecipe);
|
instances[instanceGuid] = instance = new Instance(Context.ActorOf(InstanceActor.Factory(instanceInit), "Instance-" + instanceGuid), instanceInfo, instanceProperties, launchRecipe);
|
||||||
|
|
||||||
@@ -96,10 +94,11 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
instance.Actor.Tell(new InstanceActor.ReportInstanceStatusCommand());
|
instance.Actor.Tell(new InstanceActor.ReportInstanceStatusCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string instanceFolder = instance.Properties.InstanceFolder;
|
||||||
try {
|
try {
|
||||||
Directories.Create(instance.Properties.InstanceFolder, Chmod.URWX_GRX);
|
Directories.Create(instanceFolder, Chmod.URWX_GRX);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.Error(e, "Could not create instance folder: {Path}", instance.Properties.InstanceFolder);
|
Logger.Error(e, "Could not create instance folder: {Path}", instanceFolder);
|
||||||
return ConfigureInstanceResult.CouldNotCreateInstanceFolder;
|
return ConfigureInstanceResult.CouldNotCreateInstanceFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,41 +1,30 @@
|
|||||||
using System.Buffers;
|
using System.Collections.Immutable;
|
||||||
using System.Collections.Immutable;
|
|
||||||
using Phantom.Agent.Minecraft.Instance;
|
using Phantom.Agent.Minecraft.Instance;
|
||||||
using Phantom.Agent.Minecraft.Java;
|
using Phantom.Agent.Minecraft.Java;
|
||||||
using Phantom.Common.Data.Agent.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
|
|
||||||
namespace Phantom.Agent.Services.Instances;
|
namespace Phantom.Agent.Services.Instances;
|
||||||
|
|
||||||
sealed class InstancePathResolver(AgentFolders agentFolders, JavaRuntimeRepository javaRuntimeRepository, InstanceProperties instanceProperties) : IInstancePathResolver {
|
sealed class InstancePathResolver(AgentFolders agentFolders, JavaRuntimeRepository javaRuntimeRepository, InstanceProperties instanceProperties) : IInstancePathResolver {
|
||||||
public string? Global(ImmutableArray<string> segments) {
|
public string Global(ImmutableArray<string> path) {
|
||||||
return ValidateAndCombinePath(agentFolders.ServerExecutableFolderPath, segments);
|
return CombinePath(agentFolders.ServerExecutableFolderPath, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? Local(ImmutableArray<string> segments) {
|
public string Local(ImmutableArray<string> path) {
|
||||||
return ValidateAndCombinePath(instanceProperties.InstanceFolder, segments);
|
return CombinePath(instanceProperties.InstanceFolder, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? Runtime(Guid guid) {
|
public string? Runtime(Guid guid) {
|
||||||
return javaRuntimeRepository.TryGetByGuid(guid, out var runtime) ? runtime.ExecutablePath : null;
|
if (javaRuntimeRepository.TryGetByGuid(guid, out var runtime)) {
|
||||||
|
return runtime.ExecutablePath;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
private static readonly SearchValues<char> InvalidPathPartChars = SearchValues.Create([
|
|
||||||
Path.DirectorySeparatorChar,
|
|
||||||
Path.AltDirectorySeparatorChar,
|
|
||||||
..Path.GetInvalidPathChars(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
private string? ValidateAndCombinePath(string basePath, ImmutableArray<string> pathSegments) {
|
|
||||||
string path = basePath;
|
|
||||||
|
|
||||||
foreach (string segment in pathSegments) {
|
|
||||||
if (segment == "." || segment == ".." || segment.ContainsAny(InvalidPathPartChars) || Path.IsPathRooted(segment)) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
path = Path.Combine(path, segment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Path.GetFullPath(path);
|
private string CombinePath(string basePath, ImmutableArray<string> additionalParts) {
|
||||||
|
// TODO validation
|
||||||
|
return Path.Combine([basePath, ..additionalParts]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
using Phantom.Agent.Services.Rpc;
|
using Phantom.Agent.Services.Rpc;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
using Phantom.Common.Data.Agent;
|
using Phantom.Common.Data.Agent;
|
||||||
using Phantom.Common.Data.Agent.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
using Phantom.Common.Messages.Agent.ToController;
|
using Phantom.Common.Messages.Agent.ToController;
|
||||||
using Phantom.Utils.Logging;
|
using Phantom.Utils.Logging;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Phantom.Common.Data.Agent.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
|
|
||||||
namespace Phantom.Agent.Services.Instances;
|
namespace Phantom.Agent.Services.Instances;
|
||||||
|
|
||||||
@@ -6,4 +6,8 @@ sealed class InstanceValueResolver(IInstancePathResolver pathResolver) : IInstan
|
|||||||
public string? Path(IInstancePath value) {
|
public string? Path(IInstancePath value) {
|
||||||
return value.Resolve(pathResolver);
|
return value.Resolve(pathResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string? Variable(InstanceVariable value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using Phantom.Agent.Minecraft.Instance;
|
using Phantom.Agent.Minecraft.Instance;
|
||||||
using Phantom.Agent.Minecraft.Launcher;
|
using Phantom.Agent.Minecraft.Launcher;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
using Phantom.Common.Data.Agent.Instance;
|
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
|
using Phantom.Common.Data.Instance.Launch;
|
||||||
|
|
||||||
namespace Phantom.Agent.Services.Instances.State;
|
namespace Phantom.Agent.Services.Instances.State;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
using Phantom.Agent.Minecraft.Instance;
|
using Phantom.Agent.Minecraft.Instance;
|
||||||
using Phantom.Agent.Minecraft.Launcher;
|
using Phantom.Agent.Minecraft.Launcher;
|
||||||
using Phantom.Agent.Services.Backups;
|
using Phantom.Agent.Services.Backups;
|
||||||
using Phantom.Common.Data.Agent.Instance;
|
|
||||||
using Phantom.Common.Data.Backups;
|
using Phantom.Common.Data.Backups;
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
|
using Phantom.Common.Data.Instance.Launch;
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
|
|
||||||
namespace Phantom.Agent.Services.Instances.State;
|
namespace Phantom.Agent.Services.Instances.State;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ sealed record Variables(
|
|||||||
try {
|
try {
|
||||||
return LoadOrThrow();
|
return LoadOrThrow();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
PhantomLogger.Root.Fatal("{Error}", e.Message);
|
PhantomLogger.Root.Fatal("{}", e.Message);
|
||||||
throw StopProcedureException.Instance;
|
throw StopProcedureException.Instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
using System.Collections.Immutable;
|
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Agent.Instance;
|
|
||||||
|
|
||||||
public interface IInstancePathResolver {
|
|
||||||
string? Global(ImmutableArray<string> segments);
|
|
||||||
string? Local(ImmutableArray<string> segments);
|
|
||||||
string? Runtime(Guid guid);
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
namespace Phantom.Common.Data.Agent.Instance;
|
|
||||||
|
|
||||||
public interface IInstanceValueResolver {
|
|
||||||
string? Path(IInstancePath value);
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="MemoryPack" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\Phantom.Common.Data\Phantom.Common.Data.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
|
using Phantom.Common.Data.Agent;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Web.Agent;
|
namespace Phantom.Common.Data.Web.Agent;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
|
using Phantom.Common.Data.Agent;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Web.Agent;
|
namespace Phantom.Common.Data.Web.Agent;
|
||||||
|
|
||||||
@@ -9,4 +10,8 @@ public sealed partial record AgentRuntimeInfo(
|
|||||||
[property: MemoryPackOrder(2)] RamAllocationUnits? MaxMemory = null,
|
[property: MemoryPackOrder(2)] RamAllocationUnits? MaxMemory = null,
|
||||||
[property: MemoryPackOrder(3)] AllowedPorts? AllowedServerPorts = null,
|
[property: MemoryPackOrder(3)] AllowedPorts? AllowedServerPorts = null,
|
||||||
[property: MemoryPackOrder(4)] AllowedPorts? AllowedAdditionalPorts = null
|
[property: MemoryPackOrder(4)] AllowedPorts? AllowedAdditionalPorts = null
|
||||||
);
|
) {
|
||||||
|
public static AgentRuntimeInfo From(AgentInfo agentInfo) {
|
||||||
|
return new AgentRuntimeInfo(new AgentVersionInfo(agentInfo.ProtocolVersion, agentInfo.BuildVersion), agentInfo.MaxInstances, agentInfo.MaxMemory, agentInfo.AllowedServerPorts, agentInfo.AllowedAdditionalPorts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ public enum CreateOrUpdateInstanceResult : byte {
|
|||||||
Success,
|
Success,
|
||||||
InstanceNameMustNotBeEmpty,
|
InstanceNameMustNotBeEmpty,
|
||||||
InstanceMemoryMustNotBeZero,
|
InstanceMemoryMustNotBeZero,
|
||||||
MinecraftVersionNotFound,
|
MinecraftVersionDownloadInfoNotFound,
|
||||||
AgentNotFound,
|
AgentNotFound,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ public static class CreateOrUpdateInstanceResultExtensions {
|
|||||||
CreateOrUpdateInstanceResult.Success => "Success.",
|
CreateOrUpdateInstanceResult.Success => "Success.",
|
||||||
CreateOrUpdateInstanceResult.InstanceNameMustNotBeEmpty => "Instance name must not be empty.",
|
CreateOrUpdateInstanceResult.InstanceNameMustNotBeEmpty => "Instance name must not be empty.",
|
||||||
CreateOrUpdateInstanceResult.InstanceMemoryMustNotBeZero => "Memory must not be 0 MB.",
|
CreateOrUpdateInstanceResult.InstanceMemoryMustNotBeZero => "Memory must not be 0 MB.",
|
||||||
CreateOrUpdateInstanceResult.MinecraftVersionNotFound => "Minecraft version not found.",
|
CreateOrUpdateInstanceResult.MinecraftVersionDownloadInfoNotFound => "Could not find download information for the selected Minecraft version.",
|
||||||
CreateOrUpdateInstanceResult.AgentNotFound => "Agent not found.",
|
CreateOrUpdateInstanceResult.AgentNotFound => "Agent not found.",
|
||||||
_ => "Unknown error.",
|
_ => "Unknown error.",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Web.Agent;
|
namespace Phantom.Common.Data.Agent;
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial record AgentStats(
|
public sealed partial record AgentStats(
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
using Phantom.Common.Data.Backups;
|
using Phantom.Common.Data.Backups;
|
||||||
|
using Phantom.Common.Data.Instance.Launch;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Instance;
|
namespace Phantom.Common.Data.Instance;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Agent.Instance;
|
namespace Phantom.Common.Data.Instance;
|
||||||
|
|
||||||
[MemoryPackable]
|
[MemoryPackable]
|
||||||
[MemoryPackUnion(tag: 0, typeof(InstancePath.Global))]
|
[MemoryPackUnion(tag: 0, typeof(InstancePath.Global))]
|
||||||
@@ -14,27 +14,19 @@ public partial interface IInstancePath {
|
|||||||
public static partial class InstancePath {
|
public static partial class InstancePath {
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial record Global(
|
public sealed partial record Global(
|
||||||
[property: MemoryPackOrder(0)] ImmutableArray<string> Segments
|
[property: MemoryPackOrder(0)] ImmutableArray<string> Path
|
||||||
) : IInstancePath {
|
) : IInstancePath {
|
||||||
public string? Resolve(IInstancePathResolver resolver) {
|
public string? Resolve(IInstancePathResolver resolver) {
|
||||||
return resolver.Global(Segments);
|
return resolver.Global(Path);
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString() {
|
|
||||||
return string.Join(separator: '/', Segments);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial record Local(
|
public sealed partial record Local(
|
||||||
[property: MemoryPackOrder(0)] ImmutableArray<string> Segments
|
[property: MemoryPackOrder(0)] ImmutableArray<string> Path
|
||||||
) : IInstancePath {
|
) : IInstancePath {
|
||||||
public string? Resolve(IInstancePathResolver resolver) {
|
public string? Resolve(IInstancePathResolver resolver) {
|
||||||
return resolver.Local(Segments);
|
return resolver.Local(Path);
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString() {
|
|
||||||
return string.Join(separator: '/', Segments);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Collections.Immutable;
|
||||||
|
|
||||||
|
namespace Phantom.Common.Data.Instance;
|
||||||
|
|
||||||
|
public interface IInstancePathResolver {
|
||||||
|
string? Global(ImmutableArray<string> path);
|
||||||
|
string? Local(ImmutableArray<string> path);
|
||||||
|
string? Runtime(Guid guid);
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
|
using Phantom.Common.Data.Instance.Launch;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Instance;
|
namespace Phantom.Common.Data.Instance;
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,13 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Agent.Instance;
|
namespace Phantom.Common.Data.Instance;
|
||||||
|
|
||||||
[MemoryPackable]
|
[MemoryPackable]
|
||||||
[MemoryPackUnion(tag: 0, typeof(InstanceValues.Concatenation))]
|
[MemoryPackUnion(tag: 0, typeof(InstanceValues.Concatenation))]
|
||||||
[MemoryPackUnion(tag: 1, typeof(InstanceValues.Text))]
|
[MemoryPackUnion(tag: 1, typeof(InstanceValues.Text))]
|
||||||
[MemoryPackUnion(tag: 2, typeof(InstanceValues.Path))]
|
[MemoryPackUnion(tag: 2, typeof(InstanceValues.Path))]
|
||||||
|
[MemoryPackUnion(tag: 3, typeof(InstanceValues.Variable))]
|
||||||
public partial interface IInstanceValue {
|
public partial interface IInstanceValue {
|
||||||
string? Resolve(IInstanceValueResolver resolver);
|
string? Resolve(IInstanceValueResolver resolver);
|
||||||
}
|
}
|
||||||
@@ -44,4 +45,13 @@ public static partial class InstanceValues {
|
|||||||
return resolver.Path(Value);
|
return resolver.Path(Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MemoryPackable]
|
||||||
|
public sealed partial record Variable(InstanceVariable Value) : IInstanceValue {
|
||||||
|
public string? Resolve(IInstanceValueResolver resolver) {
|
||||||
|
return resolver.Variable(Value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum InstanceVariable {}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Phantom.Common.Data.Instance;
|
||||||
|
|
||||||
|
public interface IInstanceValueResolver {
|
||||||
|
string? Path(IInstancePath value);
|
||||||
|
string? Variable(InstanceVariable value);
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
using Phantom.Common.Data.Web.Minecraft;
|
using Phantom.Common.Data.Minecraft;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Web.Instance;
|
namespace Phantom.Common.Data.Instance;
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial record InstanceConfiguration(
|
public sealed partial record InstanceConfiguration(
|
||||||
@@ -15,4 +15,7 @@ public sealed partial record InstanceConfiguration(
|
|||||||
[property: MemoryPackOrder(6)] RamAllocationUnits MemoryAllocation,
|
[property: MemoryPackOrder(6)] RamAllocationUnits MemoryAllocation,
|
||||||
[property: MemoryPackOrder(7)] Guid JavaRuntimeGuid,
|
[property: MemoryPackOrder(7)] Guid JavaRuntimeGuid,
|
||||||
[property: MemoryPackOrder(8)] ImmutableArray<string> JvmArguments
|
[property: MemoryPackOrder(8)] ImmutableArray<string> JvmArguments
|
||||||
);
|
) {
|
||||||
|
[MemoryPackIgnore]
|
||||||
|
public InstanceInfo AsInfo => new (InstanceName, ServerPort, [RconPort], MemoryAllocation);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Agent.Instance;
|
namespace Phantom.Common.Data.Instance;
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial record InstanceInfo(
|
public sealed partial record InstanceInfo(
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
|
using Phantom.Common.Data.Minecraft;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Agent.Instance.Launch;
|
namespace Phantom.Common.Data.Instance.Launch;
|
||||||
|
|
||||||
[MemoryPackable]
|
[MemoryPackable]
|
||||||
[MemoryPackUnion(tag: 0, typeof(InstanceLaunchStep.DownloadFile))]
|
[MemoryPackUnion(tag: 0, typeof(InstanceLaunchStep.DownloadFile))]
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using Phantom.Common.Data.Minecraft;
|
using Phantom.Common.Data.Minecraft;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Agent.Instance.Launch;
|
namespace Phantom.Common.Data.Instance.Launch;
|
||||||
|
|
||||||
public interface IInstanceLaunchStepExecutor {
|
public interface IInstanceLaunchStepExecutor {
|
||||||
Task DownloadFile(FileDownloadInfo downloadInfo, IInstancePath path);
|
Task DownloadFile(FileDownloadInfo downloadInfo, IInstancePath path);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Phantom.Common.Data.Instance;
|
namespace Phantom.Common.Data.Instance.Launch;
|
||||||
|
|
||||||
public enum InstanceLaunchFailReason : byte {
|
public enum InstanceLaunchFailReason : byte {
|
||||||
UnknownError = 0,
|
UnknownError = 0,
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Agent.Instance.Launch;
|
namespace Phantom.Common.Data.Instance.Launch;
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial record InstanceLaunchRecipe(
|
public sealed partial record InstanceLaunchRecipe(
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
using Phantom.Utils.Cryptography;
|
using Phantom.Utils.Cryptography;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Agent;
|
namespace Phantom.Common.Data.Minecraft;
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial class FileDownloadInfo {
|
public sealed partial class FileDownloadInfo {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Phantom.Common.Data.Web.Minecraft;
|
namespace Phantom.Common.Data.Minecraft;
|
||||||
|
|
||||||
public enum MinecraftServerKind : ushort {
|
public enum MinecraftServerKind : ushort {
|
||||||
Vanilla = 1,
|
Vanilla = 1,
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Web.Minecraft;
|
namespace Phantom.Common.Data.Minecraft;
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial record MinecraftVersion(
|
public sealed partial record MinecraftVersion(
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Web.Minecraft;
|
namespace Phantom.Common.Data.Minecraft;
|
||||||
|
|
||||||
public enum MinecraftVersionType : ushort {
|
public enum MinecraftVersionType : ushort {
|
||||||
Other = 0,
|
Other = 0,
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
|
using Phantom.Utils.Monads;
|
||||||
using Phantom.Utils.Result;
|
using Phantom.Utils.Result;
|
||||||
|
|
||||||
namespace Phantom.Common.Data;
|
namespace Phantom.Common.Data;
|
||||||
@@ -24,6 +25,9 @@ public sealed partial class Result<TValue, TError> {
|
|||||||
[MemoryPackIgnore]
|
[MemoryPackIgnore]
|
||||||
public TError Error => !hasValue ? error! : throw new InvalidOperationException("Attempted to get error from a success result.");
|
public TError Error => !hasValue ? error! : throw new InvalidOperationException("Attempted to get error from a success result.");
|
||||||
|
|
||||||
|
[MemoryPackIgnore]
|
||||||
|
public Either<TValue, TError> AsEither => hasValue ? Either.Left(value!) : Either.Right(error!);
|
||||||
|
|
||||||
private Result(bool hasValue, TValue? value, TError? error) {
|
private Result(bool hasValue, TValue? value, TError? error) {
|
||||||
this.hasValue = hasValue;
|
this.hasValue = hasValue;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
@@ -34,11 +38,6 @@ public sealed partial class Result<TValue, TError> {
|
|||||||
return hasValue && EqualityComparer<TValue>.Default.Equals(value, expectedValue);
|
return hasValue && EqualityComparer<TValue>.Default.Equals(value, expectedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
[return: NotNullIfNotNull(nameof(valueIfError))]
|
|
||||||
public TValue? OrElse(TValue? valueIfError) {
|
|
||||||
return hasValue ? Value : valueIfError;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TOutput Into<TOutput>(Func<TValue, TOutput> valueConverter, Func<TError, TOutput> errorConverter) {
|
public TOutput Into<TOutput>(Func<TValue, TOutput> valueConverter, Func<TError, TOutput> errorConverter) {
|
||||||
return hasValue ? valueConverter(value!) : errorConverter(error!);
|
return hasValue ? valueConverter(value!) : errorConverter(error!);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Phantom.Common.Data.Agent\Phantom.Common.Data.Agent.csproj" />
|
<ProjectReference Include="..\Phantom.Common.Data\Phantom.Common.Data.csproj" />
|
||||||
<ProjectReference Include="..\..\Utils\Phantom.Utils.Logging\Phantom.Utils.Logging.csproj" />
|
<ProjectReference Include="..\..\Utils\Phantom.Utils.Logging\Phantom.Utils.Logging.csproj" />
|
||||||
<ProjectReference Include="..\..\Utils\Phantom.Utils.Rpc\Phantom.Utils.Rpc.csproj" />
|
<ProjectReference Include="..\..\Utils\Phantom.Utils.Rpc\Phantom.Utils.Rpc.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
using Phantom.Common.Data.Agent.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
using Phantom.Common.Data.Agent.Instance.Launch;
|
using Phantom.Common.Data.Instance.Launch;
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
using Phantom.Utils.Actor;
|
using Phantom.Utils.Actor;
|
||||||
|
|
||||||
|
|||||||
@@ -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.Instance;
|
||||||
using Phantom.Common.Data.Web.Instance;
|
using Phantom.Common.Data.Web.Instance;
|
||||||
using Phantom.Common.Data.Web.Users;
|
using Phantom.Common.Data.Web.Users;
|
||||||
using Phantom.Utils.Actor;
|
using Phantom.Utils.Actor;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using MemoryPack;
|
using MemoryPack;
|
||||||
using Phantom.Common.Data.Web.Minecraft;
|
using Phantom.Common.Data.Minecraft;
|
||||||
using Phantom.Utils.Actor;
|
using Phantom.Utils.Actor;
|
||||||
|
|
||||||
namespace Phantom.Common.Messages.Web.ToController;
|
namespace Phantom.Common.Messages.Web.ToController;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
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.AuditLog;
|
using Phantom.Common.Data.Web.AuditLog;
|
||||||
using Phantom.Common.Data.Web.EventLog;
|
using Phantom.Common.Data.Web.EventLog;
|
||||||
using Phantom.Common.Data.Web.Instance;
|
using Phantom.Common.Data.Web.Instance;
|
||||||
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;
|
||||||
using Phantom.Common.Messages.Web.ToWeb;
|
using Phantom.Common.Messages.Web.ToWeb;
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
|
using Phantom.Common.Data.Minecraft;
|
||||||
using Phantom.Common.Data.Web.AuditLog;
|
using Phantom.Common.Data.Web.AuditLog;
|
||||||
using Phantom.Common.Data.Web.EventLog;
|
using Phantom.Common.Data.Web.EventLog;
|
||||||
using Phantom.Common.Data.Web.Minecraft;
|
|
||||||
using Phantom.Controller.Database.Converters;
|
using Phantom.Controller.Database.Converters;
|
||||||
using Phantom.Controller.Database.Entities;
|
using Phantom.Controller.Database.Entities;
|
||||||
using Phantom.Controller.Database.Factories;
|
using Phantom.Controller.Database.Factories;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
using Phantom.Common.Data.Web.Minecraft;
|
using Phantom.Common.Data.Minecraft;
|
||||||
|
|
||||||
namespace Phantom.Controller.Database.Entities;
|
namespace Phantom.Controller.Database.Entities;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Phantom.Controller.Minecraft;
|
|
||||||
|
|
||||||
public enum MinecraftLaunchRecipeCreationFailReason : byte {
|
|
||||||
UnknownError = 0,
|
|
||||||
MinecraftVersionNotFound = 1,
|
|
||||||
}
|
|
||||||
@@ -1,33 +1,34 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data.Instance;
|
||||||
using Phantom.Common.Data.Agent;
|
using Phantom.Common.Data.Instance.Launch;
|
||||||
using Phantom.Common.Data.Agent.Instance;
|
using Phantom.Common.Data.Minecraft;
|
||||||
using Phantom.Common.Data.Agent.Instance.Launch;
|
|
||||||
using Phantom.Common.Data.Web.Instance;
|
|
||||||
using Phantom.Common.Data.Web.Minecraft;
|
|
||||||
using Phantom.Utils.Collections;
|
using Phantom.Utils.Collections;
|
||||||
|
|
||||||
namespace Phantom.Controller.Minecraft;
|
namespace Phantom.Controller.Minecraft;
|
||||||
|
|
||||||
public sealed partial class MinecraftLaunchRecipes(MinecraftVersions minecraftVersions) {
|
public sealed partial class MinecraftLaunchRecipes(MinecraftVersions minecraftVersions) {
|
||||||
|
[GeneratedRegex(@"[^a-zA-Z0-9_\-\.]", RegexOptions.Compiled)]
|
||||||
|
private static partial Regex SanitizePathRegex();
|
||||||
|
|
||||||
private static readonly ImmutableDictionary<string, string> Eula = ImmutableDictionary.From([
|
private static readonly ImmutableDictionary<string, string> Eula = ImmutableDictionary.From([
|
||||||
("eula", "true"),
|
("eula", "true"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
public async Task<Result<InstanceLaunchRecipe, MinecraftLaunchRecipeCreationFailReason>> Create(InstanceConfiguration configuration, CancellationToken cancellationToken) {
|
public async Task<InstanceLaunchRecipe?> Create(InstanceConfiguration configuration, CancellationToken cancellationToken) {
|
||||||
string minecraftVersion = configuration.MinecraftVersion;
|
string minecraftVersion = configuration.MinecraftVersion;
|
||||||
|
string minecraftVersionPath = SanitizePathRegex().IsMatch(minecraftVersion) ? SanitizePathRegex().Replace(minecraftVersion, "_") : minecraftVersion;
|
||||||
var serverExecutableInfo = await minecraftVersions.GetServerExecutableInfo(minecraftVersion, cancellationToken);
|
|
||||||
if (serverExecutableInfo == null) {
|
|
||||||
return MinecraftLaunchRecipeCreationFailReason.MinecraftVersionNotFound;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint maximumHeapSizeMegabvtes = configuration.MemoryAllocation.InMegabytes;
|
uint maximumHeapSizeMegabvtes = configuration.MemoryAllocation.InMegabytes;
|
||||||
uint initialHeapSizeMegabytes = maximumHeapSizeMegabvtes / 2;
|
uint initialHeapSizeMegabytes = maximumHeapSizeMegabvtes / 2;
|
||||||
|
|
||||||
var minecraftVersionPathSegment = SanitizePath(minecraftVersion);
|
var serverExecutableInfo = await minecraftVersions.GetServerExecutableInfo(minecraftVersion, cancellationToken);
|
||||||
var vanillaJarFilePath = new InstancePath.Global(["minecraft", "vanilla", minecraftVersionPathSegment, "server.jar"]);
|
if (serverExecutableInfo == null) {
|
||||||
|
// TODO
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var vanillaJarFilePath = new InstancePath.Global(["minecraft", "vanilla", minecraftVersionPath, "server.jar"]);
|
||||||
|
|
||||||
var steps = ImmutableArray.CreateBuilder<IInstanceLaunchStep>();
|
var steps = ImmutableArray.CreateBuilder<IInstanceLaunchStep>();
|
||||||
|
|
||||||
@@ -39,8 +40,12 @@ public sealed partial class MinecraftLaunchRecipes(MinecraftVersions minecraftVe
|
|||||||
var additionalJvmArguments = new List<IInstanceValue>();
|
var additionalJvmArguments = new List<IInstanceValue>();
|
||||||
|
|
||||||
if (configuration.MinecraftServerKind == MinecraftServerKind.Fabric) {
|
if (configuration.MinecraftServerKind == MinecraftServerKind.Fabric) {
|
||||||
var fabricLauncherFilePath = new InstancePath.Global(["minecraft", "fabric", minecraftVersionPathSegment, "loader.jar"]);
|
// TODO customizable loader version
|
||||||
AddFabricDownloadStep(steps, configuration, fabricLauncherFilePath);
|
string fabricLauncherUrl = $"https://meta.fabricmc.net/v2/versions/loader/{minecraftVersion}/stable/stable/server/jar";
|
||||||
|
|
||||||
|
var fabricLauncherFilePath = new InstancePath.Global(["minecraft", "fabric", minecraftVersionPath, "loader.jar"]);
|
||||||
|
|
||||||
|
steps.Add(new InstanceLaunchStep.DownloadFile(new FileDownloadInfo(fabricLauncherUrl), fabricLauncherFilePath));
|
||||||
|
|
||||||
serverExecutableFilePath = fabricLauncherFilePath;
|
serverExecutableFilePath = fabricLauncherFilePath;
|
||||||
|
|
||||||
@@ -61,13 +66,6 @@ public sealed partial class MinecraftLaunchRecipes(MinecraftVersions minecraftVe
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[GeneratedRegex(@"[^a-zA-Z0-9_\-\.]", RegexOptions.Compiled)]
|
|
||||||
private static partial Regex SanitizePathRegex();
|
|
||||||
|
|
||||||
private static string SanitizePath(string path) {
|
|
||||||
return SanitizePathRegex().IsMatch(path) ? SanitizePathRegex().Replace(path, "_") : path;
|
|
||||||
}
|
|
||||||
|
|
||||||
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()),
|
||||||
@@ -76,11 +74,4 @@ public sealed partial class MinecraftLaunchRecipes(MinecraftVersions minecraftVe
|
|||||||
("sync-chunk-writes", "false"),
|
("sync-chunk-writes", "false"),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AddFabricDownloadStep(ImmutableArray<IInstanceLaunchStep>.Builder steps, InstanceConfiguration configuration, InstancePath.Global filePath) {
|
|
||||||
// TODO customizable loader version
|
|
||||||
string minecraftVersion = configuration.MinecraftVersion;
|
|
||||||
string fabricLauncherUrl = $"https://meta.fabricmc.net/v2/versions/loader/{minecraftVersion}/stable/stable/server/jar";
|
|
||||||
steps.Add(new InstanceLaunchStep.DownloadFile(new FileDownloadInfo(fabricLauncherUrl), filePath));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Phantom.Common.Data.Agent;
|
using Phantom.Common.Data.Minecraft;
|
||||||
using Phantom.Common.Data.Web.Minecraft;
|
|
||||||
using Phantom.Utils.Cryptography;
|
using Phantom.Utils.Cryptography;
|
||||||
using Phantom.Utils.Logging;
|
using Phantom.Utils.Logging;
|
||||||
using Phantom.Utils.Runtime;
|
using Phantom.Utils.Runtime;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Phantom.Common.Data.Agent;
|
using Phantom.Common.Data.Minecraft;
|
||||||
using Phantom.Common.Data.Web.Minecraft;
|
|
||||||
using Phantom.Utils.Logging;
|
using Phantom.Utils.Logging;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
@@ -35,7 +34,7 @@ public sealed class MinecraftVersions : IDisposable {
|
|||||||
return versions;
|
return versions;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<FileDownloadInfo?> GetServerExecutableInfo(string version, CancellationToken cancellationToken) {
|
public async Task<FileDownloadInfo?> GetServerExecutableInfo(string version, CancellationToken cancellationToken) {
|
||||||
var versions = await GetVersions(cancellationToken);
|
var versions = await GetVersions(cancellationToken);
|
||||||
return await GetCachedObject(() => cachedServerExecutables.ContainsKey(version), () => cachedServerExecutables[version], v => cachedServerExecutables[version] = v, ct => LoadServerExecutableInfo(versions, version, ct), cancellationToken);
|
return await GetCachedObject(() => cachedServerExecutables.ContainsKey(version), () => cachedServerExecutables[version], v => cachedServerExecutables[version] = v, ct => LoadServerExecutableInfo(versions, version, ct), cancellationToken);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Common\Phantom.Common.Data.Agent\Phantom.Common.Data.Agent.csproj" />
|
<ProjectReference Include="..\..\Common\Phantom.Common.Data\Phantom.Common.Data.csproj" />
|
||||||
<ProjectReference Include="..\..\Common\Phantom.Common.Data.Web\Phantom.Common.Data.Web.csproj" />
|
|
||||||
<ProjectReference Include="..\..\Utils\Phantom.Utils\Phantom.Utils.csproj" />
|
<ProjectReference Include="..\..\Utils\Phantom.Utils\Phantom.Utils.csproj" />
|
||||||
<ProjectReference Include="..\..\Utils\Phantom.Utils.Logging\Phantom.Utils.Logging.csproj" />
|
<ProjectReference Include="..\..\Utils\Phantom.Utils.Logging\Phantom.Utils.Logging.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
using Akka.Actor;
|
using Akka.Actor;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
using Phantom.Common.Data.Agent.Instance.Launch;
|
using Phantom.Common.Data.Agent;
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
|
using Phantom.Common.Data.Instance.Launch;
|
||||||
using Phantom.Common.Data.Java;
|
using Phantom.Common.Data.Java;
|
||||||
using Phantom.Common.Data.Minecraft;
|
using Phantom.Common.Data.Minecraft;
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
@@ -190,14 +191,17 @@ 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 launchRecipes.Create(instanceConfiguration, cancellationToken);
|
var launchRecipe = await CreateInstanceLaunchRecipe(instanceConfiguration);
|
||||||
var configurationMessage = new ConfigureInstanceMessage(instanceGuid, instanceConfiguration.AsInfo, launchRecipe.OrElse(null), launchAutomatically);
|
configurationMessages.Add(new ConfigureInstanceMessage(instanceGuid, instanceConfiguration.AsInfo, launchRecipe, launchAutomatically));
|
||||||
configurationMessages.Add(configurationMessage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return configurationMessages.ToImmutable();
|
return configurationMessages.ToImmutable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<InstanceLaunchRecipe?> CreateInstanceLaunchRecipe(InstanceConfiguration configuration) {
|
||||||
|
return await launchRecipes.Create(configuration, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
public interface ICommand;
|
public interface ICommand;
|
||||||
|
|
||||||
private sealed record InitializeCommand : ICommand;
|
private sealed record InitializeCommand : ICommand;
|
||||||
@@ -346,29 +350,25 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
|
|||||||
.Unwrap();
|
.Unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task<Result<CreateOrUpdateInstanceResult, InstanceActionFailure>> CreateOrUpdateInstance1(Result<InstanceLaunchRecipe, MinecraftLaunchRecipeCreationFailReason> launchRecipe, CreateOrUpdateInstanceCommand command) {
|
private Task<Result<CreateOrUpdateInstanceResult, InstanceActionFailure>> CreateOrUpdateInstance1(InstanceLaunchRecipe? launchRecipe, CreateOrUpdateInstanceCommand command) {
|
||||||
if (!launchRecipe) {
|
if (launchRecipe == null) {
|
||||||
return Task.FromResult<Result<CreateOrUpdateInstanceResult, InstanceActionFailure>>(launchRecipe.Error switch {
|
// TODO
|
||||||
MinecraftLaunchRecipeCreationFailReason.MinecraftVersionNotFound => CreateOrUpdateInstanceResult.MinecraftVersionNotFound,
|
return Task.FromResult<Result<CreateOrUpdateInstanceResult, InstanceActionFailure>>(CreateOrUpdateInstanceResult.MinecraftVersionDownloadInfoNotFound);
|
||||||
_ => CreateOrUpdateInstanceResult.UnknownError,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var instanceGuid = command.InstanceGuid;
|
|
||||||
var instanceConfiguration = command.Configuration;
|
var instanceConfiguration = command.Configuration;
|
||||||
|
|
||||||
bool isCreatingInstance = !instanceActorByGuid.TryGetValue(instanceGuid, out var instanceActorRef);
|
bool isCreatingInstance = !instanceActorByGuid.TryGetValue(command.InstanceGuid, out var instanceActorRef);
|
||||||
if (isCreatingInstance) {
|
if (isCreatingInstance) {
|
||||||
instanceActorRef = CreateNewInstance(Instance.Offline(instanceGuid, instanceConfiguration));
|
instanceActorRef = CreateNewInstance(Instance.Offline(command.InstanceGuid, instanceConfiguration));
|
||||||
}
|
}
|
||||||
|
|
||||||
var configureInstanceCommand = new InstanceActor.ConfigureInstanceCommand(command.LoggedInUserGuid, instanceGuid, instanceConfiguration, launchRecipe.Value, isCreatingInstance);
|
var configureInstanceCommand = new InstanceActor.ConfigureInstanceCommand(command.LoggedInUserGuid, command.InstanceGuid, instanceConfiguration, launchRecipe, isCreatingInstance);
|
||||||
|
|
||||||
return instanceActorRef.Request(configureInstanceCommand, cancellationToken)
|
return instanceActorRef.Request(configureInstanceCommand, cancellationToken)
|
||||||
.ContinueOnActor(CreateOrUpdateInstance2, configureInstanceCommand);
|
.ContinueOnActor(CreateOrUpdateInstance2, configureInstanceCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable CA2254
|
|
||||||
private Result<CreateOrUpdateInstanceResult, InstanceActionFailure> CreateOrUpdateInstance2(Result<ConfigureInstanceResult, InstanceActionFailure> result, InstanceActor.ConfigureInstanceCommand command) {
|
private Result<CreateOrUpdateInstanceResult, InstanceActionFailure> CreateOrUpdateInstance2(Result<ConfigureInstanceResult, InstanceActionFailure> result, InstanceActor.ConfigureInstanceCommand command) {
|
||||||
var instanceGuid = command.InstanceGuid;
|
var instanceGuid = command.InstanceGuid;
|
||||||
var instanceName = command.Configuration.InstanceName;
|
var instanceName = command.Configuration.InstanceName;
|
||||||
@@ -388,7 +388,6 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
|
|||||||
return CreateOrUpdateInstanceResult.UnknownError;
|
return CreateOrUpdateInstanceResult.UnknownError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma warning restore CA2254
|
|
||||||
|
|
||||||
private void UpdateInstanceStatus(UpdateInstanceStatusCommand command) {
|
private void UpdateInstanceStatus(UpdateInstanceStatusCommand command) {
|
||||||
TellInstance(command.InstanceGuid, new InstanceActor.SetStatusCommand(command.Status));
|
TellInstance(command.InstanceGuid, new InstanceActor.SetStatusCommand(command.Status));
|
||||||
|
|||||||
@@ -52,11 +52,8 @@ sealed class AgentManager(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var agentInfo = registration.AgentInfo;
|
var runtimeInfo = AgentRuntimeInfo.From(registration.AgentInfo);
|
||||||
var agentVersionInfo = new AgentVersionInfo(agentInfo.ProtocolVersion, agentInfo.BuildVersion);
|
return await agentActor.Request(new AgentActor.RegisterCommand(runtimeInfo, registration.JavaRuntimes), cancellationToken);
|
||||||
var agentRuntimeInfo = new AgentRuntimeInfo(agentVersionInfo, agentInfo.MaxInstances, agentInfo.MaxMemory, agentInfo.AllowedServerPorts, agentInfo.AllowedAdditionalPorts);
|
|
||||||
|
|
||||||
return await agentActor.Request(new AgentActor.RegisterCommand(agentRuntimeInfo, registration.JavaRuntimes), cancellationToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<AuthSecret?> GetAgentAuthSecret(Guid agentGuid) {
|
public async Task<AuthSecret?> GetAgentAuthSecret(Guid agentGuid) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
using Phantom.Common.Data.Agent.Instance.Launch;
|
|
||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance;
|
||||||
|
using Phantom.Common.Data.Instance.Launch;
|
||||||
using Phantom.Common.Data.Minecraft;
|
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;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using Phantom.Common.Data.Minecraft;
|
using Phantom.Common.Data.Instance;
|
||||||
using Phantom.Common.Data.Web.Instance;
|
using Phantom.Common.Data.Minecraft;
|
||||||
using Phantom.Common.Data.Web.Minecraft;
|
using Phantom.Common.Data.Web.Minecraft;
|
||||||
using Phantom.Controller.Database;
|
using Phantom.Controller.Database;
|
||||||
using Phantom.Controller.Database.Entities;
|
using Phantom.Controller.Database.Entities;
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
using Phantom.Common.Data.Agent.Instance;
|
|
||||||
using Phantom.Common.Data.Web.Instance;
|
|
||||||
|
|
||||||
namespace Phantom.Controller.Services.Instances;
|
|
||||||
|
|
||||||
static class InstanceExtensions {
|
|
||||||
extension(InstanceConfiguration configuration) {
|
|
||||||
public InstanceInfo AsInfo => new (configuration.InstanceName, configuration.ServerPort, [configuration.RconPort], configuration.MemoryAllocation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
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.AuditLog;
|
using Phantom.Common.Data.Web.AuditLog;
|
||||||
using Phantom.Common.Data.Web.EventLog;
|
using Phantom.Common.Data.Web.EventLog;
|
||||||
using Phantom.Common.Data.Web.Instance;
|
using Phantom.Common.Data.Web.Instance;
|
||||||
using Phantom.Common.Data.Web.Minecraft;
|
|
||||||
using Phantom.Common.Data.Web.Users;
|
using Phantom.Common.Data.Web.Users;
|
||||||
using Phantom.Common.Messages.Web;
|
using Phantom.Common.Messages.Web;
|
||||||
using Phantom.Common.Messages.Web.ToController;
|
using Phantom.Common.Messages.Web.ToController;
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Phantom.Agent.Services", "A
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Phantom.Common.Data", "Common\Phantom.Common.Data\Phantom.Common.Data.csproj", "{6C3DB1E5-F695-4D70-8F3A-78C2957274BE}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Phantom.Common.Data", "Common\Phantom.Common.Data\Phantom.Common.Data.csproj", "{6C3DB1E5-F695-4D70-8F3A-78C2957274BE}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Phantom.Common.Data.Agent", "Common\Phantom.Common.Data.Agent\Phantom.Common.Data.Agent.csproj", "{6EB98B08-19B2-4726-B313-19C4FDA6F89F}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Phantom.Common.Data.Tests", "Common\Phantom.Common.Data.Tests\Phantom.Common.Data.Tests.csproj", "{435D7981-DFDA-46A0-8CD8-CD8C117935D7}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Phantom.Common.Data.Tests", "Common\Phantom.Common.Data.Tests\Phantom.Common.Data.Tests.csproj", "{435D7981-DFDA-46A0-8CD8-CD8C117935D7}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Phantom.Common.Data.Web", "Common\Phantom.Common.Data.Web\Phantom.Common.Data.Web.csproj", "{BC969D0B-0019-48E0-9FAF-F5CC906AAF09}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Phantom.Common.Data.Web", "Common\Phantom.Common.Data.Web\Phantom.Common.Data.Web.csproj", "{BC969D0B-0019-48E0-9FAF-F5CC906AAF09}"
|
||||||
@@ -92,10 +90,6 @@ Global
|
|||||||
{6C3DB1E5-F695-4D70-8F3A-78C2957274BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{6C3DB1E5-F695-4D70-8F3A-78C2957274BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{6C3DB1E5-F695-4D70-8F3A-78C2957274BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{6C3DB1E5-F695-4D70-8F3A-78C2957274BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{6C3DB1E5-F695-4D70-8F3A-78C2957274BE}.Release|Any CPU.Build.0 = Release|Any CPU
|
{6C3DB1E5-F695-4D70-8F3A-78C2957274BE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{6EB98B08-19B2-4726-B313-19C4FDA6F89F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{6EB98B08-19B2-4726-B313-19C4FDA6F89F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{6EB98B08-19B2-4726-B313-19C4FDA6F89F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{6EB98B08-19B2-4726-B313-19C4FDA6F89F}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{435D7981-DFDA-46A0-8CD8-CD8C117935D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{435D7981-DFDA-46A0-8CD8-CD8C117935D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{435D7981-DFDA-46A0-8CD8-CD8C117935D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{435D7981-DFDA-46A0-8CD8-CD8C117935D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{435D7981-DFDA-46A0-8CD8-CD8C117935D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{435D7981-DFDA-46A0-8CD8-CD8C117935D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
@@ -175,7 +169,6 @@ Global
|
|||||||
{065FFFA0-DFF4-43DB-AB3D-B92EE9848DDB} = {94C1E464-3F91-49EA-99FF-3A3082C54CE8}
|
{065FFFA0-DFF4-43DB-AB3D-B92EE9848DDB} = {94C1E464-3F91-49EA-99FF-3A3082C54CE8}
|
||||||
{AEE8B77E-AB07-423F-9981-8CD829ACB834} = {F5878792-64C8-4ECF-A075-66341FF97127}
|
{AEE8B77E-AB07-423F-9981-8CD829ACB834} = {F5878792-64C8-4ECF-A075-66341FF97127}
|
||||||
{6C3DB1E5-F695-4D70-8F3A-78C2957274BE} = {01CB1A81-8950-471C-BFDF-F135FDDB2C18}
|
{6C3DB1E5-F695-4D70-8F3A-78C2957274BE} = {01CB1A81-8950-471C-BFDF-F135FDDB2C18}
|
||||||
{6EB98B08-19B2-4726-B313-19C4FDA6F89F} = {01CB1A81-8950-471C-BFDF-F135FDDB2C18}
|
|
||||||
{95B55357-F8F0-48C2-A1C2-5EA997651783} = {01CB1A81-8950-471C-BFDF-F135FDDB2C18}
|
{95B55357-F8F0-48C2-A1C2-5EA997651783} = {01CB1A81-8950-471C-BFDF-F135FDDB2C18}
|
||||||
{6E798DEB-8921-41A2-8AFB-E4416A9E0704} = {01CB1A81-8950-471C-BFDF-F135FDDB2C18}
|
{6E798DEB-8921-41A2-8AFB-E4416A9E0704} = {01CB1A81-8950-471C-BFDF-F135FDDB2C18}
|
||||||
{435D7981-DFDA-46A0-8CD8-CD8C117935D7} = {D781E00D-8563-4102-A0CD-477A679193B5}
|
{435D7981-DFDA-46A0-8CD8-CD8C117935D7} = {D781E00D-8563-4102-A0CD-477A679193B5}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
|
using Phantom.Common.Data.Instance;
|
||||||
using Phantom.Common.Data.Minecraft;
|
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;
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
@using System.ComponentModel.DataAnnotations
|
@using System.ComponentModel.DataAnnotations
|
||||||
@using System.Diagnostics.CodeAnalysis
|
@using System.Diagnostics.CodeAnalysis
|
||||||
@using Phantom.Common.Data
|
@using Phantom.Common.Data
|
||||||
|
@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
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
@using System.Diagnostics
|
@using Phantom.Utils.Collections
|
||||||
@using Phantom.Common.Data.Web.Users
|
|
||||||
@using Phantom.Utils.Collections
|
|
||||||
@using Phantom.Utils.Events
|
@using Phantom.Utils.Events
|
||||||
|
@using System.Diagnostics
|
||||||
@using Phantom.Web.Services.Instances
|
@using Phantom.Web.Services.Instances
|
||||||
@inherits PhantomComponent
|
@using Phantom.Common.Data.Web.Users
|
||||||
|
@inherits Phantom.Web.Components.PhantomComponent
|
||||||
@inject IJSRuntime Js;
|
@inject IJSRuntime Js;
|
||||||
@inject InstanceLogManager InstanceLogManager;
|
@inject InstanceLogManager InstanceLogManager;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Phantom.Common.Data.Instance;
|
using Phantom.Common.Data.Instance.Launch;
|
||||||
using Phantom.Common.Data.Replies;
|
using Phantom.Common.Data.Replies;
|
||||||
using Phantom.Common.Data.Web.Minecraft;
|
using Phantom.Common.Data.Web.Minecraft;
|
||||||
using Phantom.Common.Data.Web.Users;
|
using Phantom.Common.Data.Web.Users;
|
||||||
|
|||||||
Reference in New Issue
Block a user