diff --git a/Content.Client/GameTicking/ClientGameTicker.cs b/Content.Client/GameTicking/ClientGameTicker.cs index fb9a14ae76..a6bdc2b225 100644 --- a/Content.Client/GameTicking/ClientGameTicker.cs +++ b/Content.Client/GameTicking/ClientGameTicker.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using Content.Client.Interfaces; using Content.Client.State; using Content.Client.UserInterface; -using Content.Shared; using Content.Shared.GameTicking; using Content.Shared.Network.NetMessages; using Robust.Client.Interfaces.Graphics; @@ -11,6 +10,7 @@ using Robust.Client.Interfaces.State; using Robust.Shared.Interfaces.Network; using Robust.Shared.IoC; using Robust.Shared.Network; +using Robust.Shared.Timing; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -28,7 +28,7 @@ namespace Content.Client.GameTicking [ViewVariables] public bool IsGameStarted { get; private set; } [ViewVariables] public bool DisallowedLateJoin { get; private set; } [ViewVariables] public string ServerInfoBlob { get; private set; } - [ViewVariables] public DateTime StartTime { get; private set; } + [ViewVariables] public TimeSpan StartTime { get; private set; } [ViewVariables] public bool Paused { get; private set; } [ViewVariables] public Dictionary Status { get; private set; } [ViewVariables] public IReadOnlyList JobsAvailable => _jobsAvailable; diff --git a/Content.Client/Interfaces/IClientGameTicker.cs b/Content.Client/Interfaces/IClientGameTicker.cs index ecb54004b0..981c9a3448 100644 --- a/Content.Client/Interfaces/IClientGameTicker.cs +++ b/Content.Client/Interfaces/IClientGameTicker.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Robust.Shared.Network; +using Robust.Shared.Timing; using static Content.Shared.GameTicking.SharedGameTicker; namespace Content.Client.Interfaces @@ -11,7 +12,7 @@ namespace Content.Client.Interfaces string ServerInfoBlob { get; } bool AreWeReady { get; } bool DisallowedLateJoin { get; } - DateTime StartTime { get; } + TimeSpan StartTime { get; } bool Paused { get; } Dictionary Status { get; } IReadOnlyList JobsAvailable { get; } diff --git a/Content.Client/State/LobbyState.cs b/Content.Client/State/LobbyState.cs index d2e4f90ec8..866c65c463 100644 --- a/Content.Client/State/LobbyState.cs +++ b/Content.Client/State/LobbyState.cs @@ -13,6 +13,7 @@ using Robust.Client.Player; using Robust.Client.UserInterface.Controls; using Robust.Shared.Input.Binding; using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Prototypes; @@ -35,6 +36,7 @@ namespace Content.Client.State [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!; [Dependency] private readonly IClientPreferencesManager _preferencesManager = default!; + [Dependency] private readonly IGameTiming _gameTiming = default!; [ViewVariables] private CharacterSetupGui _characterSetup; [ViewVariables] private LobbyGui _lobby; @@ -144,10 +146,11 @@ namespace Content.Client.State } else { - var difference = _clientGameTicker.StartTime - DateTime.UtcNow; - if (difference.Ticks < 0) + var difference = _clientGameTicker.StartTime - _gameTiming.CurTime; + var seconds = difference.TotalSeconds; + if (seconds < 0) { - if (difference.TotalSeconds < -5) + if (seconds < -5) { text = Loc.GetString("Right Now?"); } @@ -158,7 +161,7 @@ namespace Content.Client.State } else { - text = $"{(int) Math.Floor(difference.TotalMinutes)}:{difference.Seconds:D2}"; + text = $"{(int) Math.Floor(difference.TotalMinutes / 60)}:{difference.Seconds:D2}"; } } @@ -178,8 +181,10 @@ namespace Content.Client.State _clientGameTicker.Status.Remove(p.Key); } } + UpdatePlayerList(); } + private void LobbyReadyUpdated() => UpdatePlayerList(); private void LobbyStatusUpdated() @@ -224,8 +229,6 @@ namespace Content.Client.State foreach (var session in _playerManager.Sessions.OrderBy(s => s.Name)) { - - var readyState = ""; // Don't show ready state if we're ingame if (!_clientGameTicker.IsGameStarted) @@ -244,6 +247,7 @@ namespace Content.Client.State _ => "", }; } + _lobby.OnlinePlayerList.AddItem(session.Name, readyState); } } diff --git a/Content.Server/GameTicking/GameTicker.cs b/Content.Server/GameTicking/GameTicker.cs index 58434232e0..9d7800bb1f 100644 --- a/Content.Server/GameTicking/GameTicker.cs +++ b/Content.Server/GameTicking/GameTicker.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading; -using Content.Server.Administration; -using Content.Server.Commands.Observer; using Content.Server.GameObjects.Components.Access; using Content.Server.GameObjects.Components.GUI; using Content.Server.GameObjects.Components.Items.Storage; @@ -32,7 +30,6 @@ using Robust.Server.Interfaces.Maps; using Robust.Server.Interfaces.Player; using Robust.Server.Player; using Robust.Server.ServerStatus; -using Robust.Server.Interfaces.Console; using Robust.Shared.Enums; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.Configuration; @@ -71,7 +68,7 @@ namespace Content.Server.GameTicking public const float PresetFailedCooldownIncrease = 30f; private const string PlayerPrototypeName = "HumanMob_Content"; private const string ObserverPrototypeName = "MobObserver"; - private static TimeSpan _roundStartTimeSpan; + private TimeSpan _roundStartTimeSpan; [ViewVariables] private readonly List _gameRules = new(); [ViewVariables] private readonly List _manifest = new(); @@ -83,9 +80,9 @@ namespace Content.Server.GameTicking [ViewVariables] private Type _presetType; - [ViewVariables] private DateTime _pauseTime; + [ViewVariables] private TimeSpan _pauseTime; [ViewVariables] private bool _roundStartCountdownHasNotStartedYetDueToNoPlayers; - private DateTime _roundStartTimeUtc; + [ViewVariables] private TimeSpan _roundStartTime; [ViewVariables] private GameRunLevel _runLevel; [ViewVariables(VVAccess.ReadWrite)] private EntityCoordinates _spawnPoint; @@ -178,7 +175,7 @@ namespace Content.Server.GameTicking if (RunLevel != GameRunLevel.PreRoundLobby || Paused || - _roundStartTimeUtc > DateTime.UtcNow || + _roundStartTime > _gameTiming.CurTime || _roundStartCountdownHasNotStartedYetDueToNoPlayers) { return; @@ -217,7 +214,7 @@ namespace Content.Server.GameTicking if (PlayerManager.PlayerCount == 0) _roundStartCountdownHasNotStartedYetDueToNoPlayers = true; else - _roundStartTimeUtc = DateTime.UtcNow + LobbyDuration; + _roundStartTime = _gameTiming.CurTime + LobbyDuration; _sendStatusToAll(); @@ -532,10 +529,10 @@ namespace Content.Server.GameTicking return false; } - _roundStartTimeUtc += time; + _roundStartTime += time; var lobbyCountdownMessage = _netManager.CreateNetMessage(); - lobbyCountdownMessage.StartTime = _roundStartTimeUtc; + lobbyCountdownMessage.StartTime = _roundStartTime; lobbyCountdownMessage.Paused = Paused; _netManager.ServerSendToAll(lobbyCountdownMessage); @@ -555,15 +552,15 @@ namespace Content.Server.GameTicking if (pause) { - _pauseTime = DateTime.UtcNow; + _pauseTime = _gameTiming.CurTime; } else if (_pauseTime != default) { - _roundStartTimeUtc += DateTime.UtcNow - _pauseTime; + _roundStartTime += _gameTiming.CurTime - _pauseTime; } var lobbyCountdownMessage = _netManager.CreateNetMessage(); - lobbyCountdownMessage.StartTime = _roundStartTimeUtc; + lobbyCountdownMessage.StartTime = _roundStartTime; lobbyCountdownMessage.Paused = Paused; _netManager.ServerSendToAll(lobbyCountdownMessage); @@ -766,7 +763,7 @@ namespace Content.Server.GameTicking if (LobbyEnabled && _roundStartCountdownHasNotStartedYetDueToNoPlayers) { _roundStartCountdownHasNotStartedYetDueToNoPlayers = false; - _roundStartTimeUtc = DateTime.UtcNow + LobbyDuration; + _roundStartTime = _gameTiming.CurTime + LobbyDuration; } break; @@ -1020,7 +1017,7 @@ namespace Content.Server.GameTicking _playersInLobby.TryGetValue(session, out var status); var msg = _netManager.CreateNetMessage(); msg.IsRoundStarted = RunLevel != GameRunLevel.PreRoundLobby; - msg.StartTime = _roundStartTimeUtc; + msg.StartTime = _roundStartTime; msg.YouAreReady = status == PlayerStatus.Ready; msg.Paused = Paused; return msg; diff --git a/Content.Shared/GameTicking/SharedGameTicker.cs b/Content.Shared/GameTicking/SharedGameTicker.cs index 1251e6d3b4..ad8445656b 100644 --- a/Content.Shared/GameTicking/SharedGameTicker.cs +++ b/Content.Shared/GameTicking/SharedGameTicker.cs @@ -92,7 +92,7 @@ namespace Content.Shared.GameTicking public bool IsRoundStarted { get; set; } public bool YouAreReady { get; set; } // UTC. - public DateTime StartTime { get; set; } + public TimeSpan StartTime { get; set; } public bool Paused { get; set; } public override void ReadFromBuffer(NetIncomingMessage buffer) @@ -105,7 +105,7 @@ namespace Content.Shared.GameTicking } YouAreReady = buffer.ReadBoolean(); - StartTime = new DateTime(buffer.ReadInt64(), DateTimeKind.Utc); + StartTime = new TimeSpan(buffer.ReadInt64()); Paused = buffer.ReadBoolean(); } @@ -158,9 +158,9 @@ namespace Content.Shared.GameTicking #endregion /// - /// The total amount of seconds to go until the countdown finishes + /// The game time that the game will start at. /// - public DateTime StartTime { get; set; } + public TimeSpan StartTime { get; set; } /// /// Whether or not the countdown is paused @@ -169,7 +169,7 @@ namespace Content.Shared.GameTicking public override void ReadFromBuffer(NetIncomingMessage buffer) { - StartTime = new DateTime(buffer.ReadInt64(), DateTimeKind.Utc); + StartTime = new TimeSpan(buffer.ReadInt64()); Paused = buffer.ReadBoolean(); }