Initial .net 6 upgrades
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
using SharedLibraryCore.Configuration.Attributes;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using SharedLibraryCore.Configuration.Attributes;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using static Data.Models.Client.EFClient;
|
||||
|
||||
namespace SharedLibraryCore.Configuration
|
||||
@ -12,8 +12,9 @@ namespace SharedLibraryCore.Configuration
|
||||
public class ApplicationConfiguration : IBaseConfiguration
|
||||
{
|
||||
[ConfigurationIgnore]
|
||||
public CommunityInformationConfiguration CommunityInformation { get; set; } = new CommunityInformationConfiguration();
|
||||
|
||||
public CommunityInformationConfiguration CommunityInformation { get; set; } =
|
||||
new CommunityInformationConfiguration();
|
||||
|
||||
[LocalizedDisplayName("SETUP_ENABLE_WEBFRONT")]
|
||||
[ConfigurationLinked("WebfrontBindUrl", "ManualWebfrontUrl", "WebfrontPrimaryColor", "WebfrontSecondaryColor",
|
||||
"WebfrontCustomBranding")]
|
||||
@ -38,8 +39,7 @@ namespace SharedLibraryCore.Configuration
|
||||
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_CUSTOM_BRANDING")]
|
||||
public string WebfrontCustomBranding { get; set; }
|
||||
|
||||
[ConfigurationIgnore]
|
||||
public WebfrontConfiguration Webfront { get; set; } = new WebfrontConfiguration();
|
||||
[ConfigurationIgnore] public WebfrontConfiguration Webfront { get; set; } = new WebfrontConfiguration();
|
||||
|
||||
[LocalizedDisplayName("SETUP_ENABLE_MULTIOWN")]
|
||||
public bool EnableMultipleOwners { get; set; }
|
||||
@ -116,8 +116,7 @@ namespace SharedLibraryCore.Configuration
|
||||
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_ENABLE_COLOR_CODES")]
|
||||
public bool EnableColorCodes { get; set; }
|
||||
|
||||
[ConfigurationIgnore]
|
||||
public string IngameAccentColorKey { get; set; } = "Cyan";
|
||||
[ConfigurationIgnore] public string IngameAccentColorKey { get; set; } = "Cyan";
|
||||
|
||||
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_AUTOMESSAGE_PERIOD")]
|
||||
public int AutoMessagePeriod { get; set; }
|
||||
@ -135,7 +134,8 @@ namespace SharedLibraryCore.Configuration
|
||||
public int MapChangeDelaySeconds { get; set; } = 5;
|
||||
|
||||
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_BAN_DURATIONS")]
|
||||
public TimeSpan[] BanDurations { get; set; } = {
|
||||
public TimeSpan[] BanDurations { get; set; } =
|
||||
{
|
||||
TimeSpan.FromHours(1),
|
||||
TimeSpan.FromHours(6),
|
||||
TimeSpan.FromDays(1),
|
||||
@ -147,36 +147,38 @@ namespace SharedLibraryCore.Configuration
|
||||
[ConfigurationIgnore]
|
||||
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_PRESET_BAN_REASONS")]
|
||||
public Dictionary<string, string> PresetPenaltyReasons { get; set; } = new Dictionary<string, string>
|
||||
{{"afk", "Away from keyboard"}, {"ci", "Connection interrupted. Reconnect"}};
|
||||
[LocalizedDisplayName(("WEBFRONT_CONFIGURATION_ENABLE_PRIVILEGED_USER_PRIVACY"))]
|
||||
{ { "afk", "Away from keyboard" }, { "ci", "Connection interrupted. Reconnect" } };
|
||||
|
||||
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_ENABLE_PRIVILEGED_USER_PRIVACY")]
|
||||
public bool EnablePrivilegedUserPrivacy { get; set; }
|
||||
|
||||
[ConfigurationIgnore]
|
||||
public bool EnableImplicitAccountLinking { get; set; } = false;
|
||||
[ConfigurationIgnore] public bool EnableImplicitAccountLinking { get; set; } = false;
|
||||
|
||||
[ConfigurationIgnore]
|
||||
public TimeSpan MaxClientHistoryTime { get; set; } = TimeSpan.FromHours(12);
|
||||
[ConfigurationIgnore] public TimeSpan MaxClientHistoryTime { get; set; } = TimeSpan.FromHours(12);
|
||||
|
||||
[ConfigurationIgnore]
|
||||
public TimeSpan ServerDataCollectionInterval { get; set; } = TimeSpan.FromMinutes(5);
|
||||
[ConfigurationIgnore] public TimeSpan ServerDataCollectionInterval { get; set; } = TimeSpan.FromMinutes(5);
|
||||
|
||||
public int ServerConnectionAttempts { get; set; } = 6;
|
||||
|
||||
|
||||
[ConfigurationIgnore]
|
||||
public Dictionary<Permission, string> OverridePermissionLevelNames { get; set; } = Enum
|
||||
.GetValues(typeof(Permission))
|
||||
.Cast<Permission>()
|
||||
.ToDictionary(perm => perm, perm => perm.ToString());
|
||||
[UIHint("ServerConfiguration")]
|
||||
public ServerConfiguration[] Servers { get; set; }
|
||||
|
||||
[UIHint("ServerConfiguration")] public ServerConfiguration[] Servers { get; set; }
|
||||
|
||||
[ConfigurationIgnore] public int MinimumNameLength { get; set; } = 3;
|
||||
[ConfigurationIgnore] public string Id { get; set; }
|
||||
[ConfigurationIgnore] public string SubscriptionId { get; set; }
|
||||
|
||||
[Obsolete("Moved to DefaultSettings")]
|
||||
[ConfigurationIgnore] public MapConfiguration[] Maps { get; set; }
|
||||
[ConfigurationIgnore]
|
||||
public MapConfiguration[] Maps { get; set; }
|
||||
|
||||
[Obsolete("Moved to DefaultSettings")]
|
||||
[ConfigurationIgnore] public QuickMessageConfiguration[] QuickMessages { get; set; }
|
||||
[ConfigurationIgnore]
|
||||
public QuickMessageConfiguration[] QuickMessages { get; set; }
|
||||
|
||||
[ConfigurationIgnore]
|
||||
[JsonIgnore]
|
||||
@ -192,30 +194,30 @@ namespace SharedLibraryCore.Configuration
|
||||
var loc = Utilities.CurrentLocalization.LocalizationIndex;
|
||||
Id = Guid.NewGuid().ToString();
|
||||
|
||||
EnableWebFront = Utilities.PromptBool(loc["SETUP_ENABLE_WEBFRONT"]);
|
||||
EnableMultipleOwners = Utilities.PromptBool(loc["SETUP_ENABLE_MULTIOWN"]);
|
||||
EnableSteppedHierarchy = Utilities.PromptBool(loc["SETUP_ENABLE_STEPPEDPRIV"]);
|
||||
EnableCustomSayName = Utilities.PromptBool(loc["SETUP_ENABLE_CUSTOMSAY"]);
|
||||
EnableWebFront = loc["SETUP_ENABLE_WEBFRONT"].PromptBool();
|
||||
EnableMultipleOwners = loc["SETUP_ENABLE_MULTIOWN"].PromptBool();
|
||||
EnableSteppedHierarchy = loc["SETUP_ENABLE_STEPPEDPRIV"].PromptBool();
|
||||
EnableCustomSayName = loc["SETUP_ENABLE_CUSTOMSAY"].PromptBool();
|
||||
|
||||
bool useCustomParserEncoding = Utilities.PromptBool(loc["SETUP_USE_CUSTOMENCODING"]);
|
||||
var useCustomParserEncoding = loc["SETUP_USE_CUSTOMENCODING"].PromptBool();
|
||||
if (useCustomParserEncoding)
|
||||
{
|
||||
CustomParserEncoding = Utilities.PromptString(loc["SETUP_ENCODING_STRING"]);
|
||||
CustomParserEncoding = loc["SETUP_ENCODING_STRING"].PromptString();
|
||||
}
|
||||
|
||||
WebfrontBindUrl = "http://0.0.0.0:1624";
|
||||
|
||||
if (EnableCustomSayName)
|
||||
{
|
||||
CustomSayName = Utilities.PromptString(loc["SETUP_SAY_NAME"]);
|
||||
CustomSayName = loc["SETUP_SAY_NAME"].PromptString();
|
||||
}
|
||||
|
||||
EnableSocialLink = Utilities.PromptBool(loc["SETUP_DISPLAY_SOCIAL"]);
|
||||
EnableSocialLink = loc["SETUP_DISPLAY_SOCIAL"].PromptBool();
|
||||
|
||||
if (EnableSocialLink)
|
||||
{
|
||||
SocialLinkTitle = Utilities.PromptString(loc["SETUP_SOCIAL_TITLE"]);
|
||||
SocialLinkAddress = Utilities.PromptString(loc["SETUP_SOCIAL_LINK"]);
|
||||
SocialLinkTitle = loc["SETUP_SOCIAL_TITLE"].PromptString();
|
||||
SocialLinkAddress = loc["SETUP_SOCIAL_LINK"].PromptString();
|
||||
}
|
||||
|
||||
RConPollRate = 5000;
|
||||
|
@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SharedLibraryCore.Configuration.Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property, Inherited = false)]
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ConfigurationIgnore : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -2,14 +2,14 @@
|
||||
|
||||
namespace SharedLibraryCore.Configuration.Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property, Inherited = false)]
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ConfigurationLinked : Attribute
|
||||
{
|
||||
public string[] LinkedPropertyNames { get; set; }
|
||||
|
||||
public ConfigurationLinked(params string[] linkedPropertyNames)
|
||||
{
|
||||
LinkedPropertyNames = linkedPropertyNames;
|
||||
}
|
||||
|
||||
public string[] LinkedPropertyNames { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SharedLibraryCore.Configuration.Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property, Inherited = false)]
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ConfigurationOptional : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SharedLibraryCore.Configuration.Attributes
|
||||
{
|
||||
class LocalizedDisplayName : DisplayNameAttribute
|
||||
internal class LocalizedDisplayName : DisplayNameAttribute
|
||||
{
|
||||
private readonly string _localizationKey;
|
||||
|
||||
public LocalizedDisplayName(string localizationKey)
|
||||
{
|
||||
_localizationKey = localizationKey;
|
||||
@ -15,4 +13,4 @@ namespace SharedLibraryCore.Configuration.Attributes
|
||||
|
||||
public override string DisplayName => Utilities.CurrentLocalization.LocalizationIndex[_localizationKey];
|
||||
}
|
||||
}
|
||||
}
|
@ -1,28 +1,29 @@
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
|
||||
namespace SharedLibraryCore.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic command configuration
|
||||
/// Basic command configuration
|
||||
/// </summary>
|
||||
public class CommandConfiguration : IBaseConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// Dict of command class names mapped to configurable properties
|
||||
/// Dict of command class names mapped to configurable properties
|
||||
/// </summary>
|
||||
public Dictionary<string, CommandProperties> Commands { get; set; } = new Dictionary<string, CommandProperties>();
|
||||
public Dictionary<string, CommandProperties> Commands { get; set; } =
|
||||
new Dictionary<string, CommandProperties>();
|
||||
|
||||
/// <summary>
|
||||
/// prefix indicated the chat message is a command
|
||||
/// prefix indicated the chat message is a command
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string CommandPrefix { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// prefix indicating that the chat message is a broadcast command
|
||||
/// prefix indicating that the chat message is a broadcast command
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string BroadcastCommandPrefix { get; set; }
|
||||
@ -32,6 +33,9 @@ namespace SharedLibraryCore.Configuration
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string Name() => nameof(CommandConfiguration);
|
||||
public string Name()
|
||||
{
|
||||
return nameof(CommandConfiguration);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,35 +6,35 @@ using static SharedLibraryCore.Server;
|
||||
namespace SharedLibraryCore.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Config driven command properties
|
||||
/// Config driven command properties
|
||||
/// </summary>
|
||||
public class CommandProperties
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the command name
|
||||
/// Specifies the command name
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Alias of this command
|
||||
/// Alias of this command
|
||||
/// </summary>
|
||||
public string Alias { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the minimum permission level needed to execute the
|
||||
/// Specifies the minimum permission level needed to execute the
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public Permission MinimumPermission { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the command can be run by another user (impersonation)
|
||||
/// Indicates if the command can be run by another user (impersonation)
|
||||
/// </summary>
|
||||
public bool AllowImpersonation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the games supporting the functionality of the command
|
||||
/// Specifies the games supporting the functionality of the command
|
||||
/// </summary>
|
||||
[JsonProperty(ItemConverterType = typeof(StringEnumConverter))]
|
||||
public Game[] SupportedGames { get; set; } = new Game[0];
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
using System.Linq;
|
||||
|
||||
namespace SharedLibraryCore.Configuration
|
||||
namespace SharedLibraryCore.Configuration
|
||||
{
|
||||
public class CommunityInformationConfiguration
|
||||
{
|
||||
public string Name { get; set; } = "IW4MAdmin - Configure In IW4MAdminSettings.json";
|
||||
|
||||
public string Description { get; set; } =
|
||||
"IW4MAdmin is an administration tool for IW4x, Pluto T6, Pluto IW5, CoD4x, TeknoMW3, and most Call of Duty® dedicated servers. It allows complete control of your server; from changing maps, to banning players, IW4MAdmin monitors and records activity on your server(s). With plugin support, extending its functionality is a breeze.";
|
||||
|
||||
public bool EnableBanner { get; set; } = true;
|
||||
|
||||
public SocialAccountConfiguration[] SocialAccounts { get; set; } =
|
||||
|
@ -8,12 +8,18 @@ namespace SharedLibraryCore.Configuration
|
||||
public string[] GlobalRules { get; set; }
|
||||
public MapConfiguration[] Maps { get; set; }
|
||||
public GametypeConfiguration[] Gametypes { get; set; }
|
||||
public QuickMessageConfiguration[] QuickMessages {get; set;}
|
||||
public QuickMessageConfiguration[] QuickMessages { get; set; }
|
||||
public string[] DisallowedClientNames { get; set; }
|
||||
public GameStringConfiguration GameStrings { get; set; }
|
||||
|
||||
public IBaseConfiguration Generate() => this;
|
||||
public IBaseConfiguration Generate()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public string Name() => "DefaultConfiguration";
|
||||
public string Name()
|
||||
{
|
||||
return "DefaultConfiguration";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.Win32;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
@ -43,6 +43,11 @@ namespace SharedLibraryCore.Configuration.Extensions
|
||||
string searchPath = null;
|
||||
var isRegistryKey = parser.Configuration.DefaultInstallationDirectoryHint.Contains("HKEY_");
|
||||
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (isRegistryKey)
|
||||
@ -51,10 +56,10 @@ namespace SharedLibraryCore.Configuration.Extensions
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
return new (string, string)[0];
|
||||
return Array.Empty<(string, string)>();
|
||||
}
|
||||
|
||||
searchPath = Path.Combine(result.ToString().Split(Path.DirectorySeparatorChar)
|
||||
searchPath = Path.Combine(result.ToString()!.Split(Path.DirectorySeparatorChar)
|
||||
.Where(p => !p.Contains(".exe"))
|
||||
.Select(p => p.Replace("\"", "")).ToArray());
|
||||
}
|
||||
@ -72,14 +77,14 @@ namespace SharedLibraryCore.Configuration.Extensions
|
||||
|
||||
if (string.IsNullOrEmpty(searchPath))
|
||||
{
|
||||
return new (string, string)[0];
|
||||
return Array.Empty<(string, string)>();
|
||||
}
|
||||
|
||||
var possibleFiles = Directory.GetFiles(searchPath, "*.cfg", SearchOption.AllDirectories);
|
||||
|
||||
if (!possibleFiles.Any())
|
||||
{
|
||||
return new (string, string)[0];
|
||||
return Array.Empty<(string, string)>();
|
||||
}
|
||||
|
||||
var possiblePasswords = possibleFiles.SelectMany(File.ReadAllLines)
|
||||
@ -95,8 +100,8 @@ namespace SharedLibraryCore.Configuration.Extensions
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new (string, string)[0];
|
||||
return Array.Empty<(string, string)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,4 +5,4 @@
|
||||
public Server.Game Game { get; set; }
|
||||
public Gametype[] Gametypes { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -5,4 +5,4 @@
|
||||
public Server.Game Game { get; set; }
|
||||
public Map[] Maps { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using static SharedLibraryCore.Server;
|
||||
|
||||
namespace SharedLibraryCore.Configuration
|
||||
@ -10,4 +8,4 @@ namespace SharedLibraryCore.Configuration
|
||||
public Game Game { get; set; }
|
||||
public Dictionary<string, string> Messages { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,24 @@
|
||||
using SharedLibraryCore.Configuration.Attributes;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SharedLibraryCore.Configuration.Attributes;
|
||||
using SharedLibraryCore.Configuration.Extensions;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
|
||||
namespace SharedLibraryCore.Configuration
|
||||
{
|
||||
public class ServerConfiguration : IBaseConfiguration
|
||||
{
|
||||
private readonly IList<IRConParser> _rconParsers;
|
||||
private IRConParser _selectedParser;
|
||||
|
||||
public ServerConfiguration()
|
||||
{
|
||||
_rconParsers = new List<IRConParser>();
|
||||
Rules = new string[0];
|
||||
AutoMessages = new string[0];
|
||||
}
|
||||
|
||||
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_SERVER_IP")]
|
||||
public string IPAddress { get; set; }
|
||||
|
||||
@ -45,14 +55,74 @@ namespace SharedLibraryCore.Configuration
|
||||
[ConfigurationOptional]
|
||||
public string CustomHostname { get; set; }
|
||||
|
||||
private readonly IList<IRConParser> _rconParsers;
|
||||
private IRConParser _selectedParser;
|
||||
|
||||
public ServerConfiguration()
|
||||
public IBaseConfiguration Generate()
|
||||
{
|
||||
_rconParsers = new List<IRConParser>();
|
||||
Rules = new string[0];
|
||||
ModifyParsers();
|
||||
var loc = Utilities.CurrentLocalization.LocalizationIndex;
|
||||
var shouldTryFindIp = loc["SETUP_SERVER_IP_AUTO"].PromptBool(defaultValue: true);
|
||||
|
||||
if (shouldTryFindIp)
|
||||
{
|
||||
this.TrySetIpAddress();
|
||||
Console.WriteLine(loc["SETUP_SERVER_IP_AUTO_RESULT"].FormatExt(IPAddress));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
while (string.IsNullOrEmpty(IPAddress))
|
||||
{
|
||||
var input = loc["SETUP_SERVER_IP"].PromptString();
|
||||
IPAddress = input;
|
||||
}
|
||||
}
|
||||
|
||||
var defaultPort = _selectedParser.Configuration.DefaultRConPort;
|
||||
Port = loc["SETUP_SERVER_PORT"].PromptInt(null, 1, ushort.MaxValue, defaultPort);
|
||||
|
||||
if (!string.IsNullOrEmpty(_selectedParser.Configuration.DefaultInstallationDirectoryHint))
|
||||
{
|
||||
var shouldTryFindPassword = loc["SETUP_RCON_PASSWORD_AUTO"].PromptBool(defaultValue: true);
|
||||
|
||||
if (shouldTryFindPassword)
|
||||
{
|
||||
var passwords = _selectedParser.TryGetRConPasswords();
|
||||
if (passwords.Length > 1)
|
||||
{
|
||||
var (index, value) =
|
||||
loc["SETUP_RCON_PASSWORD_PROMPT"].PromptSelection(loc["SETUP_RCON_PASSWORD_MANUAL"], null,
|
||||
passwords.Select(pw =>
|
||||
$"{pw.Item1}{(string.IsNullOrEmpty(pw.Item2) ? "" : " " + pw.Item2)}")
|
||||
.ToArray());
|
||||
|
||||
if (index > 0)
|
||||
{
|
||||
Password = passwords[index - 1].Item1;
|
||||
}
|
||||
}
|
||||
|
||||
else if (passwords.Length > 0)
|
||||
{
|
||||
Password = passwords[0].Item1;
|
||||
Console.WriteLine(loc["SETUP_RCON_PASSWORD_RESULT"].FormatExt(Password));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(Password))
|
||||
{
|
||||
Password = loc["SETUP_SERVER_RCON"].PromptString();
|
||||
}
|
||||
|
||||
AutoMessages = new string[0];
|
||||
Rules = new string[0];
|
||||
ManualLogPath = null;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public string Name()
|
||||
{
|
||||
return "ServerConfiguration";
|
||||
}
|
||||
|
||||
public void AddRConParser(IRConParser parser)
|
||||
@ -88,74 +158,5 @@ namespace SharedLibraryCore.Configuration
|
||||
Console.WriteLine(loc["SETUP_SERVER_NO_LOG"]);
|
||||
ManualLogPath = loc["SETUP_SERVER_LOG_PATH"].PromptString();
|
||||
}
|
||||
|
||||
public IBaseConfiguration Generate()
|
||||
{
|
||||
ModifyParsers();
|
||||
var loc = Utilities.CurrentLocalization.LocalizationIndex;
|
||||
var shouldTryFindIp = loc["SETUP_SERVER_IP_AUTO"].PromptBool(defaultValue: true);
|
||||
|
||||
if (shouldTryFindIp)
|
||||
{
|
||||
this.TrySetIpAddress();
|
||||
Console.WriteLine(loc["SETUP_SERVER_IP_AUTO_RESULT"].FormatExt(IPAddress));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
while (string.IsNullOrEmpty(IPAddress))
|
||||
{
|
||||
var input = loc["SETUP_SERVER_IP"].PromptString();
|
||||
IPAddress = input;
|
||||
}
|
||||
}
|
||||
|
||||
var defaultPort = _selectedParser.Configuration.DefaultRConPort;
|
||||
Port = loc["SETUP_SERVER_PORT"].PromptInt(null, 1, ushort.MaxValue, defaultValue:defaultPort);
|
||||
|
||||
if (!string.IsNullOrEmpty(_selectedParser.Configuration.DefaultInstallationDirectoryHint))
|
||||
{
|
||||
var shouldTryFindPassword = loc["SETUP_RCON_PASSWORD_AUTO"].PromptBool(defaultValue: true);
|
||||
|
||||
if (shouldTryFindPassword)
|
||||
{
|
||||
var passwords = _selectedParser.TryGetRConPasswords();
|
||||
if (passwords.Length > 1)
|
||||
{
|
||||
var (index, value) =
|
||||
loc["SETUP_RCON_PASSWORD_PROMPT"].PromptSelection(loc["SETUP_RCON_PASSWORD_MANUAL"], null,
|
||||
passwords.Select(pw =>
|
||||
$"{pw.Item1}{(string.IsNullOrEmpty(pw.Item2) ? "" : " " + pw.Item2)}").ToArray());
|
||||
|
||||
if (index > 0)
|
||||
{
|
||||
Password = passwords[index - 1].Item1;
|
||||
}
|
||||
}
|
||||
|
||||
else if (passwords.Length > 0)
|
||||
{
|
||||
Password = passwords[0].Item1;
|
||||
Console.WriteLine(loc["SETUP_RCON_PASSWORD_RESULT"].FormatExt(Password));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(Password))
|
||||
{
|
||||
Password = loc["SETUP_SERVER_RCON"].PromptString();
|
||||
}
|
||||
|
||||
AutoMessages = new string[0];
|
||||
Rules = new string[0];
|
||||
ManualLogPath = null;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public string Name()
|
||||
{
|
||||
return "ServerConfiguration";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
using FluentValidation;
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using FluentValidation;
|
||||
|
||||
namespace SharedLibraryCore.Configuration.Validation
|
||||
{
|
||||
/// <summary>
|
||||
/// Validation class for main application configuration
|
||||
/// Validation class for main application configuration
|
||||
/// </summary>
|
||||
public class ApplicationConfigurationValidator : AbstractValidator<ApplicationConfiguration>
|
||||
{
|
||||
@ -23,27 +24,27 @@ namespace SharedLibraryCore.Configuration.Validation
|
||||
.When(_app => _app.EnableSocialLink);
|
||||
|
||||
RuleFor(_app => _app.SocialLinkTitle)
|
||||
.NotEmpty()
|
||||
.When(_app => _app.EnableSocialLink);
|
||||
.NotEmpty()
|
||||
.When(_app => _app.EnableSocialLink);
|
||||
|
||||
RuleFor(_app => _app.CustomParserEncoding)
|
||||
.NotEmpty()
|
||||
.When(_app => _app.EnableCustomParserEncoding);
|
||||
.NotEmpty()
|
||||
.When(_app => _app.EnableCustomParserEncoding);
|
||||
|
||||
RuleFor(_app => _app.WebfrontConnectionWhitelist)
|
||||
.NotEmpty()
|
||||
.When(_app => _app.EnableWebfrontConnectionWhitelist);
|
||||
|
||||
RuleForEach(_app => _app.WebfrontConnectionWhitelist)
|
||||
.Must(_address => System.Net.IPAddress.TryParse(_address, out _));
|
||||
.Must(_address => IPAddress.TryParse(_address, out _));
|
||||
|
||||
RuleFor(_app => _app.CustomLocale)
|
||||
.NotEmpty()
|
||||
.When(_app => _app.EnableCustomLocale);
|
||||
.NotEmpty()
|
||||
.When(_app => _app.EnableCustomLocale);
|
||||
|
||||
RuleFor(_app => _app.DatabaseProvider)
|
||||
.NotEmpty()
|
||||
.Must(_provider => new[] { "sqlite", "mysql", "postgresql" }.Contains(_provider));
|
||||
.NotEmpty()
|
||||
.Must(_provider => new[] { "sqlite", "mysql", "postgresql" }.Contains(_provider));
|
||||
|
||||
RuleFor(_app => _app.ConnectionString)
|
||||
.NotEmpty()
|
||||
@ -79,4 +80,4 @@ namespace SharedLibraryCore.Configuration.Validation
|
||||
.SetValidator(new ServerConfigurationValidator());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
using FluentValidation;
|
||||
using System.Net;
|
||||
|
||||
namespace SharedLibraryCore.Configuration.Validation
|
||||
{
|
||||
/// <summary>
|
||||
/// Validation class for server configuration
|
||||
/// Validation class for server configuration
|
||||
/// </summary>
|
||||
public class ServerConfigurationValidator : AbstractValidator<ServerConfiguration>
|
||||
{
|
||||
@ -30,4 +29,4 @@ namespace SharedLibraryCore.Configuration.Validation
|
||||
.MaximumLength(128);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user