diff --git a/Content.Server/Connection/ConnectionManager.cs b/Content.Server/Connection/ConnectionManager.cs index 4938dd9610..e1f370a972 100644 --- a/Content.Server/Connection/ConnectionManager.cs +++ b/Content.Server/Connection/ConnectionManager.cs @@ -121,7 +121,7 @@ namespace Content.Server.Connection var minOverallHours = _cfg.GetCVar(CCVars.PanicBunkerMinOverallHours); var overallTime = ( await _db.GetPlayTimes(e.UserId)).Find(p => p.Tracker == PlayTimeTrackingShared.TrackerOverall); var haveMinOverallTime = overallTime != null && overallTime.TimeSpent.TotalHours > minOverallHours; - + if (showReason && !haveMinOverallTime) { return (ConnectionDenyReason.Panic, @@ -150,11 +150,21 @@ namespace Content.Server.Connection return (ConnectionDenyReason.Ban, firstBan.DisconnectMessage, bans); } - if (_cfg.GetCVar(CCVars.WhitelistEnabled) - && await _db.GetWhitelistStatusAsync(userId) == false - && adminData is null) + if (_cfg.GetCVar(CCVars.WhitelistEnabled)) { - return (ConnectionDenyReason.Whitelist, Loc.GetString(_cfg.GetCVar(CCVars.WhitelistReason)), null); + var min = _cfg.GetCVar(CCVars.WhitelistMinPlayers); + var max = _cfg.GetCVar(CCVars.WhitelistMaxPlayers); + var playerCountValid = _plyMgr.PlayerCount > min && _plyMgr.PlayerCount < max; + + if (playerCountValid && await _db.GetWhitelistStatusAsync(userId) == false + && adminData is null) + { + var msg = Loc.GetString(_cfg.GetCVar(CCVars.WhitelistReason)); + // was the whitelist playercount changed? + if (min > 0 || max < int.MaxValue) + msg += "\n" + Loc.GetString("whitelist-playercount-invalid", ("min", min), ("max", max)); + return (ConnectionDenyReason.Whitelist, msg, null); + } } return null; diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index dd624cfb06..44cfb1d929 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -940,6 +940,18 @@ namespace Content.Shared.CCVar public static readonly CVarDef WhitelistReason = CVarDef.Create("whitelist.reason", "whitelist-not-whitelisted", CVar.SERVERONLY); + /// + /// If the playercount is below this number, the whitelist will not apply. + /// + public static readonly CVarDef WhitelistMinPlayers = + CVarDef.Create("whitelist.min_players", 0, CVar.SERVERONLY); + + /// + /// If the playercount is above this number, the whitelist will not apply. + /// + public static readonly CVarDef WhitelistMaxPlayers = + CVarDef.Create("whitelist.max_players", int.MaxValue, CVar.SERVERONLY); + /* * VOTE */ diff --git a/Resources/Locale/en-US/connection-messages.ftl b/Resources/Locale/en-US/connection-messages.ftl index b62dec9d68..5d2768fdc1 100644 --- a/Resources/Locale/en-US/connection-messages.ftl +++ b/Resources/Locale/en-US/connection-messages.ftl @@ -1,4 +1,13 @@ whitelist-not-whitelisted = You are not whitelisted. + +# proper handling for having a min/max or not +whitelist-playercount-invalid = {$min -> + [0] The whitelist for this server only applies below {$max} players. + *[other] The whitelist for this server only applies above {$min} {$max -> + [2147483647] -> players, so you may be able to join later. + *[other] -> players and below {$max} players, so you may be able to join later. + } +} whitelist-not-whitelisted-rp = You are not whitelisted. To become whitelisted, visit our Discord (which can be found at https://spacestation14.io) and check the #rp-whitelist channel. command-whitelistadd-description = Adds the player with the given username to the server whitelist.