2019-04-14 11:55:05 -04:00
|
|
|
|
using SharedLibraryCore.Configuration.Attributes;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-04-23 17:03:50 -04: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;
|
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
|
|
|
|
{
|
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; }
|
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; }
|
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; }
|
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];
|
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];
|
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; }
|
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; }
|
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; }
|
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; }
|
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; }
|
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
|
|
|
|
|
2019-02-04 20:38:24 -05:00
|
|
|
|
private readonly IList<IRConParser> rconParsers;
|
|
|
|
|
private readonly IList<IEventParser> eventParsers;
|
|
|
|
|
|
|
|
|
|
public ServerConfiguration()
|
|
|
|
|
{
|
|
|
|
|
rconParsers = new List<IRConParser>();
|
|
|
|
|
eventParsers = new List<IEventParser>();
|
2020-01-17 18:31:53 -05:00
|
|
|
|
Rules = new string[0];
|
|
|
|
|
AutoMessages = new string[0];
|
2019-02-04 20:38:24 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-09 11:28:04 -05:00
|
|
|
|
public void AddRConParser(IRConParser parser)
|
|
|
|
|
{
|
|
|
|
|
rconParsers.Add(parser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddEventParser(IEventParser parser)
|
|
|
|
|
{
|
|
|
|
|
eventParsers.Add(parser);
|
|
|
|
|
}
|
2019-02-04 20:38:24 -05:00
|
|
|
|
|
2019-02-05 12:14:43 -05:00
|
|
|
|
public void ModifyParsers()
|
|
|
|
|
{
|
|
|
|
|
var loc = Utilities.CurrentLocalization.LocalizationIndex;
|
2020-01-21 19:08:18 -05:00
|
|
|
|
var parserVersions = rconParsers.Select(_parser => _parser.Name).ToArray();
|
2020-02-11 17:44:06 -05:00
|
|
|
|
var selection = Utilities.PromptSelection($"{loc["SETUP_SERVER_RCON_PARSER_VERSION"]} ({IPAddress}:{Port})", parserVersions[0], null, parserVersions);
|
2019-02-05 12:14:43 -05:00
|
|
|
|
|
2019-04-28 21:54:11 -04:00
|
|
|
|
if (selection.Item1 >= 0)
|
2019-02-05 12:14:43 -05:00
|
|
|
|
{
|
2020-02-11 17:44:06 -05:00
|
|
|
|
RConParserVersion = rconParsers.FirstOrDefault(_parser => _parser.Name == selection.Item2)?.Version;
|
2019-02-05 19:02:45 -05:00
|
|
|
|
|
2021-06-27 21:31:39 -04:00
|
|
|
|
if (selection.Item1 > 0 && !rconParsers[selection.Item1].CanGenerateLogPath)
|
2019-02-05 19:02:45 -05:00
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(loc["SETUP_SERVER_NO_LOG"]);
|
|
|
|
|
ManualLogPath = Utilities.PromptString(loc["SETUP_SERVER_LOG_PATH"]);
|
|
|
|
|
}
|
2019-02-05 12:14:43 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-24 09:57:20 -05:00
|
|
|
|
parserVersions = eventParsers.Select(_parser => _parser.Name).ToArray();
|
2020-02-11 17:44:06 -05:00
|
|
|
|
selection = Utilities.PromptSelection($"{loc["SETUP_SERVER_EVENT_PARSER_VERSION"]} ({IPAddress}:{Port})", parserVersions[0], null, parserVersions);
|
2019-02-05 12:14:43 -05:00
|
|
|
|
|
2019-04-28 21:54:11 -04:00
|
|
|
|
if (selection.Item1 >= 0)
|
2019-02-05 12:14:43 -05:00
|
|
|
|
{
|
2020-02-11 17:44:06 -05:00
|
|
|
|
EventParserVersion = eventParsers.FirstOrDefault(_parser => _parser.Name == selection.Item2)?.Version;
|
2019-02-05 12:14:43 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-11 18:24:21 -04:00
|
|
|
|
public IBaseConfiguration Generate()
|
|
|
|
|
{
|
2018-05-05 16:36:26 -04:00
|
|
|
|
var loc = Utilities.CurrentLocalization.LocalizationIndex;
|
2018-04-23 17:03:50 -04:00
|
|
|
|
|
|
|
|
|
while (string.IsNullOrEmpty(IPAddress))
|
|
|
|
|
{
|
|
|
|
|
string input = Utilities.PromptString(loc["SETUP_SERVER_IP"]);
|
|
|
|
|
|
|
|
|
|
if (System.Net.IPAddress.TryParse(input, out System.Net.IPAddress ip))
|
2019-03-09 11:28:04 -05:00
|
|
|
|
{
|
2018-04-23 17:03:50 -04:00
|
|
|
|
IPAddress = input;
|
2019-03-09 11:28:04 -05:00
|
|
|
|
}
|
2018-04-23 17:03:50 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-18 15:19:50 -04:00
|
|
|
|
Port = Utilities.PromptInt(loc["SETUP_SERVER_PORT"], null, 1, ushort.MaxValue);
|
2018-04-23 17:03:50 -04:00
|
|
|
|
Password = Utilities.PromptString(loc["SETUP_SERVER_RCON"]);
|
2020-01-17 18:31:53 -05:00
|
|
|
|
AutoMessages = new string[0];
|
|
|
|
|
Rules = new string[0];
|
2018-12-30 19:13:13 -05:00
|
|
|
|
ReservedSlotNumber = loc["SETUP_SERVER_RESERVEDSLOT"].PromptInt(null, 0, 32);
|
2019-03-09 11:28:04 -05:00
|
|
|
|
ManualLogPath = null;
|
2018-08-07 14:43:09 -04:00
|
|
|
|
|
2019-02-05 12:14:43 -05:00
|
|
|
|
ModifyParsers();
|
2019-02-04 20:38:24 -05:00
|
|
|
|
|
2018-04-11 18:24:21 -04:00
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-09 11:28:04 -05:00
|
|
|
|
public string Name()
|
|
|
|
|
{
|
|
|
|
|
return "ServerConfiguration";
|
|
|
|
|
}
|
2018-03-14 01:36:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|