From 4c1b0b87fbc9d85818053c8f7117f0ce767ac112 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Fri, 27 May 2022 23:50:11 +0200 Subject: [PATCH] Fix rules popup (#8485) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * CVar to show rules popup for localhost. For testing purposes. * Fix rules popup being broken and throwing. 😐 --- Content.Client/Info/RulesAndInfoWindow.cs | 22 +++++++++++++++++++--- Content.Client/Info/RulesControl.xaml.cs | 5 +---- Content.Server/Info/RulesManager.cs | 5 ++++- Content.Shared/CCVar/CCVars.cs | 7 +++++++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Content.Client/Info/RulesAndInfoWindow.cs b/Content.Client/Info/RulesAndInfoWindow.cs index 966f60a5f5..697f395402 100644 --- a/Content.Client/Info/RulesAndInfoWindow.cs +++ b/Content.Client/Info/RulesAndInfoWindow.cs @@ -1,9 +1,11 @@ using Content.Client.EscapeMenu.UI; using Content.Shared.CCVar; using Robust.Client.ResourceManagement; +using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; using Robust.Shared.Configuration; +using Robust.Shared.ContentPack; namespace Content.Client.Info { @@ -44,7 +46,7 @@ namespace Content.Client.Info private void PopulateRules(Info rulesList) { - AddSection(rulesList, Loc.GetString("ui-rules-header"), _cfgManager.GetCVar(CCVars.RulesFile), true); + AddSection(rulesList, MakeRules(_cfgManager, _resourceManager)); } private void PopulateTutorial(Info tutorialList) @@ -58,10 +60,24 @@ namespace Content.Client.Info infoControlSection.ControlsButton.OnPressed += _ => optionsMenu.OpenCentered(); } + private static void AddSection(Info info, Control control) + { + info.InfoContainer.AddChild(control); + } + private void AddSection(Info info, string title, string path, bool markup = false) { - info.InfoContainer.AddChild(new InfoSection(title, - _resourceManager.ContentFileReadAllText($"/Server Info/{path}"), markup)); + AddSection(info, MakeSection(title, path, markup, _resourceManager)); + } + + private static Control MakeSection(string title, string path, bool markup, IResourceManager res) + { + return new InfoSection(title, res.ContentFileReadAllText($"/Server Info/{path}"), markup); + } + + public static Control MakeRules(IConfigurationManager cfg, IResourceManager res) + { + return MakeSection(Loc.GetString("ui-rules-header"), cfg.GetCVar(CCVars.RulesFile), true, res); } } } diff --git a/Content.Client/Info/RulesControl.xaml.cs b/Content.Client/Info/RulesControl.xaml.cs index 2c6f6e7831..4470094b92 100644 --- a/Content.Client/Info/RulesControl.xaml.cs +++ b/Content.Client/Info/RulesControl.xaml.cs @@ -19,9 +19,6 @@ public sealed partial class RulesControl : BoxContainer RobustXamlLoader.Load(this); IoCManager.InjectDependencies(this); - var path = "Server Info/" + _cfgManager.GetCVar(CCVars.RulesFile); - - AddChild(new InfoSection(Loc.GetString("ui-rules-header"), - _resourceManager.ContentFileReadAllText(path), true)); + AddChild(RulesAndInfoWindow.MakeRules(_cfgManager, _resourceManager)); } } diff --git a/Content.Server/Info/RulesManager.cs b/Content.Server/Info/RulesManager.cs index dc70070161..d9d744dcbd 100644 --- a/Content.Server/Info/RulesManager.cs +++ b/Content.Server/Info/RulesManager.cs @@ -1,6 +1,8 @@ using System.Net; using Content.Server.Database; +using Content.Shared.CCVar; using Content.Shared.Info; +using Robust.Shared.Configuration; using Robust.Shared.Network; namespace Content.Server.Info; @@ -9,6 +11,7 @@ public sealed class RulesManager : SharedRulesManager { [Dependency] private readonly IServerDbManager _dbManager = default!; [Dependency] private readonly INetManager _netManager = default!; + [Dependency] private readonly IConfigurationManager _cfg = default!; private static DateTime LastValidReadTime => DateTime.UtcNow - TimeSpan.FromDays(60); @@ -22,7 +25,7 @@ public sealed class RulesManager : SharedRulesManager private async void OnConnected(object? sender, NetChannelArgs e) { - if (IPAddress.IsLoopback(e.Channel.RemoteEndPoint.Address)) + if (IPAddress.IsLoopback(e.Channel.RemoteEndPoint.Address) && _cfg.GetCVar(CCVars.RulesExemptLocal)) { return; } diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 329a374391..6f4d1fc8fd 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -906,6 +906,13 @@ namespace Content.Shared.CCVar public static readonly CVarDef RulesWaitTime = CVarDef.Create("rules.time", 45f, CVar.SERVER | CVar.REPLICATED); + /// + /// Don't show rules to localhost/loopback interface. + /// + public static readonly CVarDef RulesExemptLocal = + CVarDef.Create("rules.exempt_local", true, CVar.SERVERONLY); + + /* * Autogeneration */