Implements panic bunkering. (#9315)

* Implements panic bunkering.
Helps with raid management, esp with unknown accounts.

* adds an enable/disable command.
This commit is contained in:
Moony
2022-07-01 15:46:37 -05:00
committed by GitHub
parent 2284412def
commit 8e90bf46e9
6 changed files with 60 additions and 0 deletions

View File

@@ -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);
}
}

View File

@@ -101,6 +101,19 @@ The ban reason is: ""{ban.Reason}""
}
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)
{