2024-01-22 23:14:13 +01:00
|
|
|
using Content.Shared.CCVar;
|
2022-08-29 19:38:56 -07:00
|
|
|
using Content.Shared.Info;
|
|
|
|
|
using Robust.Shared.Configuration;
|
|
|
|
|
using Robust.Shared.ContentPack;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Info;
|
|
|
|
|
|
2023-04-16 12:55:59 +12:00
|
|
|
public sealed class InfoSystem : EntitySystem
|
2022-08-29 19:38:56 -07:00
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IResourceManager _res = default!;
|
|
|
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeNetworkEvent<RequestRulesMessage>(OnRequestRules);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-13 22:48:39 +01:00
|
|
|
private void OnRequestRules(RequestRulesMessage message, EntitySessionEventArgs eventArgs)
|
2022-08-29 19:38:56 -07:00
|
|
|
{
|
2024-03-10 01:15:13 +01:00
|
|
|
Log.Debug("Client requested rules.");
|
2022-08-29 19:38:56 -07:00
|
|
|
var title = Loc.GetString(_cfg.GetCVar(CCVars.RulesHeader));
|
|
|
|
|
var path = _cfg.GetCVar(CCVars.RulesFile);
|
|
|
|
|
var rules = "Server could not read its rules.";
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-04-16 12:55:59 +12:00
|
|
|
rules = _res.ContentFileReadAllText($"/ServerInfo/{path}");
|
2022-08-29 19:38:56 -07:00
|
|
|
}
|
2023-01-19 03:56:45 +01:00
|
|
|
catch (Exception)
|
2022-08-29 19:38:56 -07:00
|
|
|
{
|
2024-03-10 01:15:13 +01:00
|
|
|
Log.Debug("Could not read server rules file.");
|
2022-08-29 19:38:56 -07:00
|
|
|
}
|
|
|
|
|
var response = new RulesMessage(title, rules);
|
2024-01-22 23:14:13 +01:00
|
|
|
RaiseNetworkEvent(response, eventArgs.SenderSession.Channel);
|
2022-08-29 19:38:56 -07:00
|
|
|
}
|
|
|
|
|
}
|