Fix first round after a server restart being displayed as number 0 (#14194)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user