1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2026-02-25 11:08:17 +01:00
Files
Minecraft-Phantom-Panel/Web/Phantom.Web/Utils/Messages.cs

94 lines
4.7 KiB
C#

using Phantom.Common.Data.Instance;
using Phantom.Common.Data.Replies;
using Phantom.Common.Data.Web.Minecraft;
using Phantom.Common.Data.Web.Users;
namespace Phantom.Web.Utils;
static class Messages {
public static string ToSentences(this AddUserError error, string delimiter) {
return error switch {
AddUserError.NameIsInvalid e => e.Violation.ToSentence(),
AddUserError.PasswordIsInvalid e => string.Join(delimiter, e.Violations.Select(static v => v.ToSentence())),
AddUserError.NameAlreadyExists => "Username is already occupied.",
_ => "Unknown error.",
};
}
public static string ToSentences(this SetUserPasswordError error, string delimiter) {
return error switch {
SetUserPasswordError.UserNotFound => "User not found.",
SetUserPasswordError.PasswordIsInvalid e => string.Join(delimiter, e.Violations.Select(static v => v.ToSentence())),
_ => "Unknown error.",
};
}
public static string ToSentence(this UsernameRequirementViolation violation) {
return violation switch {
UsernameRequirementViolation.IsEmpty => "Username must not be empty.",
UsernameRequirementViolation.TooLong v => "Username must not be longer than " + v.MaxLength + " character(s).",
_ => "Unknown error.",
};
}
public static string ToSentence(this PasswordRequirementViolation violation) {
return violation switch {
PasswordRequirementViolation.TooShort v => "Password must be at least " + v.MinimumLength + " character(s) long.",
PasswordRequirementViolation.MustContainLowercaseLetter => "Password must contain a lowercase letter.",
PasswordRequirementViolation.MustContainUppercaseLetter => "Password must contain an uppercase letter.",
PasswordRequirementViolation.MustContainDigit => "Password must contain a digit.",
_ => "Unknown error.",
};
}
public static string ToSentence(this JvmArgumentsHelper.ValidationError? result) {
return result switch {
JvmArgumentsHelper.ValidationError.InvalidFormat => "Invalid format.",
JvmArgumentsHelper.ValidationError.XmxNotAllowed => "The -Xmx argument must not be specified manually.",
JvmArgumentsHelper.ValidationError.XmsNotAllowed => "The -Xms argument must not be specified manually.",
_ => throw new ArgumentOutOfRangeException(nameof(result), result, message: null),
};
}
public static string ToSentence(this LaunchInstanceResult reason) {
return reason switch {
LaunchInstanceResult.LaunchInitiated => "Launch initiated.",
LaunchInstanceResult.InstanceAlreadyLaunching => "Instance is already launching.",
LaunchInstanceResult.InstanceAlreadyRunning => "Instance is already running.",
LaunchInstanceResult.InstanceLimitExceeded => "Agent does not have any more available instances.",
LaunchInstanceResult.MemoryLimitExceeded => "Agent does not have enough available memory.",
LaunchInstanceResult.ServerPortNotAllowed => "Server port is not allowed.",
LaunchInstanceResult.ServerPortAlreadyInUse => "Server port is already in use.",
LaunchInstanceResult.AdditionalPortNotAllowed => "One of additional ports is not allowed.",
LaunchInstanceResult.AdditionalPortAlreadyInUse => "One of additional ports is already in use.",
_ => "Unknown error.",
};
}
public static string ToSentence(this InstanceLaunchFailReason reason) {
return reason switch {
InstanceLaunchFailReason.CouldNotPrepareServerInstance => "Could not prepare server instance.",
InstanceLaunchFailReason.CouldNotFindServerExecutable => "Could not find server executable.",
InstanceLaunchFailReason.CouldNotStartServerExecutable => "Could not start server executable.",
_ => "Unknown error.",
};
}
public static string ToSentence(this SendCommandToInstanceResult reason) {
return reason switch {
SendCommandToInstanceResult.Success => "Command sent.",
SendCommandToInstanceResult.InstanceNotRunning => "Instance is not running.",
_ => "Unknown error.",
};
}
public static string ToSentence(this StopInstanceResult reason) {
return reason switch {
StopInstanceResult.StopInitiated => "Stopping initiated.",
StopInstanceResult.InstanceAlreadyStopping => "Instance is already stopping.",
StopInstanceResult.InstanceAlreadyStopped => "Instance is already stopped.",
_ => "Unknown error.",
};
}
}