From a4a81f10e3a434b8b479360f9591be1b2ca53939 Mon Sep 17 00:00:00 2001 From: moonheart08 Date: Thu, 30 Jun 2022 19:14:21 -0500 Subject: [PATCH 1/2] Implements panic bunkering. Helps with raid management, esp with unknown accounts. --- Content.Server.Database/Model.cs | 1 + Content.Server/Connection/ConnectionManager.cs | 13 +++++++++++++ Content.Shared/CCVar/CCVars.cs | 12 ++++++++++++ Resources/Locale/en-US/connection-messages.ftl | 1 + 4 files changed, 27 insertions(+) diff --git a/Content.Server.Database/Model.cs b/Content.Server.Database/Model.cs index 3d2445f71695..0dde35eb8110 100644 --- a/Content.Server.Database/Model.cs +++ b/Content.Server.Database/Model.cs @@ -454,6 +454,7 @@ public enum ConnectionDenyReason : byte Ban = 0, Whitelist = 1, Full = 2, + Panic = 3, } public class ServerBanHit diff --git a/Content.Server/Connection/ConnectionManager.cs b/Content.Server/Connection/ConnectionManager.cs index ca4b68d3e98c..8ae9f1f67378 100644 --- a/Content.Server/Connection/ConnectionManager.cs +++ b/Content.Server/Connection/ConnectionManager.cs @@ -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(out var ticker) && ticker.PlayersInGame.Contains(userId); if ((_plyMgr.PlayerCount >= _cfg.GetCVar(CCVars.SoftMaxPlayers) && adminData is null) && !wasInGame) { diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index f43c8f24cc6b..be24de927a3a 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -206,6 +206,18 @@ public static readonly CVarDef public static readonly CVarDef SoftMaxPlayers = CVarDef.Create("game.soft_max_players", 30, CVar.SERVERONLY | CVar.ARCHIVE); + /// + /// Whether or not panic bunker is currently enabled. + /// + public static readonly CVarDef PanicBunkerEnabled = + CVarDef.Create("game.panic_bunker.enabled", false, CVar.SERVERONLY); + + /// + /// Minimum age of the account (from server's PoV, so from first-seen date) in minutes. + /// + public static readonly CVarDef PanicBunkerMinAccountAge = + CVarDef.Create("game.panic_bunker.min_account_age", 1440, CVar.SERVERONLY); + #if EXCEPTION_TOLERANCE /// /// Amount of times round start must fail before the server is shut down. diff --git a/Resources/Locale/en-US/connection-messages.ftl b/Resources/Locale/en-US/connection-messages.ftl index a5cd4c695e6c..411b1d743edc 100644 --- a/Resources/Locale/en-US/connection-messages.ftl +++ b/Resources/Locale/en-US/connection-messages.ftl @@ -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. From 7abf02b1917495de464b9391f117caebc2639798 Mon Sep 17 00:00:00 2001 From: moonheart08 Date: Thu, 30 Jun 2022 19:38:57 -0500 Subject: [PATCH 2/2] adds an enable/disable command. --- .../Commands/PanicBunkerCommand.cs | 32 +++++++++++++++++++ Resources/Locale/en-US/shell.ftl | 1 + 2 files changed, 33 insertions(+) create mode 100644 Content.Server/Administration/Commands/PanicBunkerCommand.cs diff --git a/Content.Server/Administration/Commands/PanicBunkerCommand.cs b/Content.Server/Administration/Commands/PanicBunkerCommand.cs new file mode 100644 index 000000000000..9997880a3eca --- /dev/null +++ b/Content.Server/Administration/Commands/PanicBunkerCommand.cs @@ -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 "; + 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); + } +} diff --git a/Resources/Locale/en-US/shell.ftl b/Resources/Locale/en-US/shell.ftl index 18e7fc61ac57..1b8ba88814e1 100644 --- a/Resources/Locale/en-US/shell.ftl +++ b/Resources/Locale/en-US/shell.ftl @@ -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}