Whitelist player constraints (#13812)

This commit is contained in:
Kara
2023-01-30 23:57:45 -06:00
committed by GitHub
parent 81990a4897
commit 917aa80b4b
3 changed files with 36 additions and 5 deletions

View File

@@ -150,11 +150,21 @@ namespace Content.Server.Connection
return (ConnectionDenyReason.Ban, firstBan.DisconnectMessage, bans); return (ConnectionDenyReason.Ban, firstBan.DisconnectMessage, bans);
} }
if (_cfg.GetCVar(CCVars.WhitelistEnabled) if (_cfg.GetCVar(CCVars.WhitelistEnabled))
&& await _db.GetWhitelistStatusAsync(userId) == false {
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) && adminData is null)
{ {
return (ConnectionDenyReason.Whitelist, Loc.GetString(_cfg.GetCVar(CCVars.WhitelistReason)), 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; return null;

View File

@@ -940,6 +940,18 @@ namespace Content.Shared.CCVar
public static readonly CVarDef<string> WhitelistReason = public static readonly CVarDef<string> WhitelistReason =
CVarDef.Create("whitelist.reason", "whitelist-not-whitelisted", CVar.SERVERONLY); CVarDef.Create("whitelist.reason", "whitelist-not-whitelisted", CVar.SERVERONLY);
/// <summary>
/// If the playercount is below this number, the whitelist will not apply.
/// </summary>
public static readonly CVarDef<int> WhitelistMinPlayers =
CVarDef.Create("whitelist.min_players", 0, CVar.SERVERONLY);
/// <summary>
/// If the playercount is above this number, the whitelist will not apply.
/// </summary>
public static readonly CVarDef<int> WhitelistMaxPlayers =
CVarDef.Create("whitelist.max_players", int.MaxValue, CVar.SERVERONLY);
/* /*
* VOTE * VOTE
*/ */

View File

@@ -1,4 +1,13 @@
whitelist-not-whitelisted = You are not whitelisted. 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. 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. command-whitelistadd-description = Adds the player with the given username to the server whitelist.