Fix ServerId CVar not getting replicated to the server (#5793)

* Fix ServerId CVar not getting replicated to the server

* Fix state check
This commit is contained in:
ShadowCommander
2021-12-15 22:54:04 -08:00
committed by GitHub
parent 09e0f79b89
commit 2e141347ed
2 changed files with 12 additions and 11 deletions

View File

@@ -1,29 +1,35 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using Content.Client.HUD; using Content.Client.Lobby;
using Content.Client.Viewport;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Robust.Client.State;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
using Robust.Shared.ContentPack; using Robust.Shared.ContentPack;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Network;
using Robust.Shared.Utility; using Robust.Shared.Utility;
namespace Content.Client.Info; namespace Content.Client.Info;
public sealed class RulesManager public sealed class RulesManager
{ {
[Dependency] private readonly IClientNetManager _clientNetManager = default!;
[Dependency] private readonly IResourceManager _resource = default!; [Dependency] private readonly IResourceManager _resource = default!;
[Dependency] private readonly IConfigurationManager _configManager = default!; [Dependency] private readonly IConfigurationManager _configManager = default!;
[Dependency] private readonly IStateManager _stateManager = default!;
public event Action? OpenRulesAndInfoWindow; 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; return;
_stateManager.OnStateChanged -= OnStateChanged;
var path = new ResourcePath($"/rules_last_seen_{_configManager.GetCVar(CCVars.ServerId)}"); var path = new ResourcePath($"/rules_last_seen_{_configManager.GetCVar(CCVars.ServerId)}");
var showRules = true; var showRules = true;
@@ -46,9 +52,4 @@ public sealed class RulesManager
sw.Write(DateTime.UtcNow.ToUniversalTime()); sw.Write(DateTime.UtcNow.ToUniversalTime());
} }
public void Initialize()
{
_clientNetManager.ClientConnectStateChanged += OnConnectStateChanged;
}
} }

View File

@@ -15,7 +15,7 @@ namespace Content.Shared.CCVar
/// Change this to have the changelog and rules "last seen" date stored separately. /// Change this to have the changelog and rules "last seen" date stored separately.
/// </summary> /// </summary>
public static readonly CVarDef<string> ServerId = public static readonly CVarDef<string> ServerId =
CVarDef.Create("server.id", "unknown_server_id"); CVarDef.Create("server.id", "unknown_server_id", CVar.REPLICATED | CVar.SERVER);
/* /*
* Ambience * Ambience