diff --git a/OpenDreamRuntime/EntryPoint.cs b/OpenDreamRuntime/EntryPoint.cs index 6a54f0db18..be24d5dfd6 100644 --- a/OpenDreamRuntime/EntryPoint.cs +++ b/OpenDreamRuntime/EntryPoint.cs @@ -21,6 +21,7 @@ public sealed class EntryPoint : GameServer { [Dependency] private readonly IConfigurationManager _configManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IDreamDebugManager _debugManager = default!; + [Dependency] private readonly ServerInfoManager _serverInfoManager = default!; private DreamCommandSystem? _commandSystem; @@ -51,6 +52,8 @@ public override void Init() { } _prototypeManager.LoadDirectory(new ResPath("/Resources/Prototypes")); + + _serverInfoManager.Initialize(); } public override void PostInit() { diff --git a/OpenDreamRuntime/ServerContentIoC.cs b/OpenDreamRuntime/ServerContentIoC.cs index 20a2ed95bb..77ec1706bf 100644 --- a/OpenDreamRuntime/ServerContentIoC.cs +++ b/OpenDreamRuntime/ServerContentIoC.cs @@ -13,6 +13,7 @@ public static void Register(bool unitTests = false) { IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); + IoCManager.Register(); #if DEBUG IoCManager.Register(); diff --git a/OpenDreamRuntime/ServerInfoManager.cs b/OpenDreamRuntime/ServerInfoManager.cs new file mode 100644 index 0000000000..aceb94430b --- /dev/null +++ b/OpenDreamRuntime/ServerInfoManager.cs @@ -0,0 +1,38 @@ +using System.Text.Json.Nodes; +using OpenDreamShared; +using Robust.Server.ServerStatus; +using Robust.Shared.Configuration; + +namespace OpenDreamRuntime; + +/// +/// Adds additional data like info links to the server info endpoint +/// +public sealed class ServerInfoManager { + private static readonly (CVarDef cVar, string icon, string name)[] Vars = { + // @formatter:off + (OpenDreamCVars.InfoLinksDiscord, "discord", "Discord"), + (OpenDreamCVars.InfoLinksForum, "forum", "Forum"), + (OpenDreamCVars.InfoLinksGithub, "github", "GitHub"), + (OpenDreamCVars.InfoLinksWebsite, "web", "Website"), + (OpenDreamCVars.InfoLinksWiki, "wiki", "Wiki") + // @formatter:on + }; + + [Dependency] private readonly IStatusHost _statusHost = default!; + [Dependency] private readonly IConfigurationManager _cfg = default!; + + public void Initialize() { + _statusHost.OnInfoRequest += OnInfoRequest; + } + + private void OnInfoRequest(JsonNode json) { + foreach (var (cVar, icon, name) in Vars) { + var url = _cfg.GetCVar(cVar); + if (string.IsNullOrEmpty(url)) + continue; + + StatusHostHelpers.AddLink(json, name, url, icon); + } + } +} diff --git a/OpenDreamShared/OpenDreamCVars.cs b/OpenDreamShared/OpenDreamCVars.cs index 3af2886caf..cc87102218 100644 --- a/OpenDreamShared/OpenDreamCVars.cs +++ b/OpenDreamShared/OpenDreamCVars.cs @@ -24,5 +24,39 @@ public abstract class OpenDreamCVars { public static readonly CVarDef TopicPort = CVarDef.Create("opendream.topic_port", 25567, CVar.SERVERONLY); + + /* + * INFOLINKS + */ + + /// + /// Link to Discord server to show in the launcher. + /// + public static readonly CVarDef InfoLinksDiscord = + CVarDef.Create("infolinks.discord", "", CVar.SERVER | CVar.REPLICATED); + + /// + /// Link to forum to show in the launcher. + /// + public static readonly CVarDef InfoLinksForum = + CVarDef.Create("infolinks.forum", "", CVar.SERVER | CVar.REPLICATED); + + /// + /// Link to GitHub page to show in the launcher. + /// + public static readonly CVarDef InfoLinksGithub = + CVarDef.Create("infolinks.github", "", CVar.SERVER | CVar.REPLICATED); + + /// + /// Link to website to show in the launcher. + /// + public static readonly CVarDef InfoLinksWebsite = + CVarDef.Create("infolinks.website", "", CVar.SERVER | CVar.REPLICATED); + + /// + /// Link to wiki to show in the launcher. + /// + public static readonly CVarDef InfoLinksWiki = + CVarDef.Create("infolinks.wiki", "", CVar.SERVER | CVar.REPLICATED); } }