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 ServerState _state;
|
||||||
private Stopwatch _uptime;
|
private Stopwatch _uptime;
|
||||||
private Timer _watchdog;
|
private Timer _watchdog;
|
||||||
|
private int _players;
|
||||||
|
private MultiplayerManagerDedicated _multiplayerManagerDedicated;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public TorchServer(TorchConfig config = null)
|
public TorchServer(TorchConfig config = null)
|
||||||
@@ -92,6 +94,8 @@ namespace Torch.Server
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string InstancePath => Config?.InstancePath;
|
public string InstancePath => Config?.InstancePath;
|
||||||
|
|
||||||
|
public int OnlinePlayers { get => _players; private set => SetValue(ref _players, value); }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Init()
|
public override void Init()
|
||||||
{
|
{
|
||||||
@@ -186,6 +190,7 @@ namespace Torch.Server
|
|||||||
|
|
||||||
if (newState == TorchSessionState.Loaded)
|
if (newState == TorchSessionState.Loaded)
|
||||||
{
|
{
|
||||||
|
_multiplayerManagerDedicated = CurrentSession.Managers.GetManager<MultiplayerManagerDedicated>();
|
||||||
CurrentSession.Managers.GetManager<CommandManager>().RegisterCommandModule(typeof(WhitelistCommands));
|
CurrentSession.Managers.GetManager<CommandManager>().RegisterCommandModule(typeof(WhitelistCommands));
|
||||||
ModCommunication.Register();
|
ModCommunication.Register();
|
||||||
}
|
}
|
||||||
@@ -209,6 +214,7 @@ namespace Torch.Server
|
|||||||
SimulationRatio = Math.Min(Sync.ServerSimulationRatio, 1);
|
SimulationRatio = Math.Min(Sync.ServerSimulationRatio, 1);
|
||||||
var elapsed = TimeSpan.FromSeconds(Math.Floor(_uptime.Elapsed.TotalSeconds));
|
var elapsed = TimeSpan.FromSeconds(Math.Floor(_uptime.Elapsed.TotalSeconds));
|
||||||
ElapsedPlayTime = elapsed;
|
ElapsedPlayTime = elapsed;
|
||||||
|
OnlinePlayers = _multiplayerManagerDedicated?.Players.Count ?? 0;
|
||||||
|
|
||||||
if (_watchdog == null && Config.TickTimeout > 0)
|
if (_watchdog == null && Config.TickTimeout > 0)
|
||||||
{
|
{
|
||||||
|
@@ -57,7 +57,7 @@
|
|||||||
</Label>
|
</Label>
|
||||||
<Label x:Name="LabelPlayers">
|
<Label x:Name="LabelPlayers">
|
||||||
<Label.Content>
|
<Label.Content>
|
||||||
<TextBlock ></TextBlock>
|
<TextBlock Text="{Binding OnlinePlayers, StringFormat=Players: {0}}"/>
|
||||||
</Label.Content>
|
</Label.Content>
|
||||||
</Label>
|
</Label>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
Reference in New Issue
Block a user