2018-04-11 18:24:21 -04:00
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
{
public string IPAddress { get ; set ; }
2019-03-09 11:28:04 -05:00
public int Port { get ; set ; }
2018-03-14 01:36:25 -04:00
public string Password { get ; set ; }
2018-08-26 20:20:47 -04:00
public IList < string > Rules { get ; set ; }
public IList < string > AutoMessages { get ; set ; }
2018-04-23 01:43:48 -04:00
public string ManualLogPath { get ; set ; }
2019-02-05 12:14:43 -05:00
public string RConParserVersion { get ; set ; }
public string EventParserVersion { get ; set ; }
2018-08-07 14:43:09 -04:00
public int ReservedSlotNumber { get ; set ; }
2019-02-09 16:35:13 -05:00
public Uri GameLogServerUrl { 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 > ( ) ;
}
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 ;
var parserVersions = rconParsers . Select ( _parser = > _parser . Version ) . ToArray ( ) ;
var selection = Utilities . PromptSelection ( $"{loc[" SETUP_SERVER_RCON_PARSER_VERSION "]} ({IPAddress}:{Port})" , $"{loc[" SETUP_PROMPT_DEFAULT "]} (Call of Duty)" , null , parserVersions ) ;
if ( selection . Item1 > 0 )
{
RConParserVersion = selection . Item2 ;
2019-02-05 19:02:45 -05:00
if ( ! rconParsers [ selection . Item1 - 1 ] . CanGenerateLogPath )
{
Console . WriteLine ( loc [ "SETUP_SERVER_NO_LOG" ] ) ;
ManualLogPath = Utilities . PromptString ( loc [ "SETUP_SERVER_LOG_PATH" ] ) ;
}
2019-02-05 12:14:43 -05:00
}
parserVersions = eventParsers . Select ( _parser = > _parser . Version ) . ToArray ( ) ;
selection = Utilities . PromptSelection ( $"{loc[" SETUP_SERVER_EVENT_PARSER_VERSION "]} ({IPAddress}:{Port})" , $"{loc[" SETUP_PROMPT_DEFAULT "]} (Call of Duty)" , null , parserVersions ) ;
if ( selection . Item1 > 0 )
{
EventParserVersion = selection . Item2 ;
}
}
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-03-09 11:28:04 -05:00
Port = Utilities . PromptInt ( Utilities . PromptString ( loc [ "SETUP_SERVER_PORT" ] ) , null , 1 , ushort . MaxValue ) ;
2018-04-23 17:03:50 -04:00
Password = Utilities . PromptString ( loc [ "SETUP_SERVER_RCON" ] ) ;
AutoMessages = new List < string > ( ) ;
Rules = new List < string > ( ) ;
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
}
}