support hostnames for server config

This commit is contained in:
RaidMax
2021-07-11 17:26:30 -05:00
parent 5ef00d6dae
commit e2ea5c6ce0
12 changed files with 59 additions and 52 deletions

View File

@ -87,12 +87,8 @@ namespace SharedLibraryCore.Configuration
while (string.IsNullOrEmpty(IPAddress))
{
string input = Utilities.PromptString(loc["SETUP_SERVER_IP"]);
if (System.Net.IPAddress.TryParse(input, out System.Net.IPAddress ip))
{
IPAddress = input;
}
var input = Utilities.PromptString(loc["SETUP_SERVER_IP"]);
IPAddress = input;
}
Port = Utilities.PromptInt(loc["SETUP_SERVER_PORT"], null, 1, ushort.MaxValue);

View File

@ -10,10 +10,6 @@ namespace SharedLibraryCore.Configuration.Validation
{
public ServerConfigurationValidator()
{
RuleFor(_server => _server.IPAddress)
.NotEmpty()
.Must(_address => IPAddress.TryParse(_address, out _));
RuleFor(_server => _server.Port)
.InclusiveBetween(1, ushort.MaxValue);

View File

@ -1,4 +1,6 @@
namespace SharedLibraryCore.Interfaces
using System.Net;
namespace SharedLibraryCore.Interfaces
{
/// <summary>
/// defines the capabilities of an RCon connection factory
@ -8,11 +10,10 @@
/// <summary>
/// creates an rcon connection instance
/// </summary>
/// <param name="ipAddress">ip address of the server</param>
/// <param name="port">port of the server</param>
/// <param name="ipEndpoint">ip address and port of the server</param>
/// <param name="password"> password of the server</param>
/// <param name="rconEngine">engine to create the rcon connection to</param>
/// <returns>instance of rcon connection</returns>
IRConConnection CreateConnection(string ipAddress, int port, string password, string rconEngine);
IRConConnection CreateConnection(IPEndPoint ipEndpoint, string password, string rconEngine);
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
@ -58,7 +59,9 @@ namespace SharedLibraryCore
InitializeAutoMessages();
}
public long EndPoint => Convert.ToInt64($"{IP.Replace(".", "")}{Port}");
public long EndPoint => IPAddress.TryParse(IP, out _)
? Convert.ToInt64($"{IP.Replace(".", "")}{Port}")
: $"{IP.Replace(".", "")}{Port}".GetStableHashCode();
/// <summary>
/// Returns list of all current players
@ -303,7 +306,7 @@ namespace SharedLibraryCore
{
get
{
return Clients.Where(p => p != null/* && !p.IsBot*/).Count();
return Clients.Count(p => p != null && !p.IsBot);
}
}
public int MaxClients { get; protected set; }
@ -320,7 +323,11 @@ namespace SharedLibraryCore
public SemaphoreSlim EventProcessing { get; private set; }
// Internal
/// <summary>
/// this is actually the hostname now
/// </summary>
public string IP { get; protected set; }
public IPEndPoint ResolvedIpEndPoint { get; protected set; }
public string Version { get; protected set; }
public bool IsInitialized { get; set; }
protected readonly ILogger ServerLogger;