Fix rules popup (#8485)

* CVar to show rules popup for localhost.

For testing purposes.

* Fix rules popup being broken and throwing.

😐
This commit is contained in:
Pieter-Jan Briers
2022-05-27 23:50:11 +02:00
committed by GitHub
parent 38368d1341
commit 4c1b0b87fb
4 changed files with 31 additions and 8 deletions

View File

@@ -1,9 +1,11 @@
using Content.Client.EscapeMenu.UI; using Content.Client.EscapeMenu.UI;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Robust.Client.ResourceManagement; using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
using Robust.Shared.ContentPack;
namespace Content.Client.Info namespace Content.Client.Info
{ {
@@ -44,7 +46,7 @@ namespace Content.Client.Info
private void PopulateRules(Info rulesList) 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) private void PopulateTutorial(Info tutorialList)
@@ -58,10 +60,24 @@ namespace Content.Client.Info
infoControlSection.ControlsButton.OnPressed += _ => optionsMenu.OpenCentered(); 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) private void AddSection(Info info, string title, string path, bool markup = false)
{ {
info.InfoContainer.AddChild(new InfoSection(title, AddSection(info, MakeSection(title, path, markup, _resourceManager));
_resourceManager.ContentFileReadAllText($"/Server Info/{path}"), markup)); }
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);
} }
} }
} }

View File

@@ -19,9 +19,6 @@ public sealed partial class RulesControl : BoxContainer
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
var path = "Server Info/" + _cfgManager.GetCVar(CCVars.RulesFile); AddChild(RulesAndInfoWindow.MakeRules(_cfgManager, _resourceManager));
AddChild(new InfoSection(Loc.GetString("ui-rules-header"),
_resourceManager.ContentFileReadAllText(path), true));
} }
} }

View File

@@ -1,6 +1,8 @@
using System.Net; using System.Net;
using Content.Server.Database; using Content.Server.Database;
using Content.Shared.CCVar;
using Content.Shared.Info; using Content.Shared.Info;
using Robust.Shared.Configuration;
using Robust.Shared.Network; using Robust.Shared.Network;
namespace Content.Server.Info; namespace Content.Server.Info;
@@ -9,6 +11,7 @@ public sealed class RulesManager : SharedRulesManager
{ {
[Dependency] private readonly IServerDbManager _dbManager = default!; [Dependency] private readonly IServerDbManager _dbManager = default!;
[Dependency] private readonly INetManager _netManager = default!; [Dependency] private readonly INetManager _netManager = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
private static DateTime LastValidReadTime => DateTime.UtcNow - TimeSpan.FromDays(60); 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) 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; return;
} }

View File

@@ -906,6 +906,13 @@ namespace Content.Shared.CCVar
public static readonly CVarDef<float> RulesWaitTime = public static readonly CVarDef<float> RulesWaitTime =
CVarDef.Create("rules.time", 45f, CVar.SERVER | CVar.REPLICATED); CVarDef.Create("rules.time", 45f, CVar.SERVER | CVar.REPLICATED);
/// <summary>
/// Don't show rules to localhost/loopback interface.
/// </summary>
public static readonly CVarDef<bool> RulesExemptLocal =
CVarDef.Create("rules.exempt_local", true, CVar.SERVERONLY);
/* /*
* Autogeneration * Autogeneration
*/ */