2021-06-20 17:38:05 +02:00
|
|
|
using System;
|
2022-01-10 01:41:46 +01:00
|
|
|
using System.Text.Json.Nodes;
|
2021-06-20 10:09:24 +02:00
|
|
|
using Robust.Server.ServerStatus;
|
|
|
|
|
using Robust.Shared.IoC;
|
2021-06-20 17:38:05 +02:00
|
|
|
using Robust.Shared.ViewVariables;
|
2021-06-20 10:09:24 +02:00
|
|
|
|
|
|
|
|
namespace Content.Server.GameTicking
|
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed partial class GameTicker
|
2021-06-20 10:09:24 +02:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used for thread safety, given <see cref="IStatusHost.OnStatusRequest"/> is called from another thread.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly object _statusShellLock = new();
|
|
|
|
|
|
2021-06-20 17:38:05 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Round start time in UTC, for status shell purposes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
private DateTime _roundStartDateTime;
|
|
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
private void InitializeStatusShell()
|
|
|
|
|
{
|
|
|
|
|
IoCManager.Resolve<IStatusHost>().OnStatusRequest += GetStatusResponse;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 01:41:46 +01:00
|
|
|
private void GetStatusResponse(JsonNode jObject)
|
2021-06-20 10:09:24 +02:00
|
|
|
{
|
|
|
|
|
// This method is raised from another thread, so this better be thread safe!
|
|
|
|
|
lock (_statusShellLock)
|
|
|
|
|
{
|
|
|
|
|
jObject["name"] = _baseServer.ServerName;
|
|
|
|
|
jObject["players"] = _playerManager.PlayerCount;
|
|
|
|
|
jObject["run_level"] = (int) _runLevel;
|
|
|
|
|
if (_runLevel >= GameRunLevel.InRound)
|
|
|
|
|
{
|
2021-06-20 17:38:05 +02:00
|
|
|
jObject["round_start_time"] = _roundStartDateTime.ToString("o");
|
2021-06-20 10:09:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|