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