update references from IP to ListenAddress

This commit is contained in:
RaidMax 2023-04-04 22:21:18 -05:00
parent 6fa172d757
commit 2e726ea9ed
9 changed files with 86 additions and 101 deletions

View File

@ -307,12 +307,12 @@ namespace IW4MAdmin
if (!Manager.GetApplicationSettings().Configuration().IgnoreServerConnectionLost) if (!Manager.GetApplicationSettings().Configuration().IgnoreServerConnectionLost)
{ {
Console.WriteLine(loc["SERVER_ERROR_COMMUNICATION"].FormatExt($"{IP}:{Port}")); Console.WriteLine(loc["SERVER_ERROR_COMMUNICATION"].FormatExt($"{ListenAddress}:{ListenPort}"));
var alert = Alert.AlertState.Build().OfType(E.Type.ToString()) var alert = Alert.AlertState.Build().OfType(E.Type.ToString())
.WithCategory(Alert.AlertCategory.Error) .WithCategory(Alert.AlertCategory.Error)
.FromSource("System") .FromSource("System")
.WithMessage(loc["SERVER_ERROR_COMMUNICATION"].FormatExt($"{IP}:{Port}")) .WithMessage(loc["SERVER_ERROR_COMMUNICATION"].FormatExt($"{ListenAddress}:{ListenPort}"))
.ExpiresIn(TimeSpan.FromDays(1)); .ExpiresIn(TimeSpan.FromDays(1));
Manager.AlertManager.AddAlert(alert); Manager.AlertManager.AddAlert(alert);
@ -328,12 +328,12 @@ namespace IW4MAdmin
if (!Manager.GetApplicationSettings().Configuration().IgnoreServerConnectionLost) if (!Manager.GetApplicationSettings().Configuration().IgnoreServerConnectionLost)
{ {
Console.WriteLine(loc["MANAGER_CONNECTION_REST"].FormatExt($"{IP}:{Port}")); Console.WriteLine(loc["MANAGER_CONNECTION_REST"].FormatExt($"{ListenAddress}:{ListenPort}"));
var alert = Alert.AlertState.Build().OfType(E.Type.ToString()) var alert = Alert.AlertState.Build().OfType(E.Type.ToString())
.WithCategory(Alert.AlertCategory.Information) .WithCategory(Alert.AlertCategory.Information)
.FromSource("System") .FromSource("System")
.WithMessage(loc["MANAGER_CONNECTION_REST"].FormatExt($"{IP}:{Port}")) .WithMessage(loc["MANAGER_CONNECTION_REST"].FormatExt($"{ListenAddress}:{ListenPort}"))
.ExpiresIn(TimeSpan.FromDays(1)); .ExpiresIn(TimeSpan.FromDays(1));
Manager.AlertManager.AddAlert(alert); Manager.AlertManager.AddAlert(alert);
@ -1159,7 +1159,7 @@ namespace IW4MAdmin
ServerLogger.LogError(e, "Unexpected exception occured during processing updates"); ServerLogger.LogError(e, "Unexpected exception occured during processing updates");
} }
Console.WriteLine(loc["SERVER_ERROR_EXCEPTION"].FormatExt($"[{IP}:{Port}]")); Console.WriteLine(loc["SERVER_ERROR_EXCEPTION"].FormatExt($"[{ListenAddress}:{ListenPort}]"));
return false; return false;
} }
} }
@ -1198,13 +1198,13 @@ namespace IW4MAdmin
{ {
ResolvedIpEndPoint = ResolvedIpEndPoint =
new IPEndPoint( new IPEndPoint(
(await Dns.GetHostAddressesAsync(IP)).First(address => (await Dns.GetHostAddressesAsync(ListenAddress)).First(address =>
address.AddressFamily == AddressFamily.InterNetwork), Port); address.AddressFamily == AddressFamily.InterNetwork), ListenPort);
} }
catch (Exception ex) catch (Exception ex)
{ {
ServerLogger.LogWarning(ex, "Could not resolve hostname or IP for RCon connection {IP}:{Port}", IP, Port); ServerLogger.LogWarning(ex, "Could not resolve hostname or IP for RCon connection {Address}:{Port}", ListenAddress, ListenPort);
ResolvedIpEndPoint = new IPEndPoint(IPAddress.Parse(IP), Port); ResolvedIpEndPoint = new IPEndPoint(IPAddress.Parse(ListenAddress), ListenPort);
} }
RconParser = Manager.AdditionalRConParsers RconParser = Manager.AdditionalRConParsers

View File

@ -103,17 +103,15 @@ namespace IW4MAdmin.Application.Misc
await UploadStatus(); await UploadStatus();
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogWarning(ex, "Could not send heartbeat"); _logger.LogWarning("Could not send heartbeat - {Message}", ex.Message);
} }
try try
{ {
await Task.Delay(Interval, token); await Task.Delay(Interval, token);
} }
catch catch
{ {
break; break;
@ -149,13 +147,13 @@ namespace IW4MAdmin.Application.Misc
Map = s.CurrentMap.Name, Map = s.CurrentMap.Name,
MaxClientNum = s.MaxClients, MaxClientNum = s.MaxClients,
Id = s.EndPoint, Id = s.EndPoint,
Port = (short)s.Port, Port = (short)s.ListenPort,
IPAddress = s.IP IPAddress = s.ListenAddress
}).ToList(), }).ToList(),
WebfrontUrl = _appConfig.WebfrontUrl WebfrontUrl = _appConfig.WebfrontUrl
}; };
Response<ResultMessage> response = null; Response<ResultMessage> response;
if (_firstHeartBeat) if (_firstHeartBeat)
{ {
@ -170,7 +168,7 @@ namespace IW4MAdmin.Application.Misc
if (response.ResponseMessage.StatusCode != System.Net.HttpStatusCode.OK) if (response.ResponseMessage.StatusCode != System.Net.HttpStatusCode.OK)
{ {
_logger.LogWarning("Non success response code from master is {statusCode}, message is {message}", response.ResponseMessage.StatusCode, response.StringContent); _logger.LogWarning("Non success response code from master is {StatusCode}, message is {Message}", response.ResponseMessage.StatusCode, response.StringContent);
} }
} }
} }

View File

@ -85,9 +85,14 @@ namespace SharedLibraryCore
InitializeAutoMessages(); InitializeAutoMessages();
} }
public long EndPoint => IPAddress.TryParse(IP, out _) public long EndPoint => IPAddress.TryParse(ListenAddress, out _)
? Convert.ToInt64($"{IP.Replace(".", "")}{Port}") ? Convert.ToInt64($"{ListenAddress!.Replace(".", "")}{ListenPort}")
: $"{IP.Replace(".", "")}{Port}".GetStableHashCode(); : $"{ListenAddress!.Replace(".", "")}{ListenPort}".GetStableHashCode();
public long LegacyEndpoint => EndPoint;
public abstract long LegacyDatabaseId { get; }
public string Id => $"{ListenAddress}:{ListenPort}";
// Objects // Objects
public IManager Manager { get; protected set; } public IManager Manager { get; protected set; }
@ -142,6 +147,8 @@ namespace SharedLibraryCore
/// </summary> /// </summary>
public string IP { get; protected set; } public string IP { get; protected set; }
public string ListenAddress => IP;
public IPEndPoint ResolvedIpEndPoint { get; protected set; } public IPEndPoint ResolvedIpEndPoint { get; protected set; }
public string Version { get; protected set; } public string Version { get; protected set; }
public bool IsInitialized { get; set; } public bool IsInitialized { get; set; }
@ -391,7 +398,7 @@ namespace SharedLibraryCore
public override string ToString() public override string ToString()
{ {
return $"{IP}:{Port}"; return $"{ListenAddress}:{ListenPort}";
} }
protected async Task<bool> ScriptLoaded() protected async Task<bool> ScriptLoaded()

View File

@ -1242,7 +1242,7 @@ namespace SharedLibraryCore
var serverConfig = appConfig.Servers? var serverConfig = appConfig.Servers?
.FirstOrDefault(configServer => .FirstOrDefault(configServer =>
configServer.IPAddress == server.IP && configServer.Port == server.Port); configServer.IPAddress == server.ListenAddress && configServer.Port == server.ListenPort);
var allRules = appConfig.GlobalRules?.ToList() ?? new List<string>(); var allRules = appConfig.GlobalRules?.ToList() ?? new List<string>();
if (serverConfig?.Rules != null) if (serverConfig?.Rules != null)

View File

@ -1,82 +1,62 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore; using SharedLibraryCore;
using SharedLibraryCore.Events;
using SharedLibraryCore.Interfaces; using SharedLibraryCore.Interfaces;
using System.Linq; using System.Linq;
namespace WebfrontCore.Controllers.API namespace WebfrontCore.Controllers.API;
public class ApiController : BaseController
{ {
public class ApiController : BaseController public ApiController(IManager manager) : base(manager)
{ {
public ApiController(IManager manager) : base(manager)
{
} }
public IActionResult Index() public IActionResult Index()
{ {
return Ok($"IW4MAdmin API"); return Ok("IW4MAdmin API");
} }
[HttpGet] [HttpGet]
public IActionResult Event(bool shouldConsume = true) public IActionResult Event()
{ {
var events = EventApi.GetEvents(shouldConsume); return NotFound("This API endpoint is no longer supported");
return Json(events); }
}
[HttpGet] [HttpGet]
public IActionResult Status(long? id) public IActionResult Status(long? id)
{ {
var serverInfo = Manager.GetServers() var serverInfo = Manager.GetServers()
.Select(server => new .Select(server => new
{
Id = server.EndPoint,
IsOnline = !server.Throttled,
Name = server.Hostname,
MaxPlayers = server.MaxClients,
CurrentPlayers = server.GetClientsAsList().Count,
Map = server.CurrentMap,
GameMode = server.Gametype,
server.Port,
Game = server.GameName.ToString(),
Players = server.GetClientsAsList()
.Select(player => new
{
player.Name,
player.Score,
player.Ping,
State = player.State.ToString(),
player.ClientNumber,
ConnectionTime = player.ConnectionLength,
Level = player.Level.ToLocalizedLevelName(),
})
});
if (id != null)
{ {
serverInfo = serverInfo.Where(server => server.Id == id); Id = server.EndPoint,
} IsOnline = !server.Throttled,
Name = server.ServerName,
MaxPlayers = server.MaxClients,
CurrentPlayers = server.GetClientsAsList().Count,
Map = server.CurrentMap,
GameMode = server.Gametype,
server.ListenAddress,
server.ListenPort,
Game = server.GameName.ToString(),
Players = server.GetClientsAsList()
.Select(player => new
{
player.Name,
player.Score,
player.Ping,
State = player.State.ToString(),
player.ClientNumber,
ConnectionTime = player.ConnectionLength,
Level = player.Level.ToLocalizedLevelName(),
})
});
return Json(serverInfo); if (id != null)
}
[HttpGet]
public IActionResult RestartApproved()
{ {
var serverToRestart = Manager.GetServers().FirstOrDefault(_server => _server.RestartRequested); serverInfo = serverInfo.Where(server => server.Id == id);
if (serverToRestart != null)
{
serverToRestart.RestartRequested = false;
}
return serverToRestart != null ?
(IActionResult)Json(new
{
port = serverToRestart.Port
}) :
Unauthorized();
} }
return Json(serverInfo);
} }
} }

View File

