Provide a generic way to expose tags on the status endpoint (#2769)

* Provide a generic way to expose tags on the status endpoint for Launcher to presumably later consume.

* Switch to a JSON array for server tags
This commit is contained in:
20kdc
2022-07-21 15:28:56 +01:00
committed by GitHub
parent 86590ceb1f
commit 18a5335373
4 changed files with 35 additions and 1 deletions

View File

@@ -39,11 +39,23 @@ namespace Robust.Server.ServerStatus
var jObject = new JsonObject
{
// We need to send at LEAST name and player count to have the launcher work with us.
// Tags is optional technically but will be necessary practically for future organization.
// Content can override these if it wants (e.g. stealthmins).
["name"] = _serverNameCache,
["players"] = _playerManager.PlayerCount
};
var tagsCache = _serverTagsCache;
if (tagsCache != null)
{
var tags = new JsonArray();
foreach (var tag in tagsCache)
{
tags.Add(tag);
}
jObject["tags"] = tags;
}
OnStatusRequest?.Invoke(jObject);
await context.RespondJsonAsync(jObject);

View File

@@ -42,6 +42,7 @@ namespace Robust.Server.ServerStatus
private ISawmill _aczSawmill = default!;
private string? _serverNameCache;
private string[]? _serverTagsCache;
public async Task ProcessRequestAsync(HttpListenerContext context)
{
@@ -99,9 +100,20 @@ namespace Robust.Server.ServerStatus
_aczSawmill = Logger.GetSawmill($"{Sawmill}.acz");
RegisterCVars();
// Cache this in a field to avoid thread safety shenanigans.
// Cache these in fields to avoid thread safety shenanigans.
// Writes/reads of references are atomic in C# so no further synchronization necessary.
_cfg.OnValueChanged(CVars.GameHostName, n => _serverNameCache = n, true);
_cfg.OnValueChanged(CVars.HubTags, t =>
{
var tags = t.Split(",", StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < tags.Length; i++)
{
tags[i] = tags[i].Trim();
}
_serverTagsCache = tags;
},
true
);
if (!_cfg.GetCVar(CVars.StatusEnabled))
{

View File

@@ -45,7 +45,11 @@ loginlocal = true
[hub]
# Set to true to show this server on the public server list
# Before enabling this, read: https://docs.spacestation14.io/hosts/hub-rules
advertise = false
# Comma-separated list of tags, useful for categorizing your server.
# See https://docs.spacestation14.io/hosts/hub-rules for more details on this when it becomes relevant.
tags = ""
# URL of your server. Fill this in if you have a domain name,
# want to use HTTPS (with a reverse proxy), or other advanced scenarios.
# Must be in the form of an ss14:// or ss14s:// URI pointing to the status API.

View File

@@ -1095,6 +1095,12 @@ namespace Robust.Shared
public static readonly CVarDef<bool> HubAdvertise =
CVarDef.Create("hub.advertise", false, CVar.SERVERONLY);
/// <summary>
/// Comma-separated list of tags to advertise via the status server (and therefore, to the hub).
/// </summary>
public static readonly CVarDef<string> HubTags =
CVarDef.Create("hub.tags", "", CVar.ARCHIVE | CVar.SERVERONLY);
/// <summary>
/// URL of the master hub server to advertise to.
/// </summary>