Add an exception to the soft max player cap for players who joined the game at some point during the current round. (#6245)

This commit is contained in:
Moony
2022-01-19 17:01:21 -06:00
committed by GitHub
parent 044635c10b
commit 1a62cefdf9
5 changed files with 14 additions and 5 deletions

View File

@@ -1,13 +1,13 @@
using System; using System;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.Administration.Managers;
using Content.Server.Database; using Content.Server.Database;
using Content.Server.GameTicking;
using Content.Server.Preferences.Managers; using Content.Server.Preferences.Managers;
using Content.Shared;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Robust.Server.Player; using Robust.Server.Player;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Network; using Robust.Shared.Network;
@@ -76,9 +76,10 @@ The ban reason is: ""{ban.Reason}""
} }
var adminData = await _dbManager.GetAdminDataForAsync(e.UserId); var adminData = await _dbManager.GetAdminDataForAsync(e.UserId);
if (_plyMgr.PlayerCount >= _cfg.GetCVar(CCVars.SoftMaxPlayers) && adminData is null) var wasInGame = EntitySystem.TryGet<GameTicker>(out var ticker) && ticker.PlayersInGame.Contains(userId);
if ((_plyMgr.PlayerCount >= _cfg.GetCVar(CCVars.SoftMaxPlayers) && adminData is null) && !wasInGame )
{ {
e.Deny("The server is full!"); e.Deny(Loc.GetString("soft-player-cap-full"));
return; return;
} }

View File

@@ -16,6 +16,8 @@ namespace Content.Server.GameTicking
[ViewVariables] [ViewVariables]
private readonly Dictionary<IPlayerSession, LobbyPlayerStatus> _playersInLobby = new(); private readonly Dictionary<IPlayerSession, LobbyPlayerStatus> _playersInLobby = new();
[ViewVariables] private readonly HashSet<NetUserId> _playersInGame = new();
[ViewVariables] [ViewVariables]
private TimeSpan _roundStartTime; private TimeSpan _roundStartTime;
@@ -29,6 +31,7 @@ namespace Content.Server.GameTicking
private bool _roundStartCountdownHasNotStartedYetDueToNoPlayers; private bool _roundStartCountdownHasNotStartedYetDueToNoPlayers;
public IReadOnlyDictionary<IPlayerSession, LobbyPlayerStatus> PlayersInLobby => _playersInLobby; public IReadOnlyDictionary<IPlayerSession, LobbyPlayerStatus> PlayersInLobby => _playersInLobby;
public IReadOnlySet<NetUserId> PlayersInGame => _playersInGame;
private void UpdateInfoText() private void UpdateInfoText()
{ {

View File

@@ -134,12 +134,15 @@ namespace Content.Server.GameTicking
if (_playersInLobby.ContainsKey(session)) if (_playersInLobby.ContainsKey(session))
_playersInLobby.Remove(session); _playersInLobby.Remove(session);
_playersInGame.Add(session.UserId);
RaiseNetworkEvent(new TickerJoinGameEvent(), session.ConnectedClient); RaiseNetworkEvent(new TickerJoinGameEvent(), session.ConnectedClient);
} }
private void PlayerJoinLobby(IPlayerSession session) private void PlayerJoinLobby(IPlayerSession session)
{ {
_playersInLobby[session] = LobbyPlayerStatus.NotReady; _playersInLobby[session] = LobbyPlayerStatus.NotReady;
_playersInGame.Remove(session.UserId);
var client = session.ConnectedClient; var client = session.ConnectedClient;
RaiseNetworkEvent(new TickerJoinLobbyEvent(), client); RaiseNetworkEvent(new TickerJoinLobbyEvent(), client);

View File

@@ -429,7 +429,7 @@ namespace Content.Server.GameTicking
} }
// This ordering mechanism isn't great (no ordering of minds) but functions // This ordering mechanism isn't great (no ordering of minds) but functions
var listOfPlayerInfoFinal = listOfPlayerInfo.OrderBy(pi => pi.PlayerOOCName).ToArray(); var listOfPlayerInfoFinal = listOfPlayerInfo.OrderBy(pi => pi.PlayerOOCName).ToArray();
_playersInGame.Clear();
RaiseNetworkEvent(new RoundEndMessageEvent(gamemodeTitle, roundEndText, roundDuration, listOfPlayerInfoFinal.Length, listOfPlayerInfoFinal)); RaiseNetworkEvent(new RoundEndMessageEvent(gamemodeTitle, roundEndText, roundDuration, listOfPlayerInfoFinal.Length, listOfPlayerInfoFinal));
} }

View File

@@ -8,3 +8,5 @@ command-whitelistremove-help = whitelistremove <username>
command-kicknonwhitelisted-description = Kicks all non-whitelisted players from the server. command-kicknonwhitelisted-description = Kicks all non-whitelisted players from the server.
command-kicknonwhitelisted-help = kicknonwhitelisted command-kicknonwhitelisted-help = kicknonwhitelisted
soft-player-cap-full = The server is full!