From 068b074de03393685cf123417f602eebeffa46f0 Mon Sep 17 00:00:00 2001 From: Brant Martin Date: Sat, 20 Apr 2019 09:02:21 -0400 Subject: [PATCH] Add player display to main UI window. Ref TorchAPI/Essentials#106 --- Torch.Server/TorchServer.cs | 6 ++++++ Torch.Server/Views/TorchUI.xaml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Torch.Server/TorchServer.cs b/Torch.Server/TorchServer.cs index c4070cd..06e1402 100644 --- a/Torch.Server/TorchServer.cs +++ b/Torch.Server/TorchServer.cs @@ -45,6 +45,8 @@ namespace Torch.Server private ServerState _state; private Stopwatch _uptime; private Timer _watchdog; + private int _players; + private MultiplayerManagerDedicated _multiplayerManagerDedicated; /// public TorchServer(TorchConfig config = null) @@ -92,6 +94,8 @@ namespace Torch.Server /// public string InstancePath => Config?.InstancePath; + public int OnlinePlayers { get => _players; private set => SetValue(ref _players, value); } + /// public override void Init() { @@ -186,6 +190,7 @@ namespace Torch.Server if (newState == TorchSessionState.Loaded) { + _multiplayerManagerDedicated = CurrentSession.Managers.GetManager(); CurrentSession.Managers.GetManager().RegisterCommandModule(typeof(WhitelistCommands)); ModCommunication.Register(); } @@ -209,6 +214,7 @@ namespace Torch.Server SimulationRatio = Math.Min(Sync.ServerSimulationRatio, 1); var elapsed = TimeSpan.FromSeconds(Math.Floor(_uptime.Elapsed.TotalSeconds)); ElapsedPlayTime = elapsed; + OnlinePlayers = _multiplayerManagerDedicated?.Players.Count ?? 0; if (_watchdog == null && Config.TickTimeout > 0) { diff --git a/Torch.Server/Views/TorchUI.xaml b/Torch.Server/Views/TorchUI.xaml index a198cae..5c7e34f 100644 --- a/Torch.Server/Views/TorchUI.xaml +++ b/Torch.Server/Views/TorchUI.xaml @@ -57,7 +57,7 @@