Whitelist player constraints (#13812)
This commit is contained in:
@@ -150,11 +150,21 @@ namespace Content.Server.Connection
|
||||
return (ConnectionDenyReason.Ban, firstBan.DisconnectMessage, bans);
|
||||
}
|
||||
|
||||
if (_cfg.GetCVar(CCVars.WhitelistEnabled)
|
||||
&& await _db.GetWhitelistStatusAsync(userId) == false
|
||||
if (_cfg.GetCVar(CCVars.WhitelistEnabled))
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -940,6 +940,18 @@ namespace Content.Shared.CCVar
|
||||
public static readonly CVarDef<string> WhitelistReason =
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user