@ -23,9 +23,9 @@ namespace WebfrontCore.Controllers.API
return new JsonResult(Manager.GetServers().Select(server => new return new JsonResult(Manager.GetServers().Select(server => new
{ {
Id = server.EndPoint, Id = server.EndPoint,
server.Hostname, server.ServerName,
server.IP, server.ListenAddress,
server.Port, server.ListenPort,
Game = server.GameName.ToString(), Game = server.GameName.ToString(),
server.ClientNum, server.ClientNum,
server.MaxClients, server.MaxClients,
@ -52,9 +52,9 @@ namespace WebfrontCore.Controllers.API
return new JsonResult(new return new JsonResult(new
{ {
Id = foundServer.EndPoint, Id = foundServer.EndPoint,
foundServer.Hostname, foundServer.ServerName,
foundServer.IP, foundServer.ListenAddress,
foundServer.Port, foundServer.ListenPort,
Game = foundServer.GameName.ToString(), Game = foundServer.GameName.ToString(),
foundServer.ClientNum, foundServer.ClientNum,
foundServer.MaxClients, foundServer.MaxClients,

View File

@ -28,7 +28,7 @@ namespace WebfrontCore.Controllers
: _appConfig.CommunityInformation.Name; : _appConfig.CommunityInformation.Name;
var activeServers = _appConfig.Servers.Where(server => var activeServers = _appConfig.Servers.Where(server =>
Manager.GetServers().FirstOrDefault(s => s.IP == server.IPAddress && s.Port == server.Port) != null); Manager.GetServers().FirstOrDefault(s => s.ListenAddress == server.IPAddress && s.ListenPort == server.Port) != null);
var info = new CommunityInfo var info = new CommunityInfo
{ {
@ -36,9 +36,9 @@ namespace WebfrontCore.Controllers
ServerRules = activeServers.ToDictionary( ServerRules = activeServers.ToDictionary(
config => config =>
{ {
var server = Manager.GetServers().FirstOrDefault(server => var server = Manager.GetServers().First(server =>
server.IP == config.IPAddress && server.Port == config.Port); server.ListenAddress == config.IPAddress && server.ListenPort == config.Port);
return (server.Hostname, server.EndPoint); return (server.ServerName, server.EndPoint);
}, },
config => config.Rules), config => config.Rules),
CommunityInformation = _appConfig.CommunityInformation CommunityInformation = _appConfig.CommunityInformation

View File

@ -143,8 +143,8 @@ namespace WebfrontCore.Controllers
ConnectProtocolUrl = ingameClient?.CurrentServer.EventParser.URLProtocolFormat.FormatExt( ConnectProtocolUrl = ingameClient?.CurrentServer.EventParser.URLProtocolFormat.FormatExt(
ingameClient.CurrentServer.ResolvedIpEndPoint.Address.IsInternal() ingameClient.CurrentServer.ResolvedIpEndPoint.Address.IsInternal()
? Program.Manager.ExternalIPAddress ? Program.Manager.ExternalIPAddress
: ingameClient.CurrentServer.IP, : ingameClient.CurrentServer.ListenAddress,
ingameClient.CurrentServer.Port), ingameClient.CurrentServer.ListenPort),
CurrentServerName = ingameClient?.CurrentServer?.Hostname, CurrentServerName = ingameClient?.CurrentServer?.Hostname,
GeoLocationInfo = await _geoLocationService.Locate(client.IPAddressString), GeoLocationInfo = await _geoLocationService.Locate(client.IPAddressString),
NoteMeta = string.IsNullOrWhiteSpace(note?.Note) ? null: note, NoteMeta = string.IsNullOrWhiteSpace(note?.Note) ? null: note,

View File

@ -93,10 +93,10 @@ namespace WebfrontCore.ViewComponents
}).ToList(), }).ToList(),
ChatHistory = server.ChatHistory.ToList(), ChatHistory = server.ChatHistory.ToList(),
Online = !server.Throttled, Online = !server.Throttled,
IPAddress = server.IP, IPAddress = server.ListenAddress,
ExternalIPAddress = server.ResolvedIpEndPoint.Address.IsInternal() ? Program.Manager.ExternalIPAddress : server.IP, ExternalIPAddress = server.ResolvedIpEndPoint.Address.IsInternal() ? Program.Manager.ExternalIPAddress : server.ListenAddress,
ConnectProtocolUrl = server.EventParser.URLProtocolFormat.FormatExt( ConnectProtocolUrl = server.EventParser.URLProtocolFormat.FormatExt(
server.ResolvedIpEndPoint.Address.IsInternal() ? Program.Manager.ExternalIPAddress : server.IP, server.ResolvedIpEndPoint.Address.IsInternal() ? Program.Manager.ExternalIPAddress : server.ListenAddress,
server.ListenPort) server.ListenPort)
}); });
} }