From a2c7d9216225a123b91c6f40ac532d5f6c28063e Mon Sep 17 00:00:00 2001 From: RaidMax Date: Tue, 19 Oct 2021 20:02:31 -0500 Subject: [PATCH] fix issue on about page with duplicate server names or inactive servers --- WebfrontCore/Controllers/AboutController.cs | 16 +++++++++++----- WebfrontCore/ViewModels/CommunityInfo.cs | 2 +- WebfrontCore/Views/About/Index.cshtml | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/WebfrontCore/Controllers/AboutController.cs b/WebfrontCore/Controllers/AboutController.cs index 7ae540655..ab2d8c5b9 100644 --- a/WebfrontCore/Controllers/AboutController.cs +++ b/WebfrontCore/Controllers/AboutController.cs @@ -27,14 +27,20 @@ namespace WebfrontCore.Controllers ? Localization["WEBFRONT_NAV_ABOUT"] : _appConfig.CommunityInformation.Name; + var activeServers = _appConfig.Servers.Where(server => + Manager.GetServers().FirstOrDefault(s => s.IP == server.IPAddress && s.Port == server.Port) != null); + var info = new CommunityInfo { GlobalRules = _appConfig.GlobalRules, - ServerRules = - _appConfig.Servers.ToDictionary( - config => Manager.GetServers().FirstOrDefault(server => - server.IP == config.IPAddress && server.Port == config.Port)?.Hostname, - config => config.Rules), + ServerRules = activeServers.ToDictionary( + config => + { + var server = Manager.GetServers().FirstOrDefault(server => + server.IP == config.IPAddress && server.Port == config.Port); + return (server.Hostname, server.EndPoint); + }, + config => config.Rules), CommunityInformation = _appConfig.CommunityInformation }; diff --git a/WebfrontCore/ViewModels/CommunityInfo.cs b/WebfrontCore/ViewModels/CommunityInfo.cs index 5ccf5be8e..9a01da960 100644 --- a/WebfrontCore/ViewModels/CommunityInfo.cs +++ b/WebfrontCore/ViewModels/CommunityInfo.cs @@ -6,7 +6,7 @@ namespace WebfrontCore.ViewModels public class CommunityInfo { public string[] GlobalRules { get; set; } - public Dictionary ServerRules { get; set; } + public Dictionary<(string, long), string[]> ServerRules { get; set; } public CommunityInformationConfiguration CommunityInformation { get; set; } } } \ No newline at end of file diff --git a/WebfrontCore/Views/About/Index.cshtml b/WebfrontCore/Views/About/Index.cshtml index d18cdc816..1c45e28b8 100644 --- a/WebfrontCore/Views/About/Index.cshtml +++ b/WebfrontCore/Views/About/Index.cshtml @@ -1,7 +1,7 @@ @using SharedLibraryCore.Configuration @model WebfrontCore.ViewModels.CommunityInfo @{ - IEnumerable> allRules = new[] {new KeyValuePair(ViewBag.Localization["WEBFRONT_ABOUT_GLOBAL_RULES"], Model.GlobalRules)}; + IEnumerable> allRules = new[] {new KeyValuePair<(string, long), string[]>((ViewBag.Localization["WEBFRONT_ABOUT_GLOBAL_RULES"], 0), Model.GlobalRules)}; var serverRules = Model.ServerRules?.Where(server => server.Value != null && server.Value.Any()).ToList(); if (serverRules?.Any() ?? false) { @@ -56,7 +56,7 @@

@ViewBag.Localization["WEBFRONT_ABOUT_COMMUNITY_GUIDELINES"]

} - @foreach (var (serverName, rules) in allRules) + @foreach (var ((serverName, id), rules) in allRules) { if (!rules.Any()) {