update references from IP to ListenAddress
This commit is contained in:
parent
6fa172d757
commit
2e726ea9ed
@ -307,12 +307,12 @@ namespace IW4MAdmin
|
||||
|
||||
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())
|
||||
.WithCategory(Alert.AlertCategory.Error)
|
||||
.FromSource("System")
|
||||
.WithMessage(loc["SERVER_ERROR_COMMUNICATION"].FormatExt($"{IP}:{Port}"))
|
||||
.WithMessage(loc["SERVER_ERROR_COMMUNICATION"].FormatExt($"{ListenAddress}:{ListenPort}"))
|
||||
.ExpiresIn(TimeSpan.FromDays(1));
|
||||
|
||||
Manager.AlertManager.AddAlert(alert);
|
||||
@ -328,12 +328,12 @@ namespace IW4MAdmin
|
||||
|
||||
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())
|
||||
.WithCategory(Alert.AlertCategory.Information)
|
||||
.FromSource("System")
|
||||
.WithMessage(loc["MANAGER_CONNECTION_REST"].FormatExt($"{IP}:{Port}"))
|
||||
.WithMessage(loc["MANAGER_CONNECTION_REST"].FormatExt($"{ListenAddress}:{ListenPort}"))
|
||||
.ExpiresIn(TimeSpan.FromDays(1));
|
||||
|
||||
Manager.AlertManager.AddAlert(alert);
|
||||
@ -1159,7 +1159,7 @@ namespace IW4MAdmin
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -1198,13 +1198,13 @@ namespace IW4MAdmin
|
||||
{
|
||||
ResolvedIpEndPoint =
|
||||
new IPEndPoint(
|
||||
(await Dns.GetHostAddressesAsync(IP)).First(address =>
|
||||
address.AddressFamily == AddressFamily.InterNetwork), Port);
|
||||
(await Dns.GetHostAddressesAsync(ListenAddress)).First(address =>
|
||||
address.AddressFamily == AddressFamily.InterNetwork), ListenPort);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ServerLogger.LogWarning(ex, "Could not resolve hostname or IP for RCon connection {IP}:{Port}", IP, Port);
|
||||
ResolvedIpEndPoint = new IPEndPoint(IPAddress.Parse(IP), Port);
|
||||
ServerLogger.LogWarning(ex, "Could not resolve hostname or IP for RCon connection {Address}:{Port}", ListenAddress, ListenPort);
|
||||
ResolvedIpEndPoint = new IPEndPoint(IPAddress.Parse(ListenAddress), ListenPort);
|
||||
}
|
||||
|
||||
RconParser = Manager.AdditionalRConParsers
|
||||
|
@ -103,17 +103,15 @@ namespace IW4MAdmin.Application.Misc
|
||||
await UploadStatus();
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Could not send heartbeat");
|
||||
_logger.LogWarning("Could not send heartbeat - {Message}", ex.Message);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Delay(Interval, token);
|
||||
}
|
||||
|
||||
catch
|
||||
{
|
||||
break;
|
||||
@ -149,13 +147,13 @@ namespace IW4MAdmin.Application.Misc
|
||||
Map = s.CurrentMap.Name,
|
||||
MaxClientNum = s.MaxClients,
|
||||
Id = s.EndPoint,
|
||||
Port = (short)s.Port,
|
||||
IPAddress = s.IP
|
||||
Port = (short)s.ListenPort,
|
||||
IPAddress = s.ListenAddress
|
||||
}).ToList(),
|
||||
WebfrontUrl = _appConfig.WebfrontUrl
|
||||
};
|
||||
|
||||
Response<ResultMessage> response = null;
|
||||
Response<ResultMessage> response;
|
||||
|
||||
if (_firstHeartBeat)
|
||||
{
|
||||
@ -170,7 +168,7 @@ namespace IW4MAdmin.Application.Misc
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -85,9 +85,14 @@ namespace SharedLibraryCore
|
||||
InitializeAutoMessages();
|
||||
}
|
||||
|
||||
public long EndPoint => IPAddress.TryParse(IP, out _)
|
||||
? Convert.ToInt64($"{IP.Replace(".", "")}{Port}")
|
||||
: $"{IP.Replace(".", "")}{Port}".GetStableHashCode();
|
||||
public long EndPoint => IPAddress.TryParse(ListenAddress, out _)
|
||||
? Convert.ToInt64($"{ListenAddress!.Replace(".", "")}{ListenPort}")
|
||||
: $"{ListenAddress!.Replace(".", "")}{ListenPort}".GetStableHashCode();
|
||||
|
||||
public long LegacyEndpoint => EndPoint;
|
||||
|
||||
public abstract long LegacyDatabaseId { get; }
|
||||
public string Id => $"{ListenAddress}:{ListenPort}";
|
||||
|
||||
// Objects
|
||||
public IManager Manager { get; protected set; }
|
||||
@ -142,6 +147,8 @@ namespace SharedLibraryCore
|
||||
/// </summary>
|
||||
public string IP { get; protected set; }
|
||||
|
||||
public string ListenAddress => IP;
|
||||
|
||||
public IPEndPoint ResolvedIpEndPoint { get; protected set; }
|
||||
public string Version { get; protected set; }
|
||||
public bool IsInitialized { get; set; }
|
||||
@ -391,7 +398,7 @@ namespace SharedLibraryCore
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{IP}:{Port}";
|
||||
return $"{ListenAddress}:{ListenPort}";
|
||||
}
|
||||
|
||||
protected async Task<bool> ScriptLoaded()
|
||||
|
@ -1242,7 +1242,7 @@ namespace SharedLibraryCore
|
||||
|
||||
var serverConfig = appConfig.Servers?
|
||||
.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>();
|
||||
if (serverConfig?.Rules != null)
|
||||
|
@ -1,82 +1,62 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Events;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
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()
|
||||
{
|
||||
return Ok($"IW4MAdmin API");
|
||||
}
|
||||
public IActionResult Index()
|
||||
{
|
||||
return Ok("IW4MAdmin API");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Event(bool shouldConsume = true)
|
||||
{
|
||||
var events = EventApi.GetEvents(shouldConsume);
|
||||
return Json(events);
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Event()
|
||||
{
|
||||
return NotFound("This API endpoint is no longer supported");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Status(long? id)
|
||||
{
|
||||
var serverInfo = Manager.GetServers()
|
||||
.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)
|
||||
[HttpGet]
|
||||
public IActionResult Status(long? id)
|
||||
{
|
||||
var serverInfo = Manager.GetServers()
|
||||
.Select(server => new
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult RestartApproved()
|
||||
if (id != null)
|
||||
{
|
||||
var serverToRestart = Manager.GetServers().FirstOrDefault(_server => _server.RestartRequested);
|
||||
|
||||
if (serverToRestart != null)
|
||||
{
|
||||
serverToRestart.RestartRequested = false;
|
||||
}
|
||||
|
||||
return serverToRestart != null ?
|
||||
(IActionResult)Json(new
|
||||
{
|
||||
port = serverToRestart.Port
|
||||
}) :
|
||||
Unauthorized();
|
||||
serverInfo = serverInfo.Where(server => server.Id == id);
|
||||
}
|
||||
|
||||
return Json(serverInfo);
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,9 @@ namespace WebfrontCore.Controllers.API
|
||||
return new JsonResult(Manager.GetServers().Select(server => new
|
||||
{
|
||||
Id = server.EndPoint,
|
||||
server.Hostname,
|
||||
server.IP,
|
||||
server.Port,
|
||||
server.ServerName,
|
||||
server.ListenAddress,
|
||||
server.ListenPort,
|
||||
Game = server.GameName.ToString(),
|
||||
server.ClientNum,
|
||||
server.MaxClients,
|
||||
@ -52,9 +52,9 @@ namespace WebfrontCore.Controllers.API
|
||||
return new JsonResult(new
|
||||
{
|
||||
Id = foundServer.EndPoint,
|
||||
foundServer.Hostname,
|
||||
foundServer.IP,
|
||||
foundServer.Port,
|
||||
foundServer.ServerName,
|
||||
foundServer.ListenAddress,
|
||||
foundServer.ListenPort,
|
||||
Game = foundServer.GameName.ToString(),
|
||||
foundServer.ClientNum,
|
||||
foundServer.MaxClients,
|
||||
|
@ -28,7 +28,7 @@ namespace WebfrontCore.Controllers
|
||||
: _appConfig.CommunityInformation.Name;
|
||||
|
||||
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
|
||||
{
|
||||
@ -36,9 +36,9 @@ namespace WebfrontCore.Controllers
|
||||
ServerRules = activeServers.ToDictionary(
|
||||
config =>
|
||||
{
|
||||
var server = Manager.GetServers().FirstOrDefault(server =>
|
||||
server.IP == config.IPAddress && server.Port == config.Port);
|
||||
return (server.Hostname, server.EndPoint);
|
||||
var server = Manager.GetServers().First(server =>
|
||||
server.ListenAddress == config.IPAddress && server.ListenPort == config.Port);
|
||||
return (server.ServerName, server.EndPoint);
|
||||
},
|
||||
config => config.Rules),
|
||||
CommunityInformation = _appConfig.CommunityInformation
|
||||
|
@ -143,8 +143,8 @@ namespace WebfrontCore.Controllers
|
||||
ConnectProtocolUrl = ingameClient?.CurrentServer.EventParser.URLProtocolFormat.FormatExt(
|
||||
ingameClient.CurrentServer.ResolvedIpEndPoint.Address.IsInternal()
|
||||
? Program.Manager.ExternalIPAddress
|
||||
: ingameClient.CurrentServer.IP,
|
||||
ingameClient.CurrentServer.Port),
|
||||
: ingameClient.CurrentServer.ListenAddress,
|
||||
ingameClient.CurrentServer.ListenPort),
|
||||
CurrentServerName = ingameClient?.CurrentServer?.Hostname,
|
||||
GeoLocationInfo = await _geoLocationService.Locate(client.IPAddressString),
|
||||
NoteMeta = string.IsNullOrWhiteSpace(note?.Note) ? null: note,
|
||||
|
@ -93,10 +93,10 @@ namespace WebfrontCore.ViewComponents
|
||||
}).ToList(),
|
||||
ChatHistory = server.ChatHistory.ToList(),
|
||||
Online = !server.Throttled,
|
||||
IPAddress = server.IP,
|
||||
ExternalIPAddress = server.ResolvedIpEndPoint.Address.IsInternal() ? Program.Manager.ExternalIPAddress : server.IP,
|
||||
IPAddress = server.ListenAddress,
|
||||
ExternalIPAddress = server.ResolvedIpEndPoint.Address.IsInternal() ? Program.Manager.ExternalIPAddress : server.ListenAddress,
|
||||
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)
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user