Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements panic bunkering. #9315

Merged
merged 2 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Content.Server.Database/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ public enum ConnectionDenyReason : byte
Ban = 0,
Whitelist = 1,
Full = 2,
Panic = 3,
}

public class ServerBanHit
Expand Down
32 changes: 32 additions & 0 deletions Content.Server/Administration/Commands/PanicBunkerCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Content.Shared.Administration;
using Content.Shared.CCVar;
using Robust.Shared.Configuration;
using Robust.Shared.Console;

namespace Content.Server.Administration.Commands;

[AdminCommand(AdminFlags.Server)]
public sealed class PanicBunkerCommand : IConsoleCommand
{
[Dependency] private readonly IConfigurationManager _cfg = default!;

public string Command => "panicbunker";
public string Description => "Enables or disables the panic bunker functionality.";
public string Help => "panicbunker <enabled>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}

if (!bool.TryParse(args[0], out var enabled))
{
shell.WriteError(Loc.GetString("shell-invalid-bool"));
return;
}

_cfg.SetCVar(CCVars.PanicBunkerEnabled, enabled);
}
}
13 changes: 13 additions & 0 deletions Content.Server/Connection/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ private async Task NetMgrOnConnecting(NetConnectingArgs e)
}

var adminData = await _dbManager.GetAdminDataForAsync(e.UserId);

if (_cfg.GetCVar(CCVars.PanicBunkerEnabled))
{
var record = await _dbManager.GetPlayerRecordByUserId(userId);
if ((record is null ||
record.FirstSeenTime.CompareTo(DateTimeOffset.Now - TimeSpan.FromMinutes(_cfg.GetCVar(CCVars.PanicBunkerMinAccountAge))) < 0)
&& !await _db.GetWhitelistStatusAsync(userId)
)
{
return (ConnectionDenyReason.Panic, Loc.GetString("panic-bunker-account-denied"), null);
}
}

var wasInGame = EntitySystem.TryGet<GameTicker>(out var ticker) && ticker.PlayersInGame.Contains(userId);
if ((_plyMgr.PlayerCount >= _cfg.GetCVar(CCVars.SoftMaxPlayers) && adminData is null) && !wasInGame)
{
Expand Down
12 changes: 12 additions & 0 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ public static readonly CVarDef<bool>
public static readonly CVarDef<int> SoftMaxPlayers =
CVarDef.Create("game.soft_max_players", 30, CVar.SERVERONLY | CVar.ARCHIVE);

/// <summary>
/// Whether or not panic bunker is currently enabled.
/// </summary>
public static readonly CVarDef<bool> PanicBunkerEnabled =
CVarDef.Create("game.panic_bunker.enabled", false, CVar.SERVERONLY);

/// <summary>
/// Minimum age of the account (from server's PoV, so from first-seen date) in minutes.
/// </summary>
public static readonly CVarDef<int> PanicBunkerMinAccountAge =
CVarDef.Create("game.panic_bunker.min_account_age", 1440, CVar.SERVERONLY);

#if EXCEPTION_TOLERANCE
/// <summary>
/// Amount of times round start must fail before the server is shut down.
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/connection-messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ command-kicknonwhitelisted-description = Kicks all non-whitelisted players from
command-kicknonwhitelisted-help = kicknonwhitelisted

soft-player-cap-full = The server is full!
panic-bunker-account-denied = This server is in Panic mode and you were rejected. Contact the server administrator for help.
1 change: 1 addition & 0 deletions Resources/Locale/en-US/shell.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ shell-invalid-entity-id = Invalid entity ID.
shell-invalid-grid-id = Invalid grid ID.
shell-invalid-map-id = Invalid map ID.
shell-invalid-entity-uid = {$uid} is not a valid entity uid
shell-invalid-bool = Invalid boolean.
shell-entity-uid-must-be-number = EntityUid must be a number.
shell-could-not-find-entity = Could not find entity {$entity}
shell-could-not-find-entity-with-uid = Could not find entity with uid {$uid}
Expand Down