Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ports infolinks #1579

Merged
merged 5 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading