Fix server update restarts when server paused. (#8509)

This commit is contained in:
Pieter-Jan Briers
2022-05-30 10:09:50 +02:00
committed by GitHub
parent e649dcea14
commit 5f9f319d5a
10 changed files with 135 additions and 73 deletions

View File

@@ -26,11 +26,6 @@ namespace Content.Server.GameTicking
switch (args.NewStatus)
{
case SessionStatus.Connecting:
// Cancel shutdown update timer in progress.
_updateShutdownCts?.Cancel();
break;
case SessionStatus.Connected:
{
AddPlayerToDb(args.Session.UserId.UserId);
@@ -95,7 +90,6 @@ namespace Content.Server.GameTicking
_chatManager.SendAdminAnnouncement(Loc.GetString("player-leave-message", ("name", args.Session.Name)));
ServerEmptyUpdateRestartCheck();
_prefsManager.OnClientDisconnected(session);
break;
}

View File

@@ -335,11 +335,9 @@ namespace Content.Server.GameTicking
if (DummyTicker)
return;
if (_updateOnRoundEnd)
{
_baseServer.Shutdown(Loc.GetString("game-ticker-shutdown-server-update"));
// Handle restart for server update
if (_serverUpdates.RoundEnded())
return;
}
_sawmill.Info("Restarting round!");

View File

@@ -1,58 +0,0 @@
using System.Linq;
using System.Threading;
using Robust.Shared.Enums;
using Timer = Robust.Shared.Timing.Timer;
namespace Content.Server.GameTicking
{
public sealed partial class GameTicker
{
private static readonly TimeSpan UpdateRestartDelay = TimeSpan.FromSeconds(20);
[ViewVariables]
private bool _updateOnRoundEnd;
private CancellationTokenSource? _updateShutdownCts;
private void InitializeUpdates()
{
_watchdogApi.UpdateReceived += WatchdogApiOnUpdateReceived;
}
private void WatchdogApiOnUpdateReceived()
{
_chatManager.DispatchServerAnnouncement(Loc.GetString("game-ticker-restart-round-server-update"));
_updateOnRoundEnd = true;
ServerEmptyUpdateRestartCheck();
}
/// <summary>
/// Checks whether there are still players on the server,
/// and if not starts a timer to automatically reboot the server if an update is available.
/// </summary>
private void ServerEmptyUpdateRestartCheck()
{
// Can't simple check the current connected player count since that doesn't update
// before PlayerStatusChanged gets fired.
// So in the disconnect handler we'd still see a single player otherwise.
var playersOnline = _playerManager.Sessions.Any(p => p.Status != SessionStatus.Disconnected);
if (playersOnline || !_updateOnRoundEnd)
{
// Still somebody online.
return;
}
if (_updateShutdownCts is {IsCancellationRequested: false})
{
// Do nothing because I guess we already have a timer running..?
return;
}
_updateShutdownCts = new CancellationTokenSource();
Timer.Spawn(UpdateRestartDelay, () =>
{
_baseServer.Shutdown(Loc.GetString("game-ticker-shutdown-server-update"));
}, _updateShutdownCts.Token);
}
}
}

View File

@@ -5,6 +5,7 @@ using Content.Server.Database;
using Content.Server.Ghost;
using Content.Server.Maps;
using Content.Server.Preferences.Managers;
using Content.Server.ServerUpdates;
using Content.Server.Station.Systems;
using Content.Shared.Chat;
using Content.Shared.Damage;
@@ -12,7 +13,6 @@ using Content.Shared.GameTicking;
using Content.Shared.Roles;
using Robust.Server;
using Robust.Server.Maps;
using Robust.Server.ServerStatus;
using Robust.Shared.Configuration;
using Robust.Shared.Console;
#if EXCEPTION_TOLERANCE
@@ -55,7 +55,6 @@ namespace Content.Server.GameTicking
DebugTools.Assert(_prototypeManager.Index<JobPrototype>(FallbackOverflowJob).Name == Loc.GetString(FallbackOverflowJobName),
"Overflow role does not have the correct name!");
InitializeGameRules();
InitializeUpdates();
_initialized = true;
}
@@ -101,7 +100,6 @@ namespace Content.Server.GameTicking
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly IServerPreferencesManager _prefsManager = default!;
[Dependency] private readonly IBaseServer _baseServer = default!;
[Dependency] private readonly IWatchdogApi _watchdogApi = default!;
[Dependency] private readonly IGameMapManager _gameMapManager = default!;
[Dependency] private readonly IServerDbManager _db = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
@@ -116,5 +114,6 @@ namespace Content.Server.GameTicking
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly GhostSystem _ghosts = default!;
[Dependency] private readonly RoleBanManager _roleBanManager = default!;
[Dependency] private readonly ServerUpdateManager _serverUpdates = default!;
}
}