mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2024-11-26 10:42:52 +01:00
Compare commits
No commits in common. "46dba1a4fa93e8c36173b480cffdfd25c5822d23" and "2180e0c067028a3638a8de0d3a4ff9b143ee68ef" have entirely different histories.
46dba1a4fa
...
2180e0c067
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.Immutable;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Java;
|
namespace Phantom.Agent.Minecraft.Java;
|
||||||
|
|
||||||
@ -6,12 +7,12 @@ sealed class JvmArgumentBuilder {
|
|||||||
private readonly JvmProperties basicProperties;
|
private readonly JvmProperties basicProperties;
|
||||||
private readonly List<string> customArguments = new ();
|
private readonly List<string> customArguments = new ();
|
||||||
|
|
||||||
public JvmArgumentBuilder(JvmProperties basicProperties) {
|
public JvmArgumentBuilder(JvmProperties basicProperties, ImmutableArray<string> customArguments) {
|
||||||
this.basicProperties = basicProperties;
|
this.basicProperties = basicProperties;
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(string argument) {
|
foreach (var jvmArgument in customArguments) {
|
||||||
customArguments.Add(argument);
|
this.customArguments.Add(jvmArgument);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddProperty(string key, string value) {
|
public void AddProperty(string key, string value) {
|
||||||
@ -23,8 +24,8 @@ sealed class JvmArgumentBuilder {
|
|||||||
target.Add(property);
|
target.Add(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
// In case of duplicate JVM arguments, typically the last one wins.
|
|
||||||
target.Add("-Xms" + basicProperties.InitialHeapMegabytes + "M");
|
target.Add("-Xms" + basicProperties.InitialHeapMegabytes + "M");
|
||||||
target.Add("-Xmx" + basicProperties.MaximumHeapMegabytes + "M");
|
target.Add("-Xmx" + basicProperties.MaximumHeapMegabytes + "M");
|
||||||
|
target.Add("-Xrs");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
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.Java;
|
||||||
using Phantom.Utils.Runtime;
|
using Phantom.Utils.Runtime;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
@ -21,6 +22,10 @@ public abstract class BaseLauncher : IServerLauncher {
|
|||||||
return new LaunchResult.InvalidJavaRuntime();
|
return new LaunchResult.InvalidJavaRuntime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (JvmArgumentsHelper.Validate(instanceProperties.JvmArguments) != null) {
|
||||||
|
return new LaunchResult.InvalidJvmArguments();
|
||||||
|
}
|
||||||
|
|
||||||
var vanillaServerJarPath = await services.ServerExecutables.DownloadAndGetPath(instanceProperties.LaunchProperties.ServerDownloadInfo, MinecraftVersion, downloadProgressEventHandler, cancellationToken);
|
var vanillaServerJarPath = await services.ServerExecutables.DownloadAndGetPath(instanceProperties.LaunchProperties.ServerDownloadInfo, MinecraftVersion, downloadProgressEventHandler, cancellationToken);
|
||||||
if (vanillaServerJarPath == null) {
|
if (vanillaServerJarPath == null) {
|
||||||
return new LaunchResult.CouldNotDownloadMinecraftServer();
|
return new LaunchResult.CouldNotDownloadMinecraftServer();
|
||||||
@ -56,8 +61,16 @@ public abstract class BaseLauncher : IServerLauncher {
|
|||||||
UseShellExecute = false
|
UseShellExecute = false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var jvmArguments = new JvmArgumentBuilder(instanceProperties.JvmProperties, instanceProperties.JvmArguments);
|
||||||
|
CustomizeJvmArguments(jvmArguments);
|
||||||
|
|
||||||
var processArguments = processConfigurator.ArgumentList;
|
var processArguments = processConfigurator.ArgumentList;
|
||||||
PrepareJvmArguments(serverJar).Build(processArguments);
|
jvmArguments.Build(processArguments);
|
||||||
|
|
||||||
|
foreach (var extraArgument in serverJar.ExtraArgs) {
|
||||||
|
processArguments.Add(extraArgument);
|
||||||
|
}
|
||||||
|
|
||||||
processArguments.Add("-jar");
|
processArguments.Add("-jar");
|
||||||
processArguments.Add(serverJar.FilePath);
|
processArguments.Add(serverJar.FilePath);
|
||||||
processArguments.Add("nogui");
|
processArguments.Add("nogui");
|
||||||
@ -82,21 +95,6 @@ public abstract class BaseLauncher : IServerLauncher {
|
|||||||
return new LaunchResult.Success(instanceProcess);
|
return new LaunchResult.Success(instanceProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
private JvmArgumentBuilder PrepareJvmArguments(ServerJarInfo serverJar) {
|
|
||||||
var builder = new JvmArgumentBuilder(instanceProperties.JvmProperties);
|
|
||||||
|
|
||||||
foreach (string argument in instanceProperties.JvmArguments) {
|
|
||||||
builder.Add(argument);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var argument in serverJar.ExtraArgs) {
|
|
||||||
builder.Add(argument);
|
|
||||||
}
|
|
||||||
|
|
||||||
CustomizeJvmArguments(builder);
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
private protected virtual void CustomizeJvmArguments(JvmArgumentBuilder arguments) {}
|
private protected virtual void CustomizeJvmArguments(JvmArgumentBuilder arguments) {}
|
||||||
|
|
||||||
private protected virtual Task<ServerJarInfo> PrepareServerJar(ILogger logger, string serverJarPath, CancellationToken cancellationToken) {
|
private protected virtual Task<ServerJarInfo> PrepareServerJar(ILogger logger, string serverJarPath, CancellationToken cancellationToken) {
|
||||||
|
@ -9,6 +9,8 @@ public abstract record LaunchResult {
|
|||||||
|
|
||||||
public sealed record InvalidJavaRuntime : LaunchResult;
|
public sealed record InvalidJavaRuntime : LaunchResult;
|
||||||
|
|
||||||
|
public sealed record InvalidJvmArguments : LaunchResult;
|
||||||
|
|
||||||
public sealed record CouldNotDownloadMinecraftServer : LaunchResult;
|
public sealed record CouldNotDownloadMinecraftServer : LaunchResult;
|
||||||
|
|
||||||
public sealed record CouldNotPrepareMinecraftServerLauncher : LaunchResult;
|
public sealed record CouldNotPrepareMinecraftServerLauncher : LaunchResult;
|
||||||
|
@ -63,6 +63,9 @@ sealed record LaunchInstanceProcedure(InstanceConfiguration Configuration, IServ
|
|||||||
if (launchResult is LaunchResult.InvalidJavaRuntime) {
|
if (launchResult is LaunchResult.InvalidJavaRuntime) {
|
||||||
throw new LaunchFailureException(InstanceLaunchFailReason.JavaRuntimeNotFound, "Session failed to launch, invalid Java runtime.");
|
throw new LaunchFailureException(InstanceLaunchFailReason.JavaRuntimeNotFound, "Session failed to launch, invalid Java runtime.");
|
||||||
}
|
}
|
||||||
|
else if (launchResult is LaunchResult.InvalidJvmArguments) {
|
||||||
|
throw new LaunchFailureException(InstanceLaunchFailReason.InvalidJvmArguments, "Session failed to launch, invalid JVM arguments.");
|
||||||
|
}
|
||||||
else if (launchResult is LaunchResult.CouldNotDownloadMinecraftServer) {
|
else if (launchResult is LaunchResult.CouldNotDownloadMinecraftServer) {
|
||||||
throw new LaunchFailureException(InstanceLaunchFailReason.CouldNotDownloadMinecraftServer, "Session failed to launch, could not download Minecraft server.");
|
throw new LaunchFailureException(InstanceLaunchFailReason.CouldNotDownloadMinecraftServer, "Session failed to launch, could not download Minecraft server.");
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
namespace Phantom.Common.Data.Instance;
|
namespace Phantom.Common.Data.Instance;
|
||||||
|
|
||||||
public enum InstanceLaunchFailReason : byte {
|
public enum InstanceLaunchFailReason : byte {
|
||||||
UnknownError = 0,
|
UnknownError,
|
||||||
ServerPortNotAllowed = 1,
|
ServerPortNotAllowed,
|
||||||
ServerPortAlreadyInUse = 2,
|
ServerPortAlreadyInUse,
|
||||||
RconPortNotAllowed = 3,
|
RconPortNotAllowed,
|
||||||
RconPortAlreadyInUse = 4,
|
RconPortAlreadyInUse,
|
||||||
JavaRuntimeNotFound = 5,
|
JavaRuntimeNotFound,
|
||||||
CouldNotDownloadMinecraftServer = 6,
|
InvalidJvmArguments,
|
||||||
CouldNotConfigureMinecraftServer = 7,
|
CouldNotDownloadMinecraftServer,
|
||||||
CouldNotPrepareMinecraftServerLauncher = 8,
|
CouldNotConfigureMinecraftServer,
|
||||||
CouldNotStartMinecraftServer = 9
|
CouldNotPrepareMinecraftServerLauncher,
|
||||||
|
CouldNotStartMinecraftServer
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class InstanceLaunchFailReasonExtensions {
|
public static class InstanceLaunchFailReasonExtensions {
|
||||||
@ -21,6 +22,7 @@ public static class InstanceLaunchFailReasonExtensions {
|
|||||||
InstanceLaunchFailReason.RconPortNotAllowed => "Rcon port not allowed.",
|
InstanceLaunchFailReason.RconPortNotAllowed => "Rcon port not allowed.",
|
||||||
InstanceLaunchFailReason.RconPortAlreadyInUse => "Rcon port already in use.",
|
InstanceLaunchFailReason.RconPortAlreadyInUse => "Rcon port already in use.",
|
||||||
InstanceLaunchFailReason.JavaRuntimeNotFound => "Java runtime not found.",
|
InstanceLaunchFailReason.JavaRuntimeNotFound => "Java runtime not found.",
|
||||||
|
InstanceLaunchFailReason.InvalidJvmArguments => "Invalid JVM arguments.",
|
||||||
InstanceLaunchFailReason.CouldNotDownloadMinecraftServer => "Could not download Minecraft server.",
|
InstanceLaunchFailReason.CouldNotDownloadMinecraftServer => "Could not download Minecraft server.",
|
||||||
InstanceLaunchFailReason.CouldNotConfigureMinecraftServer => "Could not configure Minecraft server.",
|
InstanceLaunchFailReason.CouldNotConfigureMinecraftServer => "Could not configure Minecraft server.",
|
||||||
InstanceLaunchFailReason.CouldNotPrepareMinecraftServerLauncher => "Could not prepare Minecraft server launcher.",
|
InstanceLaunchFailReason.CouldNotPrepareMinecraftServerLauncher => "Could not prepare Minecraft server launcher.",
|
||||||
|
@ -1,21 +1,17 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
|
||||||
namespace Phantom.Server.Minecraft;
|
namespace Phantom.Common.Data.Java;
|
||||||
|
|
||||||
public static class JvmArgumentsHelper {
|
public static class JvmArgumentsHelper {
|
||||||
public static ImmutableArray<string> Split(string arguments) {
|
public static ImmutableArray<string> Split(string arguments) {
|
||||||
return arguments.Split('\n', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries).ToImmutableArray();
|
return arguments.Split('\n', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries).ToImmutableArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string Join(ImmutableArray<string> arguments) {
|
|
||||||
return string.Join('\n', arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ValidationError? Validate(string arguments) {
|
public static ValidationError? Validate(string arguments) {
|
||||||
return Validate(Split(arguments));
|
return Validate(Split(arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ValidationError? Validate(ImmutableArray<string> arguments) {
|
public static ValidationError? Validate(ImmutableArray<string> arguments) {
|
||||||
if (!arguments.All(static argument => argument.StartsWith('-'))) {
|
if (!arguments.All(static argument => argument.StartsWith('-'))) {
|
||||||
return ValidationError.InvalidFormat;
|
return ValidationError.InvalidFormat;
|
||||||
}
|
}
|
||||||
@ -32,6 +28,10 @@ public static class JvmArgumentsHelper {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string Join(ImmutableArray<string> arguments) {
|
||||||
|
return string.Join('\n', arguments);
|
||||||
|
}
|
||||||
|
|
||||||
public enum ValidationError {
|
public enum ValidationError {
|
||||||
InvalidFormat,
|
InvalidFormat,
|
||||||
XmxNotAllowed,
|
XmxNotAllowed,
|
Loading…
Reference in New Issue
Block a user