Add player display to main UI window. Ref TorchAPI/Essentials#106
This commit is contained in:
@@ -45,6 +45,8 @@ namespace Torch.Server
|
||||
private ServerState _state;
|
||||
private Stopwatch _uptime;
|
||||
private Timer _watchdog;
|
||||
private int _players;
|
||||
private MultiplayerManagerDedicated _multiplayerManagerDedicated;
|
||||
|
||||
/// <inheritdoc />
|
||||
public TorchServer(TorchConfig config = null)
|
||||
@@ -92,6 +94,8 @@ namespace Torch.Server
|
||||
/// <inheritdoc />
|
||||
public string InstancePath => Config?.InstancePath;
|
||||
|
||||
public int OnlinePlayers { get => _players; private set => SetValue(ref _players, value); }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Init()
|
||||
{
|
||||
@@ -186,6 +190,7 @@ namespace Torch.Server
|
||||
|
||||
if (newState == TorchSessionState.Loaded)
|
||||
{
|
||||
_multiplayerManagerDedicated = CurrentSession.Managers.GetManager<MultiplayerManagerDedicated>();
|
||||
CurrentSession.Managers.GetManager<CommandManager>().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)
|
||||
{
|
||||
|
@@ -57,7 +57,7 @@
|
||||
</Label>
|
||||
<Label x:Name="LabelPlayers">
|
||||
<Label.Content>
|
||||
<TextBlock ></TextBlock>
|
||||
<TextBlock Text="{Binding OnlinePlayers, StringFormat=Players: {0}}"/>
|
||||
</Label.Content>
|
||||
</Label>
|
||||
</StackPanel>
|
||||
|
Reference in New Issue
Block a user