mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-09-14 12:32:11 +02:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
591a6a62ab
|
|||
ae32537d8c
|
@@ -1,5 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
using Phantom.Agent.Minecraft.Instance;
|
||||
using Phantom.Agent.Minecraft.Java;
|
||||
using Phantom.Agent.Minecraft.Server;
|
||||
@@ -12,7 +11,6 @@ public abstract class BaseLauncher : IServerLauncher {
|
||||
private readonly InstanceProperties instanceProperties;
|
||||
|
||||
protected string MinecraftVersion => instanceProperties.ServerVersion;
|
||||
protected string InstanceFolder => instanceProperties.InstanceFolder;
|
||||
|
||||
private protected BaseLauncher(InstanceProperties instanceProperties) {
|
||||
this.instanceProperties = instanceProperties;
|
||||
@@ -53,14 +51,16 @@ public abstract class BaseLauncher : IServerLauncher {
|
||||
|
||||
var processConfigurator = new ProcessConfigurator {
|
||||
FileName = javaRuntimeExecutable.ExecutablePath,
|
||||
WorkingDirectory = InstanceFolder,
|
||||
WorkingDirectory = instanceProperties.InstanceFolder,
|
||||
RedirectInput = true,
|
||||
UseShellExecute = false
|
||||
};
|
||||
|
||||
var processArguments = processConfigurator.ArgumentList;
|
||||
PrepareJvmArguments(serverJar).Build(processArguments);
|
||||
PrepareJavaProcessArguments(processArguments, serverJar.FilePath);
|
||||
processArguments.Add("-jar");
|
||||
processArguments.Add(serverJar.FilePath);
|
||||
processArguments.Add("nogui");
|
||||
|
||||
var process = processConfigurator.CreateProcess();
|
||||
var instanceProcess = new InstanceProcess(instanceProperties, process);
|
||||
@@ -99,12 +99,6 @@ public abstract class BaseLauncher : IServerLauncher {
|
||||
|
||||
private protected virtual void CustomizeJvmArguments(JvmArgumentBuilder arguments) {}
|
||||
|
||||
protected virtual void PrepareJavaProcessArguments(Collection<string> processArguments, string serverJarFilePath) {
|
||||
processArguments.Add("-jar");
|
||||
processArguments.Add(serverJarFilePath);
|
||||
processArguments.Add("nogui");
|
||||
}
|
||||
|
||||
private protected virtual Task<ServerJarInfo> PrepareServerJar(ILogger logger, string serverJarPath, CancellationToken cancellationToken) {
|
||||
return Task.FromResult(new ServerJarInfo(serverJarPath));
|
||||
}
|
||||
|
@@ -1,29 +0,0 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Phantom.Agent.Minecraft.Instance;
|
||||
using Phantom.Agent.Minecraft.Java;
|
||||
using Serilog;
|
||||
|
||||
namespace Phantom.Agent.Minecraft.Launcher.Types;
|
||||
|
||||
public sealed class ForgeLauncher : BaseLauncher {
|
||||
public ForgeLauncher(InstanceProperties instanceProperties) : base(instanceProperties) {}
|
||||
|
||||
private protected override void CustomizeJvmArguments(JvmArgumentBuilder arguments) {
|
||||
arguments.AddProperty("terminal.ansi", "true"); // TODO
|
||||
}
|
||||
|
||||
protected override void PrepareJavaProcessArguments(Collection<string> processArguments, string serverJarFilePath) {
|
||||
if (OperatingSystem.IsWindows()) {
|
||||
processArguments.Add("@libraries/net/minecraftforge/forge/1.20.1-47.2.0/win_args.txt");
|
||||
}
|
||||
else {
|
||||
processArguments.Add("@libraries/net/minecraftforge/forge/1.20.1-47.2.0/unix_args.txt");
|
||||
}
|
||||
|
||||
processArguments.Add("nogui");
|
||||
}
|
||||
|
||||
private protected override Task<ServerJarInfo> PrepareServerJar(ILogger logger, string serverJarPath, CancellationToken cancellationToken) {
|
||||
return Task.FromResult(new ServerJarInfo(Path.Combine(InstanceFolder, "run.sh")));
|
||||
}
|
||||
}
|
@@ -25,7 +25,7 @@ sealed class BackupArchiver {
|
||||
}
|
||||
|
||||
private bool IsFolderSkipped(ImmutableList<string> relativePath) {
|
||||
return relativePath is ["cache" or "crash-reports" or "debug" or "libraries" or "logs" or "mods" or "servermods" or "versions"];
|
||||
return relativePath is ["cache" or "crash-reports" or "debug" or "libraries" or "logs" or "mods" or "versions"];
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "ConvertIfStatementToReturnStatement")]
|
||||
|
@@ -102,7 +102,6 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
||||
IServerLauncher launcher = configuration.MinecraftServerKind switch {
|
||||
MinecraftServerKind.Vanilla => new VanillaLauncher(properties),
|
||||
MinecraftServerKind.Fabric => new FabricLauncher(properties),
|
||||
MinecraftServerKind.Forge => new ForgeLauncher(properties),
|
||||
_ => InvalidLauncher.Instance
|
||||
};
|
||||
|
||||
|
@@ -5,7 +5,6 @@ using Phantom.Common.Data.Instance;
|
||||
using Phantom.Common.Data.Replies;
|
||||
using Phantom.Common.Messages.Agent.ToController;
|
||||
using Phantom.Utils.Logging;
|
||||
using Phantom.Utils.Tasks;
|
||||
using Serilog;
|
||||
|
||||
namespace Phantom.Agent.Services.Instances;
|
||||
|
@@ -2,6 +2,5 @@
|
||||
|
||||
public enum MinecraftServerKind : ushort {
|
||||
Vanilla = 1,
|
||||
Fabric = 2,
|
||||
Forge = 3
|
||||
Fabric = 2
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Immutable;
|
||||
using Phantom.Common.Data;
|
||||
using Phantom.Common.Data.Web.Users;
|
||||
using Phantom.Common.Data.Web.Users.CreateOrUpdateAdministratorUserResults;
|
||||
using Phantom.Controller.Database;
|
||||
using Phantom.Controller.Database.Entities;
|
||||
using Phantom.Controller.Database.Repositories;
|
||||
@@ -56,12 +57,12 @@ sealed class UserManager {
|
||||
wasCreated = true;
|
||||
}
|
||||
else {
|
||||
return new Common.Data.Web.Users.CreateOrUpdateAdministratorUserResults.CreationFailed(result.Error);
|
||||
return new CreationFailed(result.Error);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (userRepository.SetUserPassword(user, password).TryGetError(out var error)) {
|
||||
return new Common.Data.Web.Users.CreateOrUpdateAdministratorUserResults.UpdatingFailed(error);
|
||||
return new UpdatingFailed(error);
|
||||
}
|
||||
|
||||
auditLogWriter.AdministratorUserModified(user);
|
||||
@@ -70,7 +71,7 @@ sealed class UserManager {
|
||||
|
||||
var role = await new RoleRepository(db).GetByGuid(Role.Administrator.Guid);
|
||||
if (role == null) {
|
||||
return new Common.Data.Web.Users.CreateOrUpdateAdministratorUserResults.AddingToRoleFailed();
|
||||
return new AddingToRoleFailed();
|
||||
}
|
||||
|
||||
await new UserRoleRepository(db).Add(user, role);
|
||||
@@ -84,10 +85,10 @@ sealed class UserManager {
|
||||
Logger.Information("Updated administrator user \"{Username}\" (GUID {Guid}).", username, user.UserGuid);
|
||||
}
|
||||
|
||||
return new Common.Data.Web.Users.CreateOrUpdateAdministratorUserResults.Success(user.ToUserInfo());
|
||||
return new Success(user.ToUserInfo());
|
||||
} catch (Exception e) {
|
||||
Logger.Error(e, "Could not create or update administrator user \"{Username}\".", username);
|
||||
return new Common.Data.Web.Users.CreateOrUpdateAdministratorUserResults.UnknownError();
|
||||
return new UnknownError();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<LangVersion>11</LangVersion>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<LangVersion>13</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
# +---------------+
|
||||
# | Prepare build |
|
||||
# +---------------+
|
||||
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/nightly/sdk:8.0 AS phantom-builder
|
||||
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/nightly/sdk:9.0 AS phantom-builder
|
||||
ARG TARGETARCH
|
||||
|
||||
ADD . /app
|
||||
@@ -19,7 +19,7 @@ RUN find .artifacts/publish/*/* -maxdepth 0 -execdir mv '{}' 'release' \;
|
||||
# +---------------------+
|
||||
# | Phantom Agent image |
|
||||
# +---------------------+
|
||||
FROM mcr.microsoft.com/dotnet/nightly/runtime:8.0 AS phantom-agent
|
||||
FROM mcr.microsoft.com/dotnet/nightly/runtime:9.0 AS phantom-agent
|
||||
|
||||
RUN mkdir /data && chmod 777 /data
|
||||
WORKDIR /data
|
||||
@@ -46,7 +46,7 @@ ENTRYPOINT ["dotnet", "/app/Phantom.Agent.dll"]
|
||||
# +--------------------------+
|
||||
# | Phantom Controller image |
|
||||
# +--------------------------+
|
||||
FROM mcr.microsoft.com/dotnet/nightly/runtime:8.0 AS phantom-controller
|
||||
FROM mcr.microsoft.com/dotnet/nightly/runtime:9.0 AS phantom-controller
|
||||
|
||||
RUN mkdir /data && chmod 777 /data
|
||||
WORKDIR /data
|
||||
@@ -59,7 +59,7 @@ ENTRYPOINT ["dotnet", "/app/Phantom.Controller.dll"]
|
||||
# +-------------------+
|
||||
# | Phantom Web image |
|
||||
# +-------------------+
|
||||
FROM mcr.microsoft.com/dotnet/nightly/aspnet:8.0 AS phantom-web
|
||||
FROM mcr.microsoft.com/dotnet/nightly/aspnet:9.0 AS phantom-web
|
||||
|
||||
RUN mkdir /data && chmod 777 /data
|
||||
WORKDIR /data
|
||||
|
@@ -1,6 +1,6 @@
|
||||
@using Phantom.Web.Services.Authentication
|
||||
@using Phantom.Common.Data.Web.Users
|
||||
@using Phantom.Web.Services
|
||||
@using Phantom.Common.Data.Web.Users
|
||||
@using Phantom.Web.Services.Authentication
|
||||
@inject ApplicationProperties ApplicationProperties
|
||||
|
||||
<div class="navbar navbar-dark">
|
||||
|
@@ -3,8 +3,8 @@
|
||||
@using System.Collections.Immutable
|
||||
@using Phantom.Common.Data.Web.AuditLog
|
||||
@using Phantom.Common.Data.Web.Users
|
||||
@using Phantom.Web.Services.Users
|
||||
@using Phantom.Web.Services.Instances
|
||||
@using Phantom.Web.Services.Users
|
||||
@inherits PhantomComponent
|
||||
@inject AuditLogManager AuditLogManager
|
||||
@inject InstanceManager InstanceManager
|
||||
|
@@ -6,7 +6,7 @@
|
||||
@using Phantom.Web.Services.Agents
|
||||
@using Phantom.Web.Services.Events
|
||||
@using Phantom.Web.Services.Instances
|
||||
@inherits Phantom.Web.Components.PhantomComponent
|
||||
@inherits PhantomComponent
|
||||
@inject AgentManager AgentManager
|
||||
@inject EventLogManager EventLogManager
|
||||
@inject InstanceManager InstanceManager
|
||||
|
@@ -1,5 +1,5 @@
|
||||
@page "/"
|
||||
@inherits Phantom.Web.Components.PhantomComponent
|
||||
@inherits PhantomComponent
|
||||
|
||||
<h1>Home</h1>
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
@page "/login"
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using Phantom.Web.Services
|
||||
@using Phantom.Web.Services.Authentication
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@attribute [AllowAnonymous]
|
||||
@inject Navigation Navigation
|
||||
@inject UserLoginManager LoginManager
|
||||
|
@@ -1,4 +1,6 @@
|
||||
@page "/setup"
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using System.Security.Cryptography
|
||||
@using Phantom.Common.Data
|
||||
@using Phantom.Common.Data.Web.Users
|
||||
@using Phantom.Common.Data.Web.Users.CreateOrUpdateAdministratorUserResults
|
||||
@@ -7,8 +9,6 @@
|
||||
@using Phantom.Web.Services
|
||||
@using Phantom.Web.Services.Authentication
|
||||
@using Phantom.Web.Services.Rpc
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using System.Security.Cryptography
|
||||
@attribute [AllowAnonymous]
|
||||
@inject ApplicationProperties ApplicationProperties
|
||||
@inject UserLoginManager LoginManager
|
||||
|
@@ -1,11 +1,11 @@
|
||||
@page "/users"
|
||||
@attribute [Authorize(Permission.ViewUsersPolicy)]
|
||||
@using System.Collections.Immutable
|
||||
@using Phantom.Common.Data.Web.Users
|
||||
@using Phantom.Web.Services.Authentication
|
||||
@using Phantom.Web.Services.Authorization
|
||||
@using Phantom.Web.Services.Users
|
||||
@using Phantom.Common.Data.Web.Users
|
||||
@inherits Phantom.Web.Components.PhantomComponent
|
||||
@inherits PhantomComponent
|
||||
@inject UserManager UserManager
|
||||
@inject RoleManager RoleManager
|
||||
@inject UserRoleManager UserRoleManager
|
||||
|
@@ -2,22 +2,27 @@
|
||||
using Phantom.Common.Data.Replies;
|
||||
using Phantom.Common.Data.Web.Minecraft;
|
||||
using Phantom.Common.Data.Web.Users;
|
||||
using Phantom.Common.Data.Web.Users.AddUserErrors;
|
||||
using Phantom.Common.Data.Web.Users.PasswordRequirementViolations;
|
||||
using Phantom.Common.Data.Web.Users.SetUserPasswordErrors;
|
||||
using Phantom.Common.Data.Web.Users.UsernameRequirementViolations;
|
||||
using PasswordIsInvalid = Phantom.Common.Data.Web.Users.AddUserErrors.PasswordIsInvalid;
|
||||
|
||||
namespace Phantom.Web.Utils;
|
||||
|
||||
static class Messages {
|
||||
public static string ToSentences(this AddUserError error, string delimiter) {
|
||||
return error switch {
|
||||
Common.Data.Web.Users.AddUserErrors.NameIsInvalid e => e.Violation.ToSentence(),
|
||||
Common.Data.Web.Users.AddUserErrors.PasswordIsInvalid e => string.Join(delimiter, e.Violations.Select(static v => v.ToSentence())),
|
||||
Common.Data.Web.Users.AddUserErrors.NameAlreadyExists => "Username is already occupied.",
|
||||
NameIsInvalid e => e.Violation.ToSentence(),
|
||||
PasswordIsInvalid e => string.Join(delimiter, e.Violations.Select(static v => v.ToSentence())),
|
||||
NameAlreadyExists => "Username is already occupied.",
|
||||
_ => "Unknown error."
|
||||
};
|
||||
}
|
||||
|
||||
public static string ToSentences(this SetUserPasswordError error, string delimiter) {
|
||||
return error switch {
|
||||
Common.Data.Web.Users.SetUserPasswordErrors.UserNotFound => "User not found.",
|
||||
UserNotFound => "User not found.",
|
||||
Common.Data.Web.Users.SetUserPasswordErrors.PasswordIsInvalid e => string.Join(delimiter, e.Violations.Select(static v => v.ToSentence())),
|
||||
_ => "Unknown error."
|
||||
};
|
||||
@@ -25,18 +30,18 @@ static class Messages {
|
||||
|
||||
public static string ToSentence(this UsernameRequirementViolation violation) {
|
||||
return violation switch {
|
||||
Common.Data.Web.Users.UsernameRequirementViolations.IsEmpty => "Username must not be empty.",
|
||||
Common.Data.Web.Users.UsernameRequirementViolations.TooLong v => "Username must not be longer than " + v.MaxLength + " character(s).",
|
||||
IsEmpty => "Username must not be empty.",
|
||||
TooLong v => "Username must not be longer than " + v.MaxLength + " character(s).",
|
||||
_ => "Unknown error."
|
||||
};
|
||||
}
|
||||
|
||||
public static string ToSentence(this PasswordRequirementViolation violation) {
|
||||
return violation switch {
|
||||
Common.Data.Web.Users.PasswordRequirementViolations.TooShort v => "Password must be at least " + v.MinimumLength + " character(s) long.",
|
||||
Common.Data.Web.Users.PasswordRequirementViolations.MustContainLowercaseLetter => "Password must contain a lowercase letter.",
|
||||
Common.Data.Web.Users.PasswordRequirementViolations.MustContainUppercaseLetter => "Password must contain an uppercase letter.",
|
||||
Common.Data.Web.Users.PasswordRequirementViolations.MustContainDigit => "Password must contain a digit.",
|
||||
TooShort v => "Password must be at least " + v.MinimumLength + " character(s) long.",
|
||||
MustContainLowercaseLetter => "Password must contain a lowercase letter.",
|
||||
MustContainUppercaseLetter => "Password must contain an uppercase letter.",
|
||||
MustContainDigit => "Password must contain a digit.",
|
||||
_ => "Unknown error."
|
||||
};
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "8.0.0",
|
||||
"version": "9.0.0",
|
||||
"rollForward": "latestMinor",
|
||||
"allowPrerelease": true
|
||||
}
|
||||
|
Reference in New Issue
Block a user