2022-01-26 11:32:16 -05:00
|
|
|
|
using System;
|
2018-04-11 18:24:21 -04:00
|
|
|
|
using System.Collections.Generic;
|
2019-02-04 20:38:24 -05:00
|
|
|
|
using System.Linq;
|
2022-01-26 11:32:16 -05:00
|
|
|
|
using SharedLibraryCore.Configuration.Attributes;
|
2021-11-14 22:38:00 -05:00
|
|
|
|
using SharedLibraryCore.Configuration.Extensions;
|
2022-01-26 11:32:16 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-03-18 22:25:11 -04:00
|
|
|
|
|
2018-04-08 02:44:42 -04:00
|
|
|
|
namespace SharedLibraryCore.Configuration
|
2018-03-14 01:36:25 -04:00
|
|
|
|
{
|
2018-04-11 18:24:21 -04:00
|
|
|
|
public class ServerConfiguration : IBaseConfiguration
|
2018-03-14 01:36:25 -04:00
|
|
|
|
{
|
2022-01-26 11:32:16 -05:00
|
|
|
|
private readonly IList<IRConParser> _rconParsers;
|
|
|
|
|
private IRConParser _selectedParser;
|
|
|
|
|
|
|
|
|
|
public ServerConfiguration()
|
|
|
|
|
{
|
|
|
|
|
_rconParsers = new List<IRConParser>();
|
|
|
|
|
Rules = new string[0];
|
|
|
|
|
AutoMessages = new string[0];
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-14 11:55:05 -04:00
|
|
|
|
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_SERVER_IP")]
|
2018-03-14 01:36:25 -04:00
|
|
|
|
public string IPAddress { get; set; }
|
2021-11-14 22:38:00 -05:00
|
|
|
|
|
2019-04-14 11:55:05 -04:00
|
|
|
|
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_SERVER_PORT")]
|
2019-03-09 11:28:04 -05:00
|
|
|
|
public int Port { get; set; }
|
2021-11-14 22:38:00 -05:00
|
|
|
|
|
2019-04-14 11:55:05 -04:00
|
|
|
|
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_SERVER_PASSWORD")]
|
2018-03-14 01:36:25 -04:00
|
|
|
|
public string Password { get; set; }
|
2021-11-14 22:38:00 -05:00
|
|
|
|
|
2019-04-14 11:55:05 -04:00
|
|
|
|
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_SERVER_RULES")]
|
2020-01-17 18:31:53 -05:00
|
|
|
|
public string[] Rules { get; set; } = new string[0];
|
2021-11-14 22:38:00 -05:00
|
|
|
|
|
2019-04-14 11:55:05 -04:00
|
|
|
|
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_SERVER_AUTO_MESSAGES")]
|
2020-01-17 18:31:53 -05:00
|
|
|
|
public string[] AutoMessages { get; set; } = new string[0];
|
2021-11-14 22:38:00 -05:00
|
|
|
|
|
2019-04-14 11:55:05 -04:00
|
|
|
|
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_SERVER_PATH")]
|
|
|
|
|
[ConfigurationOptional]
|
2018-04-23 01:43:48 -04:00
|
|
|
|
public string ManualLogPath { get; set; }
|
2021-11-14 22:38:00 -05:00
|
|
|
|
|
2019-04-14 11:55:05 -04:00
|
|
|
|
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_SERVER_RCON_PARSER")]
|
2019-02-05 12:14:43 -05:00
|
|
|
|
public string RConParserVersion { get; set; }
|
2021-11-14 22:38:00 -05:00
|
|
|
|
|
2019-04-14 11:55:05 -04:00
|
|
|
|
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_SERVER_EVENT_PARSER")]
|
2019-02-05 12:14:43 -05:00
|
|
|
|
public string EventParserVersion { get; set; }
|
2021-11-14 22:38:00 -05:00
|
|
|
|
|
2019-04-14 11:55:05 -04:00
|
|
|
|
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_SERVER_RESERVED_SLOT")]
|
2018-08-07 14:43:09 -04:00
|
|
|
|
public int ReservedSlotNumber { get; set; }
|
2021-11-14 22:38:00 -05:00
|
|
|
|
|
2019-04-14 11:55:05 -04:00
|
|
|
|
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_SERVER_GAME_LOG_SERVER")]
|
|
|
|
|
[ConfigurationOptional]
|
2019-02-09 16:35:13 -05:00
|
|
|
|
public Uri GameLogServerUrl { get; set; }
|
2021-11-14 22:38:00 -05:00
|
|
|
|
|
2020-05-23 14:15:22 -04:00
|
|
|
|
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_SERVER_CUSTOM_HOSTNAME")]
|
|
|
|
|
[ConfigurationOptional]
|
|
|
|
|
public string CustomHostname { get; set; }
|
2018-04-11 18:24:21 -04:00
|
|
|
|
|
|
|
|
|
public IBaseConfiguration Generate()
|
|
|
|
|
{
|
2021-11-14 22:38:00 -05:00
|
|
|
|
ModifyParsers();
|
2018-05-05 16:36:26 -04:00
|
|
|
|
var loc = Utilities.CurrentLocalization.LocalizationIndex;
|
2021-11-14 22:38:00 -05:00
|
|
|
|
var shouldTryFindIp = loc["SETUP_SERVER_IP_AUTO"].PromptBool(defaultValue: true);
|
2018-04-23 17:03:50 -04:00
|
|
|
|
|
2021-11-14 22:38:00 -05:00
|
|
|
|
if (shouldTryFindIp)
|
2018-04-23 17:03:50 -04:00
|
|
|
|
{
|
2021-11-14 22:38:00 -05:00
|
|
|
|
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;
|
2022-01-26 11:32:16 -05:00
|
|
|
|
Port = loc["SETUP_SERVER_PORT"].PromptInt(null, 1, ushort.MaxValue, defaultPort);
|
2021-11-14 22:38:00 -05:00
|
|
|
|
|
|
|
|
|
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) =
|
2021-11-15 11:25:55 -05:00
|
|
|
|
loc["SETUP_RCON_PASSWORD_PROMPT"].PromptSelection(loc["SETUP_RCON_PASSWORD_MANUAL"], null,
|
2021-11-14 22:38:00 -05:00
|
|
|
|
passwords.Select(pw =>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
$"{pw.Item1}{(string.IsNullOrEmpty(pw.Item2) ? "" : " " + pw.Item2)}")
|
|
|
|
|
.ToArray());
|
2021-11-14 22:38:00 -05:00
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2021-11-14 22:38:00 -05:00
|
|
|
|
if (string.IsNullOrEmpty(Password))
|
|
|
|
|
{
|
|
|
|
|
Password = loc["SETUP_SERVER_RCON"].PromptString();
|
2018-04-23 17:03:50 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-17 18:31:53 -05:00
|
|
|
|
AutoMessages = new string[0];
|
|
|
|
|
Rules = new string[0];
|
2019-03-09 11:28:04 -05:00
|
|
|
|
ManualLogPath = null;
|
2018-08-07 14:43:09 -04:00
|
|
|
|
|
2018-04-11 18:24:21 -04:00
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-09 11:28:04 -05:00
|
|
|
|
public string Name()
|
|
|
|
|
{
|
|
|
|
|
return "ServerConfiguration";
|
|
|
|
|
}
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
|
|
|
|
public void AddRConParser(IRConParser parser)
|
|
|
|
|
{
|
|
|
|
|
_rconParsers.Add(parser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddEventParser(IEventParser parser)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ModifyParsers()
|
|
|
|
|
{
|
|
|
|
|
var loc = Utilities.CurrentLocalization.LocalizationIndex;
|
|
|
|
|
var parserVersions = _rconParsers.Select(p => p.Name).ToArray();
|
|
|
|
|
var (index, parser) = loc["SETUP_SERVER_RCON_PARSER_VERSION"].PromptSelection(parserVersions[0],
|
|
|
|
|
null, parserVersions);
|
|
|
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_selectedParser = _rconParsers.FirstOrDefault(p => p.Name == parser);
|
2022-02-01 19:27:03 -05:00
|
|
|
|
RConParserVersion = _selectedParser?.Name;
|
|
|
|
|
EventParserVersion = _selectedParser?.Name;
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
|
|
|
|
if (index <= 0 || _rconParsers[index].CanGenerateLogPath)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(loc["SETUP_SERVER_NO_LOG"]);
|
|
|
|
|
ManualLogPath = loc["SETUP_SERVER_LOG_PATH"].PromptString();
|
|
|
|
|
}
|
2018-03-14 01:36:25 -04:00
|
|
|
|
}
|
2022-01-26 11:32:16 -05:00
|
|
|
|
}
|