]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix first round after a server restart being displayed as number 0 (#14194)
authorDrSmugleaf <DrSmugleaf@users.noreply.github.com>
Tue, 21 Feb 2023 00:16:25 +0000 (01:16 +0100)
committerGitHub <noreply@github.com>
Tue, 21 Feb 2023 00:16:25 +0000 (11:16 +1100)
Content.Server/GameTicking/GameTicker.GamePreset.cs
Content.Server/GameTicking/GameTicker.Player.cs
Content.Server/GameTicking/GameTicker.RoundFlow.cs

index 7956a3d7d8b165ec9056fb76d2fcb5ad8ee6fc3a..41622d6e822c48d1cd6cfff9945bb33250792c11 100644 (file)
@@ -1,5 +1,7 @@
 using System.Diagnostics.CodeAnalysis;
 using System.Linq;
+using System.Threading.Tasks;
+using Content.Server.GameTicking.Events;
 using Content.Server.GameTicking.Presets;
 using Content.Server.GameTicking.Rules;
 using Content.Server.Ghost.Components;
@@ -241,6 +243,27 @@ namespace Content.Server.GameTicking
                 mind.TransferTo(ghost);
             return true;
         }
+
+        private void IncrementRoundNumber()
+        {
+            var playerIds = _playerGameStatuses.Keys.Select(player => player.UserId).ToArray();
+            var serverName = _configurationManager.GetCVar(CCVars.AdminLogsServerName);
+
+            // TODO FIXME AAAAAAAAAAAAAAAAAAAH THIS IS BROKEN
+            // Task.Run as a terrible dirty workaround to avoid synchronization context deadlock from .Result here.
+            // This whole setup logic should be made asynchronous so we can properly wait on the DB AAAAAAAAAAAAAH
+            var task = Task.Run(async () =>
+            {
+                var server = await _db.AddOrGetServer(serverName);
+                return await _db.AddNewRound(server, playerIds);
+            });
+
+            _taskManager.BlockWaitOnTask(task);
+            RoundId = task.GetAwaiter().GetResult();
+
+            var startingEvent = new RoundStartingEvent(RoundId);
+            RaiseLocalEvent(startingEvent);
+        }
     }
 
     public sealed class GhostAttemptHandleEvent : HandledEntityEventArgs
index d785878d45b7638ad9e75ea4c2ca930d850f6aee..10edb7d096826e9435d8e1543bb1801d329cec75 100644 (file)
@@ -128,6 +128,7 @@ namespace Content.Server.GameTicking
             _chatManager.DispatchServerMessage(session, Loc.GetString("game-ticker-player-join-game-message"));
 
             _playerGameStatuses[session.UserId] = PlayerGameStatus.JoinedGame;
+            _db.AddRoundPlayers(RoundId, session.UserId);
 
             RaiseNetworkEvent(new TickerJoinGameEvent(), session.ConnectedClient);
         }
@@ -135,6 +136,7 @@ namespace Content.Server.GameTicking
         private void PlayerJoinLobby(IPlayerSession session)
         {
             _playerGameStatuses[session.UserId] = LobbyEnabled ? PlayerGameStatus.NotReadyToPlay : PlayerGameStatus.ReadyToPlay;
+            _db.AddRoundPlayers(RoundId, session.UserId);
 
             var client = session.ConnectedClient;
             RaiseNetworkEvent(new TickerJoinLobbyEvent(), client);
index ab88cccc63b38c9817e8bb5116cd122e110a0e19..5e45894c16d0aa0bb70d9680363a9a7b01a48b6e 100644 (file)
@@ -180,24 +180,6 @@ namespace Content.Server.GameTicking
 
             RoundLengthMetric.Set(0);
 
-            var playerIds = _playerGameStatuses.Keys.Select(player => player.UserId).ToArray();
-            var serverName = _configurationManager.GetCVar(CCVars.AdminLogsServerName);
-
-            // TODO FIXME AAAAAAAAAAAAAAAAAAAH THIS IS BROKEN
-            // Task.Run as a terrible dirty workaround to avoid synchronization context deadlock from .Result here.
-            // This whole setup logic should be made asynchronous so we can properly wait on the DB AAAAAAAAAAAAAH
-            var task = Task.Run(async () =>
-            {
-                var server = await _db.AddOrGetServer(serverName);
-                return await _db.AddNewRound(server, playerIds);
-            });
-
-            _taskManager.BlockWaitOnTask(task);
-            RoundId = task.GetAwaiter().GetResult();
-
-            var startingEvent = new RoundStartingEvent(RoundId);
-            RaiseLocalEvent(startingEvent);
-
             var readyPlayers = new List<IPlayerSession>();
             var readyPlayerProfiles = new Dictionary<NetUserId, HumanoidCharacterProfile>();
 
@@ -392,6 +374,7 @@ namespace Content.Server.GameTicking
             LobbySong = _robustRandom.Pick(_lobbyMusicCollection.PickFiles).ToString();
             RandomizeLobbyBackground();
             ResettingCleanup();
+            IncrementRoundNumber();
 
             if (!LobbyEnabled)
             {
@@ -405,6 +388,7 @@ namespace Content.Server.GameTicking
                     _roundStartTime = _gameTiming.CurTime + LobbyDuration;
 
                 SendStatusToAll();
+                UpdateInfoText();
 
                 ReqWindowAttentionAll();
             }