Skip to content

Commit

Permalink
Ports infolinks (OpenDreamProject#1579)
Browse files Browse the repository at this point in the history
* Ports infolinks

* Update OpenDreamRuntime/ServerInfoManager.cs

* Update OpenDreamRuntime/ServerInfoManager.cs

* breh

---------

Co-authored-by: ike709 <[email protected]>
  • Loading branch information
ike709 and ike709 authored Dec 31, 2023
1 parent 186d10d commit a9bf040
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
3 changes: 3 additions & 0 deletions OpenDreamRuntime/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -51,6 +52,8 @@ public override void Init() {
}

_prototypeManager.LoadDirectory(new ResPath("/Resources/Prototypes"));

_serverInfoManager.Initialize();
}

public override void PostInit() {
Expand Down
1 change: 1 addition & 0 deletions OpenDreamRuntime/ServerContentIoC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static void Register(bool unitTests = false) {
IoCManager.Register<DreamResourceManager>();
IoCManager.Register<WalkManager, WalkManager>();
IoCManager.Register<IDreamDebugManager, DreamDebugManager>();
IoCManager.Register<ServerInfoManager>();

#if DEBUG
IoCManager.Register<LocalHostConGroup>();
Expand Down
38 changes: 38 additions & 0 deletions OpenDreamRuntime/ServerInfoManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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!;

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);
}
}
}
34 changes: 34 additions & 0 deletions OpenDreamShared/OpenDreamCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,39 @@ public abstract class OpenDreamCVars {

public static readonly CVarDef<ushort> TopicPort =
CVarDef.Create<ushort>("opendream.topic_port", 25567, CVar.SERVERONLY);

/*
* INFOLINKS
*/

/// <summary>
/// Link to Discord server to show in the launcher.
/// </summary>
public static readonly CVarDef<string> InfoLinksDiscord =
CVarDef.Create("infolinks.discord", "", CVar.SERVER | CVar.REPLICATED);

/// <summary>
/// Link to forum to show in the launcher.
/// </summary>
public static readonly CVarDef<string> InfoLinksForum =
CVarDef.Create("infolinks.forum", "", CVar.SERVER | CVar.REPLICATED);

/// <summary>
/// Link to GitHub page to show in the launcher.
/// </summary>
public static readonly CVarDef<string> InfoLinksGithub =
CVarDef.Create("infolinks.github", "", CVar.SERVER | CVar.REPLICATED);

/// <summary>
/// Link to website to show in the launcher.
/// </summary>
public static readonly CVarDef<string> InfoLinksWebsite =
CVarDef.Create("infolinks.website", "", CVar.SERVER | CVar.REPLICATED);

/// <summary>
/// Link to wiki to show in the launcher.
/// </summary>
public static readonly CVarDef<string> InfoLinksWiki =
CVarDef.Create("infolinks.wiki", "", CVar.SERVER | CVar.REPLICATED);
}
}

0 comments on commit a9bf040

Please sign in to comment.