-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ike709
committed
Dec 31, 2023
1 parent
186d10d
commit 8acaf2b
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Text.Json.Nodes; | ||
using OpenDreamShared; | ||
using Robust.Server.ServerStatus; | ||
using Robust.Shared.Configuration; | ||
|
||
namespace OpenDreamRuntime; | ||
|
||
/// <summary> | ||
/// Adds additional data like info links to the server info endpoint | ||
/// </summary> | ||
public sealed class ServerInfoManager | ||
{ | ||
private static readonly (CVarDef<string> 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!; | ||
[Dependency] private readonly ILocalizationManager _loc = 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, _loc.GetString(name), url, icon); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters