Send server rules over the network (#10847)

Add a new InfoSystem that sends SharedInfo from the server to client
when requested. Currently, only the rule header and rule text is sent.

Previously, the rule header and rule text was bundled in the client,
which means that the client would only display rules that it was built
with, even if the server has different rules.

This allows servers all running the same build to send different rules.
This could be useful, for example, for servers running the official
builds to send different rulesets without a client rebuild.
This commit is contained in:
Kevin Zheng
2022-08-29 19:38:56 -07:00
committed by GitHub
parent 5f5f795ae2
commit b84d19e702
7 changed files with 117 additions and 13 deletions

View File

@@ -0,0 +1,25 @@
using Content.Shared.Info;
using Robust.Shared.Log;
namespace Content.Client.Info;
public sealed class InfoSystem : EntitySystem
{
public RulesMessage Rules = new RulesMessage("Server Rules", "The server did not send any rules.");
[Dependency] private readonly RulesManager _rules = default!;
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<RulesMessage>(OnRulesReceived);
Logger.DebugS("info", "Requested server info.");
RaiseNetworkEvent(new RequestRulesMessage());
}
protected void OnRulesReceived(RulesMessage message, EntitySessionEventArgs eventArgs)
{
Logger.DebugS("info", "Received server rules.");
Rules = message;
_rules.UpdateRules();
}
}