diff --git a/Content.Client/Credits/CreditsWindow.xaml.cs b/Content.Client/Credits/CreditsWindow.xaml.cs index 224a1007e1..a2145b479d 100644 --- a/Content.Client/Credits/CreditsWindow.xaml.cs +++ b/Content.Client/Credits/CreditsWindow.xaml.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using Content.Client.Links; using Content.Client.Stylesheets; using Content.Shared.CCVar; using Robust.Client.AutoGenerated; @@ -68,7 +67,8 @@ namespace Content.Client.Credits // Do not show "become a patron" button on Steam builds // since Patreon violates Valve's rules about alternative storefronts. - if (!_cfg.GetCVar(CCVars.BrandingSteam)) + var linkPatreon = _cfg.GetCVar(CCVars.InfoLinksPatreon); + if (!_cfg.GetCVar(CCVars.BrandingSteam) && linkPatreon != "") { Button patronButton; patronsContainer.AddChild(patronButton = new Button @@ -78,7 +78,7 @@ namespace Content.Client.Credits }); patronButton.OnPressed += - _ => IoCManager.Resolve().OpenUri(UILinks.Patreon); + _ => IoCManager.Resolve().OpenUri(linkPatreon); } var first = true; @@ -158,8 +158,13 @@ namespace Content.Client.Credits AddSection(Loc.GetString("credits-window-original-remake-team-section-title"), "OriginalRemake.txt"); AddSection(Loc.GetString("credits-window-special-thanks-section-title"), "SpecialThanks.txt", true); + var linkGithub = _cfg.GetCVar(CCVars.InfoLinksGithub); + contributeButton.OnPressed += _ => - IoCManager.Resolve().OpenUri(UILinks.GitHub); + IoCManager.Resolve().OpenUri(linkGithub); + + if (linkGithub == "") + contributeButton.Visible = false; } private sealed class PatronEntry diff --git a/Content.Client/Info/DevInfoBanner.cs b/Content.Client/Info/DevInfoBanner.cs index 9898b60f83..0599b355f5 100644 --- a/Content.Client/Info/DevInfoBanner.cs +++ b/Content.Client/Info/DevInfoBanner.cs @@ -1,8 +1,9 @@ using Content.Client.Changelog; using Content.Client.Credits; -using Content.Client.Links; +using Content.Shared.CCVar; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; +using Robust.Shared.Configuration; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Utility; @@ -19,13 +20,18 @@ namespace Content.Client.Info AddChild(buttons); var uriOpener = IoCManager.Resolve(); + var cfg = IoCManager.Resolve(); - var reportButton = new Button {Text = Loc.GetString("server-info-report-button")}; - reportButton.OnPressed += args => uriOpener.OpenUri(UILinks.BugReport); + var bugReport = cfg.GetCVar(CCVars.InfoLinksBugReport); + if (bugReport != "") + { + var reportButton = new Button {Text = Loc.GetString("server-info-report-button")}; + reportButton.OnPressed += args => uriOpener.OpenUri(bugReport); + buttons.AddChild(reportButton); + } var creditsButton = new Button {Text = Loc.GetString("server-info-credits-button")}; creditsButton.OnPressed += args => new CreditsWindow().Open(); - buttons.AddChild(reportButton); buttons.AddChild(creditsButton); } } diff --git a/Content.Client/Info/LinkBanner.cs b/Content.Client/Info/LinkBanner.cs index 6e87dc5c40..569cbc9095 100644 --- a/Content.Client/Info/LinkBanner.cs +++ b/Content.Client/Info/LinkBanner.cs @@ -1,9 +1,10 @@ using Content.Client.Changelog; using Content.Client.Credits; -using Content.Client.Links; using Content.Client.UserInterface.Systems.EscapeMenu; +using Content.Shared.CCVar; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; +using Robust.Shared.Configuration; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Utility; @@ -21,25 +22,31 @@ namespace Content.Client.Info AddChild(buttons); var uriOpener = IoCManager.Resolve(); + var cfg = IoCManager.Resolve(); var rulesButton = new Button() {Text = Loc.GetString("server-info-rules-button")}; rulesButton.OnPressed += args => new RulesAndInfoWindow().Open(); + buttons.AddChild(rulesButton); - var discordButton = new Button {Text = Loc.GetString("server-info-discord-button")}; - discordButton.OnPressed += args => uriOpener.OpenUri(UILinks.Discord); + AddInfoButton("server-info-discord-button", CCVars.InfoLinksDiscord); + AddInfoButton("server-info-website-button", CCVars.InfoLinksWebsite); + AddInfoButton("server-info-wiki-button", CCVars.InfoLinksWiki); + AddInfoButton("server-info-forum-button", CCVars.InfoLinksForum); - var websiteButton = new Button {Text = Loc.GetString("server-info-website-button")}; - websiteButton.OnPressed += args => uriOpener.OpenUri(UILinks.Website); - - var wikiButton = new Button {Text = Loc.GetString("server-info-wiki-button")}; - wikiButton.OnPressed += args => uriOpener.OpenUri(UILinks.Wiki); var changelogButton = new ChangelogButton(); changelogButton.OnPressed += args => UserInterfaceManager.GetUIController().ToggleWindow(); buttons.AddChild(changelogButton); - buttons.AddChild(rulesButton); - buttons.AddChild(discordButton); - buttons.AddChild(websiteButton); - buttons.AddChild(wikiButton); + + void AddInfoButton(string loc, CVarDef cVar) + { + var link = cfg.GetCVar(cVar); + if (link == "") + return; + + var button = new Button { Text = Loc.GetString(loc) }; + button.OnPressed += _ => uriOpener.OpenUri(link); + buttons.AddChild(button); + } } } } diff --git a/Content.Client/Info/ServerInfo.cs b/Content.Client/Info/ServerInfo.cs index f072c50397..23be750626 100644 --- a/Content.Client/Info/ServerInfo.cs +++ b/Content.Client/Info/ServerInfo.cs @@ -1,6 +1,5 @@ using Content.Client.Changelog; using Content.Client.Credits; -using Content.Client.Links; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.IoC; diff --git a/Content.Client/Links/UILinks.cs b/Content.Client/Links/UILinks.cs deleted file mode 100644 index 7481e80cd0..0000000000 --- a/Content.Client/Links/UILinks.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Content.Client.Links -{ - public static class UILinks - { - public const string GitHub = "https://github.com/space-wizards/space-station-14/"; - public const string Patreon = "https://www.patreon.com/spacestation14"; - - public const string Discord = "https://discord.ss14.io/"; - public const string BugReport = "https://github.com/space-wizards/space-station-14/issues/new/choose"; - public const string Website = "https://spacestation14.io"; - public const string Wiki = "https://wiki.spacestation14.io"; - } -} diff --git a/Content.Client/UserInterface/Systems/EscapeMenu/EscapeUIController.cs b/Content.Client/UserInterface/Systems/EscapeMenu/EscapeUIController.cs index 4af5c04216..68cc5392e5 100644 --- a/Content.Client/UserInterface/Systems/EscapeMenu/EscapeUIController.cs +++ b/Content.Client/UserInterface/Systems/EscapeMenu/EscapeUIController.cs @@ -1,13 +1,14 @@ using Content.Client.Gameplay; using Content.Client.Info; -using Content.Client.Links; using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Systems.Info; +using Content.Shared.CCVar; using JetBrains.Annotations; using Robust.Client.Console; using Robust.Client.Input; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controllers; +using Robust.Shared.Configuration; using Robust.Shared.Input; using Robust.Shared.Input.Binding; using Robust.Shared.Utility; @@ -20,6 +21,7 @@ public sealed class EscapeUIController : UIController, IOnStateEntered { - _uri.OpenUri(UILinks.Wiki); + _uri.OpenUri(_cfg.GetCVar(CCVars.InfoLinksWiki)); }; + // Hide wiki button if we don't have a link for it. + _escapeWindow.WikiButton.Visible = _cfg.GetCVar(CCVars.InfoLinksWiki) != ""; + CommandBinds.Builder .Bind(EngineKeyFunctions.EscapeMenu, InputCmdHandler.FromDelegate(_ => ToggleWindow())) diff --git a/Content.Server/Entry/EntryPoint.cs b/Content.Server/Entry/EntryPoint.cs index ae17684f99..92e7b8d832 100644 --- a/Content.Server/Entry/EntryPoint.cs +++ b/Content.Server/Entry/EntryPoint.cs @@ -16,6 +16,7 @@ using Content.Server.Maps; using Content.Server.NodeContainer.NodeGroups; using Content.Server.Players.PlayTimeTracking; using Content.Server.Preferences.Managers; +using Content.Server.ServerInfo; using Content.Server.ServerUpdates; using Content.Server.Voting.Managers; using Content.Shared.Administration; @@ -96,6 +97,7 @@ namespace Content.Server.Entry IoCManager.Resolve().Initialize(); IoCManager.Resolve().Initialize(); IoCManager.Resolve().Initialize(); + IoCManager.Resolve().Initialize(); _voteManager.Initialize(); _updateManager.Initialize(); diff --git a/Content.Server/IoC/ServerContentIoC.cs b/Content.Server/IoC/ServerContentIoC.cs index 8e48a9562a..3ab0052b89 100644 --- a/Content.Server/IoC/ServerContentIoC.cs +++ b/Content.Server/IoC/ServerContentIoC.cs @@ -16,6 +16,7 @@ using Content.Server.Objectives; using Content.Server.Objectives.Interfaces; using Content.Server.Players.PlayTimeTracking; using Content.Server.Preferences.Managers; +using Content.Server.ServerInfo; using Content.Server.ServerUpdates; using Content.Server.Voting.Managers; using Content.Shared.Administration; @@ -55,6 +56,7 @@ namespace Content.Server.IoC IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); + IoCManager.Register(); } } } diff --git a/Content.Server/ServerInfo/ServerInfoManager.cs b/Content.Server/ServerInfo/ServerInfoManager.cs new file mode 100644 index 0000000000..d2e35e9663 --- /dev/null +++ b/Content.Server/ServerInfo/ServerInfoManager.cs @@ -0,0 +1,44 @@ +using System.Text.Json.Nodes; +using Content.Shared.CCVar; +using Robust.Server.ServerStatus; +using Robust.Shared.Configuration; + +namespace Content.Server.ServerInfo; + +/// +/// 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 + (CCVars.InfoLinksDiscord, "discord", "info-link-discord"), + (CCVars.InfoLinksForum, "forum", "info-link-forum"), + (CCVars.InfoLinksGithub, "github", "info-link-github"), + (CCVars.InfoLinksWebsite, "web", "info-link-website"), + (CCVars.InfoLinksWiki, "wiki", "info-link-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); + } + } +} diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 4f68a22be8..c721685e11 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -1348,5 +1348,51 @@ namespace Content.Shared.CCVar /// public static readonly CVarDef PlayTimeSaveInterval = CVarDef.Create("playtime.save_interval", 900f, 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 website 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); + + /// + /// Link to Patreon. Not shown in the launcher currently. + /// + public static readonly CVarDef InfoLinksPatreon = + CVarDef.Create("infolinks.patreon", "", CVar.SERVER | CVar.REPLICATED); + + /// + /// Link to the bug report form. + /// + public static readonly CVarDef InfoLinksBugReport = + CVarDef.Create("infolinks.bug_report", "", CVar.SERVER | CVar.REPLICATED); } } diff --git a/Resources/Locale/en-US/info/server-info.ftl b/Resources/Locale/en-US/info/server-info.ftl index e406a704b5..0686b78c3b 100644 --- a/Resources/Locale/en-US/info/server-info.ftl +++ b/Resources/Locale/en-US/info/server-info.ftl @@ -2,5 +2,6 @@ server-info-rules-button = Rules server-info-discord-button = Discord server-info-website-button = Website server-info-wiki-button = Wiki +server-info-forum-button = Forum server-info-report-button = Report Bugs server-info-credits-button = Credits diff --git a/Resources/Locale/en-US/server-info/info-links.ftl b/Resources/Locale/en-US/server-info/info-links.ftl new file mode 100644 index 0000000000..0f8f9eb7d9 --- /dev/null +++ b/Resources/Locale/en-US/server-info/info-links.ftl @@ -0,0 +1,7 @@ +### Strings for link buttons shown in the launcher's server description. + +info-link-discord = Discord +info-link-forum = Forum +info-link-github = GitHub +info-link-website = Website +info-link-wiki = Wiki