Fixes client having authority over rules popup cvars (#28655)

* Fixes client having authority over rules popup cvars

* Delete duplicate migration

* Pre-update

* Post-update
This commit is contained in:
AJCM-git
2024-06-07 15:53:20 -04:00
committed by GitHub
parent a1a3a0d131
commit 63e0ee08cb
16 changed files with 3930 additions and 36 deletions

View File

@@ -1,13 +1,9 @@
using System.Globalization;
using Content.Client.Gameplay;
using Content.Client.Info;
using Content.Shared.Administration.Managers;
using Content.Shared.CCVar;
using Content.Shared.Guidebook;
using Content.Shared.Info;
using Robust.Client;
using Robust.Client.Console;
using Robust.Client.Player;
using Robust.Client.UserInterface.Controllers;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Configuration;
@@ -18,24 +14,20 @@ namespace Content.Client.UserInterface.Systems.Info;
public sealed class InfoUIController : UIController, IOnStateExited<GameplayState>
{
[Dependency] private readonly IBaseClient _client = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
[Dependency] private readonly INetManager _netManager = default!;
[Dependency] private readonly ISharedAdminManager _adminManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
private RulesPopup? _rulesPopup;
private RulesAndInfoWindow? _infoWindow;
private static DateTime NextRulesReadTime => DateTime.UtcNow + TimeSpan.FromDays(60);
public override void Initialize()
{
base.Initialize();
_client.PlayerJoinedServer += OnJoinedServer;
_netManager.RegisterNetMessage<RulesAcceptedMessage>();
_netManager.RegisterNetMessage<ShowRulesPopupMessage>(OnShowRulesPopupMessage);
_consoleHost.RegisterCommand("fuckrules",
@@ -47,22 +39,6 @@ public sealed class InfoUIController : UIController, IOnStateExited<GameplayStat
});
}
private void OnJoinedServer(object? sender, PlayerEventArgs args)
{
if (_playerManager.LocalSession is not { } localSession)
return;
if (_adminManager.IsAdmin(localSession) && _cfg.GetCVar(CCVars.RulesExemptLocal))
return;
var nextReadTarget = DateTime.Parse(_cfg.GetCVar(CCVars.RulesNextPopupTime));
if (nextReadTarget >= DateTime.UtcNow)
return;
var time = _cfg.GetCVar(CCVars.RulesWaitTime);
ShowRules(time);
}
private void OnShowRulesPopupMessage(ShowRulesPopupMessage message)
{
ShowRules(message.PopupTime);
@@ -100,8 +76,7 @@ public sealed class InfoUIController : UIController, IOnStateExited<GameplayStat
private void OnAcceptPressed()
{
_cfg.SetCVar(CCVars.RulesNextPopupTime, NextRulesReadTime.ToString(CultureInfo.InvariantCulture));
_cfg.SaveToFile();
_netManager.ClientSendMessage(new RulesAcceptedMessage());
_rulesPopup?.Orphan();
_rulesPopup = null;