diff --git a/Content.Client/Info/RulesManager.cs b/Content.Client/Info/RulesManager.cs index a1eece5434..3bccbddc77 100644 --- a/Content.Client/Info/RulesManager.cs +++ b/Content.Client/Info/RulesManager.cs @@ -1,29 +1,35 @@ using System; using System.Globalization; using System.IO; -using Content.Client.HUD; +using Content.Client.Lobby; +using Content.Client.Viewport; using Content.Shared.CCVar; +using Robust.Client.State; using Robust.Shared.Configuration; using Robust.Shared.ContentPack; using Robust.Shared.IoC; -using Robust.Shared.Network; using Robust.Shared.Utility; namespace Content.Client.Info; public sealed class RulesManager { - [Dependency] private readonly IClientNetManager _clientNetManager = default!; [Dependency] private readonly IResourceManager _resource = default!; [Dependency] private readonly IConfigurationManager _configManager = default!; + [Dependency] private readonly IStateManager _stateManager = default!; public event Action? OpenRulesAndInfoWindow; - private void OnConnectStateChanged(ClientConnectionState state) + public void Initialize() { + _stateManager.OnStateChanged += OnStateChanged; + } - if (state != ClientConnectionState.Connected) + private void OnStateChanged(StateChangedEventArgs args) + { + if (args.NewState is not (GameScreen or LobbyState)) return; + _stateManager.OnStateChanged -= OnStateChanged; var path = new ResourcePath($"/rules_last_seen_{_configManager.GetCVar(CCVars.ServerId)}"); var showRules = true; @@ -46,9 +52,4 @@ public sealed class RulesManager sw.Write(DateTime.UtcNow.ToUniversalTime()); } - - public void Initialize() - { - _clientNetManager.ClientConnectStateChanged += OnConnectStateChanged; - } } diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 62067fc697..c5095bf568 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -15,7 +15,7 @@ namespace Content.Shared.CCVar /// Change this to have the changelog and rules "last seen" date stored separately. /// public static readonly CVarDef ServerId = - CVarDef.Create("server.id", "unknown_server_id"); + CVarDef.Create("server.id", "unknown_server_id", CVar.REPLICATED | CVar.SERVER); /* * Ambience