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.
37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
using Content.Shared.CCVar;
|
|
using Content.Shared.Info;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.ContentPack;
|
|
using Robust.Shared.Log;
|
|
|
|
namespace Content.Server.Info;
|
|
|
|
public class InfoSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IResourceManager _res = default!;
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeNetworkEvent<RequestRulesMessage>(OnRequestRules);
|
|
}
|
|
|
|
protected void OnRequestRules(RequestRulesMessage message, EntitySessionEventArgs eventArgs)
|
|
{
|
|
Logger.DebugS("info", "Client requested rules.");
|
|
var title = Loc.GetString(_cfg.GetCVar(CCVars.RulesHeader));
|
|
var path = _cfg.GetCVar(CCVars.RulesFile);
|
|
var rules = "Server could not read its rules.";
|
|
try
|
|
{
|
|
rules = _res.ContentFileReadAllText($"/Server Info/{path}");
|
|
}
|
|
catch (System.Exception)
|
|
{
|
|
Logger.ErrorS("info", "Could not read server rules file.");
|
|
}
|
|
var response = new RulesMessage(title, rules);
|
|
RaiseNetworkEvent(response, eventArgs.SenderSession.ConnectedClient);
|
|
}
|
|
}
|