]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
SS14-28662 Add Baby Jail: a Jail for Babies (inverse panic bunker) (#28763)
authorHannah Giovanna Dawson <karakkaraz@gmail.com>
Sun, 9 Jun 2024 18:58:10 +0000 (19:58 +0100)
committerGitHub <noreply@github.com>
Sun, 9 Jun 2024 18:58:10 +0000 (14:58 -0400)
19 files changed:
Content.Client/Administration/UI/AdminMenuWindow.xaml
Content.Client/Administration/UI/AdminMenuWindow.xaml.cs
Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailStatusWindow.xaml [new file with mode: 0644]
Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailStatusWindow.xaml.cs [new file with mode: 0644]
Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailTab.xaml [new file with mode: 0644]
Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailTab.xaml.cs [new file with mode: 0644]
Content.Client/UserInterface/Systems/Admin/AdminUIController.cs
Content.Server.Database/Model.cs
Content.Server/Administration/Commands/BabyJailCommand.cs [new file with mode: 0644]
Content.Server/Administration/Systems/AdminSystem.cs
Content.Server/Connection/ConnectionManager.cs
Content.Server/GameTicking/GameTicker.StatusShell.cs
Content.Shared/Administration/Events/BabyJailChangedEvent.cs [new file with mode: 0644]
Content.Shared/CCVar/CCVars.cs
Resources/Locale/en-US/administration/commands/babyjail.ftl [new file with mode: 0644]
Resources/Locale/en-US/administration/ui/admin-menu-window.ftl
Resources/Locale/en-US/administration/ui/tabs/babyjail-tab.ftl [new file with mode: 0644]
Resources/Locale/en-US/connection-messages.ftl
Resources/Locale/en-US/generic.ftl

index 311d67b826c7a2aad1711832d6917c95a257b322..d3d3df02d93609f7a4cb4c8804a922ab3d08135d 100644 (file)
@@ -6,7 +6,8 @@
     xmlns:tabs="clr-namespace:Content.Client.Administration.UI.Tabs"
     xmlns:playerTab="clr-namespace:Content.Client.Administration.UI.Tabs.PlayerTab"
     xmlns:objectsTab="clr-namespace:Content.Client.Administration.UI.Tabs.ObjectsTab"
-    xmlns:panic="clr-namespace:Content.Client.Administration.UI.Tabs.PanicBunkerTab">
+    xmlns:panic="clr-namespace:Content.Client.Administration.UI.Tabs.PanicBunkerTab"
+    xmlns:baby="clr-namespace:Content.Client.Administration.UI.Tabs.BabyJailTab">
     <TabContainer Name="MasterTabContainer">
         <adminTab:AdminTab />
         <adminbusTab:AdminbusTab />
@@ -14,6 +15,7 @@
         <tabs:RoundTab />
         <tabs:ServerTab />
         <panic:PanicBunkerTab Name="PanicBunkerControl" Access="Public" />
+        <baby:BabyJailTab Name="BabyJailControl" Access="Public" />
         <playerTab:PlayerTab Name="PlayerTabControl" Access="Public" />
         <objectsTab:ObjectsTab Name="ObjectsTabControl" Access="Public" />
     </TabContainer>
index c3ea67a3edb91d30162836bf1416e5cba7b7cabd..f3aa2572f2f99b294e730b0b20aad44e03851b12 100644 (file)
@@ -21,8 +21,12 @@ namespace Content.Client.Administration.UI
             MasterTabContainer.SetTabTitle(3, Loc.GetString("admin-menu-round-tab"));
             MasterTabContainer.SetTabTitle(4, Loc.GetString("admin-menu-server-tab"));
             MasterTabContainer.SetTabTitle(5, Loc.GetString("admin-menu-panic-bunker-tab"));
-            MasterTabContainer.SetTabTitle(6, Loc.GetString("admin-menu-players-tab"));
-            MasterTabContainer.SetTabTitle(7, Loc.GetString("admin-menu-objects-tab"));
+            /*
+             * TODO: Remove baby jail code once a more mature gateway process is established. This code is only being issued as a stopgap to help with potential tiding in the immediate future.
+             */
+            MasterTabContainer.SetTabTitle(6, Loc.GetString("admin-menu-baby-jail-tab"));
+            MasterTabContainer.SetTabTitle(7, Loc.GetString("admin-menu-players-tab"));
+            MasterTabContainer.SetTabTitle(8, Loc.GetString("admin-menu-objects-tab"));
         }
 
         protected override void Dispose(bool disposing)
diff --git a/Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailStatusWindow.xaml b/Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailStatusWindow.xaml
new file mode 100644 (file)
index 0000000..3432f11
--- /dev/null
@@ -0,0 +1,6 @@
+<controls:BabyJailStatusWindow
+    xmlns="https://spacestation14.io"
+    xmlns:controls="clr-namespace:Content.Client.Administration.UI.Tabs.BabyJailTab"
+    Title="{Loc admin-ui-baby-jail-window-title}">
+    <Label Name="MessageLabel" Access="Public" Text="{Loc admin-ui-baby-jail-is-enabled}" />
+</controls:BabyJailStatusWindow>
diff --git a/Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailStatusWindow.xaml.cs b/Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailStatusWindow.xaml.cs
new file mode 100644 (file)
index 0000000..4e5f679
--- /dev/null
@@ -0,0 +1,18 @@
+using Robust.Client.AutoGenerated;
+using Robust.Client.UserInterface.CustomControls;
+using Robust.Client.UserInterface.XAML;
+
+namespace Content.Client.Administration.UI.Tabs.BabyJailTab;
+
+/*
+ * TODO: Remove me once a more mature gateway process is established. This code is only being issued as a stopgap to help with potential tiding in the immediate future.
+ */
+
+[GenerateTypedNameReferences]
+public sealed partial class BabyJailStatusWindow : DefaultWindow
+{
+    public BabyJailStatusWindow()
+    {
+        RobustXamlLoader.Load(this);
+    }
+}
diff --git a/Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailTab.xaml b/Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailTab.xaml
new file mode 100644 (file)
index 0000000..dd770c2
--- /dev/null
@@ -0,0 +1,26 @@
+<controls:BabyJailTab
+    xmlns="https://spacestation14.io"
+    xmlns:controls="clr-namespace:Content.Client.Administration.UI.Tabs.BabyJailTab"
+    xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
+    Margin="4">
+    <BoxContainer Orientation="Vertical">
+        <cc:CommandButton Name="EnabledButton" Command="babyjail" ToggleMode="True"
+                          Text="{Loc admin-ui-baby-jail-disabled}"
+                          ToolTip="{Loc admin-ui-baby-jail-tooltip}" />
+        <cc:CommandButton Name="ShowReasonButton" Command="babyjail_show_reason"
+                          ToggleMode="True" Text="{Loc admin-ui-baby-jail-show-reason}"
+                          ToolTip="{Loc admin-ui-baby-jail-show-reason-tooltip}" />
+        <BoxContainer Orientation="Vertical" Margin="0 10 0 0">
+            <BoxContainer Orientation="Horizontal" Margin="2">
+                <Label Text="{Loc admin-ui-baby-jail-max-account-age}" MinWidth="175" />
+                <LineEdit Name="MaxAccountAge" MinWidth="50" Margin="0 0 5 0" />
+                <Label Text="{Loc generic-minutes}" />
+            </BoxContainer>
+            <BoxContainer Orientation="Horizontal" Margin="2">
+                <Label Text="{Loc admin-ui-baby-jail-max-overall-minutes}" MinWidth="175" />
+                <LineEdit Name="MaxOverallMinutes" MinWidth="50" Margin="0 0 5 0" />
+                <Label Text="{Loc generic-minutes}" />
+            </BoxContainer>
+        </BoxContainer>
+    </BoxContainer>
+</controls:BabyJailTab>
diff --git a/Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailTab.xaml.cs b/Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailTab.xaml.cs
new file mode 100644 (file)
index 0000000..aa9d6ce
--- /dev/null
@@ -0,0 +1,75 @@
+using Content.Shared.Administration.Events;
+using Robust.Client.AutoGenerated;
+using Robust.Client.UserInterface;
+using Robust.Client.UserInterface.XAML;
+using Robust.Shared.Console;
+
+/*
+ * TODO: Remove me once a more mature gateway process is established. This code is only being issued as a stopgap to help with potential tiding in the immediate future.
+ */
+
+namespace Content.Client.Administration.UI.Tabs.BabyJailTab;
+
+[GenerateTypedNameReferences]
+public sealed partial class BabyJailTab : Control
+{
+    [Dependency] private readonly IConsoleHost _console = default!;
+
+    private string _maxAccountAge;
+    private string _maxOverallMinutes;
+
+    public BabyJailTab()
+    {
+        RobustXamlLoader.Load(this);
+        IoCManager.InjectDependencies(this);
+
+        MaxAccountAge.OnTextEntered += args => SendMaxAccountAge(args.Text);
+        MaxAccountAge.OnFocusExit += args => SendMaxAccountAge(args.Text);
+        _maxAccountAge = MaxAccountAge.Text;
+
+        MaxOverallMinutes.OnTextEntered += args => SendMaxOverallMinutes(args.Text);
+        MaxOverallMinutes.OnFocusExit += args => SendMaxOverallMinutes(args.Text);
+        _maxOverallMinutes = MaxOverallMinutes.Text;
+    }
+
+    private void SendMaxAccountAge(string text)
+    {
+        if (string.IsNullOrWhiteSpace(text) ||
+            text == _maxAccountAge ||
+            !int.TryParse(text, out var minutes))
+        {
+            return;
+        }
+
+        _console.ExecuteCommand($"babyjail_max_account_age {minutes}");
+    }
+
+    private void SendMaxOverallMinutes(string text)
+    {
+        if (string.IsNullOrWhiteSpace(text) ||
+            text == _maxOverallMinutes ||
+            !int.TryParse(text, out var minutes))
+        {
+            return;
+        }
+
+        _console.ExecuteCommand($"babyjail_max_overall_minutes {minutes}");
+    }
+
+    public void UpdateStatus(BabyJailStatus status)
+    {
+        EnabledButton.Pressed = status.Enabled;
+        EnabledButton.Text = Loc.GetString(status.Enabled
+            ? "admin-ui-baby-jail-enabled"
+            : "admin-ui-baby-jail-disabled"
+        );
+        EnabledButton.ModulateSelfOverride = status.Enabled ? Color.Red : null;
+        ShowReasonButton.Pressed = status.ShowReason;
+
+        MaxAccountAge.Text = status.MaxAccountAgeMinutes.ToString();
+        _maxAccountAge = MaxAccountAge.Text;
+
+        MaxOverallMinutes.Text = status.MaxOverallMinutes.ToString();
+        _maxOverallMinutes = MaxOverallMinutes.Text;
+    }
+}
index 3d8235591ad4c52f0cc1856fe592843d3d7feace..e12ce0ab011c9b53808a16341b5b2f4df3678453 100644 (file)
@@ -3,6 +3,7 @@ using Content.Client.Administration.Systems;
 using Content.Client.Administration.UI;
 using Content.Client.Administration.UI.Tabs.ObjectsTab;
 using Content.Client.Administration.UI.Tabs.PanicBunkerTab;
+using Content.Client.Administration.UI.Tabs.BabyJailTab;
 using Content.Client.Administration.UI.Tabs.PlayerTab;
 using Content.Client.Gameplay;
 using Content.Client.Lobby;
@@ -37,11 +38,13 @@ public sealed class AdminUIController : UIController,
     private AdminMenuWindow? _window;
     private MenuButton? AdminButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.AdminButton;
     private PanicBunkerStatus? _panicBunker;
+    private BabyJailStatus? _babyJail;
 
     public override void Initialize()
     {
         base.Initialize();
         SubscribeNetworkEvent<PanicBunkerChangedEvent>(OnPanicBunkerUpdated);
+        SubscribeNetworkEvent<BabyJailChangedEvent>(OnBabyJailUpdated);
     }
 
     private void OnPanicBunkerUpdated(PanicBunkerChangedEvent msg, EntitySessionEventArgs args)
@@ -56,6 +59,18 @@ public sealed class AdminUIController : UIController,
         }
     }
 
+    private void OnBabyJailUpdated(BabyJailChangedEvent msg, EntitySessionEventArgs args)
+    {
+        var showDialog = _babyJail == null && msg.Status.Enabled;
+        _babyJail = msg.Status;
+        _window?.BabyJailControl.UpdateStatus(msg.Status);
+
+        if (showDialog)
+        {
+            UIManager.CreateWindow<BabyJailStatusWindow>().OpenCentered();
+        }
+    }
+
     public void OnStateEntered(GameplayState state)
     {
         EnsureWindow();
@@ -101,6 +116,13 @@ public sealed class AdminUIController : UIController,
         if (_panicBunker != null)
             _window.PanicBunkerControl.UpdateStatus(_panicBunker);
 
+        /*
+         * TODO: Remove baby jail code once a more mature gateway process is established. This code is only being issued as a stopgap to help with potential tiding in the immediate future.
+         */
+
+        if (_babyJail != null)
+            _window.BabyJailControl.UpdateStatus(_babyJail);
+
         _window.PlayerTabControl.OnEntryKeyBindDown += PlayerTabEntryKeyBindDown;
         _window.ObjectsTabControl.OnEntryKeyBindDown += ObjectsTabEntryKeyBindDown;
         _window.OnOpen += OnWindowOpen;
index 60935e8f06ad930e88f81d282f946a55107ea461..3510a5422e3c55d583af156a0846702e04f5708d 100644 (file)
@@ -889,6 +889,10 @@ namespace Content.Server.Database
         Whitelist = 1,
         Full = 2,
         Panic = 3,
+        /*
+         * TODO: Remove baby jail code once a more mature gateway process is established. This code is only being issued as a stopgap to help with potential tiding in the immediate future.
+         */
+        BabyJail = 4,
     }
 
     public class ServerBanHit
diff --git a/Content.Server/Administration/Commands/BabyJailCommand.cs b/Content.Server/Administration/Commands/BabyJailCommand.cs
new file mode 100644 (file)
index 0000000..058b67c
--- /dev/null
@@ -0,0 +1,139 @@
+using Content.Shared.Administration;
+using Content.Shared.CCVar;
+using Robust.Shared.Configuration;
+using Robust.Shared.Console;
+
+/*
+ * TODO: Remove baby jail code once a more mature gateway process is established. This code is only being issued as a stopgap to help with potential tiding in the immediate future.
+ */
+
+namespace Content.Server.Administration.Commands;
+
+[AdminCommand(AdminFlags.Server)]
+public sealed class BabyJailCommand : LocalizedCommands
+{
+    [Dependency] private readonly IConfigurationManager _cfg = default!;
+
+    public override string Command => "babyjail";
+
+    public override void Execute(IConsoleShell shell, string argStr, string[] args)
+    {
+        var toggle = Toggle(CCVars.BabyJailEnabled, shell, args, _cfg);
+        if (toggle == null)
+            return;
+
+        shell.WriteLine(Loc.GetString(toggle.Value ? "babyjail-command-enabled" : "babyjail-command-disabled"));
+    }
+
+    public static bool? Toggle(CVarDef<bool> cvar, IConsoleShell shell, string[] args, IConfigurationManager config)
+    {
+        if (args.Length > 1)
+        {
+            shell.WriteError(Loc.GetString("shell-need-between-arguments",("lower", 0), ("upper", 1)));
+            return null;
+        }
+
+        var enabled = config.GetCVar(cvar);
+
+        switch (args.Length)
+        {
+            case 0:
+                enabled = !enabled;
+                break;
+            case 1 when !bool.TryParse(args[0], out enabled):
+                shell.WriteError(Loc.GetString("shell-argument-must-be-boolean"));
+                return null;
+        }
+
+        config.SetCVar(cvar, enabled);
+
+        return enabled;
+    }
+}
+
+
+[AdminCommand(AdminFlags.Server)]
+public sealed class BabyJailShowReasonCommand : LocalizedCommands
+{
+    [Dependency] private readonly IConfigurationManager _cfg = default!;
+
+    public override string Command => "babyjail_show_reason";
+
+    public override void Execute(IConsoleShell shell, string argStr, string[] args)
+    {
+        var toggle = BabyJailCommand.Toggle(CCVars.BabyJailShowReason, shell, args, _cfg);
+        if (toggle == null)
+            return;
+
+        shell.WriteLine(Loc.GetString(toggle.Value
+            ? "babyjail-command-show-reason-enabled"
+            : "babyjail-command-show-reason-disabled"
+        ));
+    }
+}
+
+[AdminCommand(AdminFlags.Server)]
+public sealed class BabyJailMinAccountAgeCommand : LocalizedCommands
+{
+    [Dependency] private readonly IConfigurationManager _cfg = default!;
+
+    public override string Command => "babyjail_max_account_age";
+
+    public override void Execute(IConsoleShell shell, string argStr, string[] args)
+    {
+        switch (args.Length)
+        {
+            case 0:
+            {
+                var current = _cfg.GetCVar(CCVars.BabyJailMaxAccountAge);
+                shell.WriteLine(Loc.GetString("babyjail-command-max-account-age-is", ("minutes", current)));
+                break;
+            }
+            case > 1:
+                shell.WriteError(Loc.GetString("shell-need-between-arguments",("lower", 0), ("upper", 1)));
+                return;
+        }
+
+        if (!int.TryParse(args[0], out var minutes))
+        {
+            shell.WriteError(Loc.GetString("shell-argument-must-be-number"));
+            return;
+        }
+
+        _cfg.SetCVar(CCVars.BabyJailMaxAccountAge, minutes);
+        shell.WriteLine(Loc.GetString("babyjail-command-max-account-age-set", ("minutes", minutes)));
+    }
+}
+
+[AdminCommand(AdminFlags.Server)]
+public sealed class BabyJailMinOverallHoursCommand : LocalizedCommands
+{
+    [Dependency] private readonly IConfigurationManager _cfg = default!;
+
+    public override string Command => "babyjail_max_overall_minutes";
+
+    public override void Execute(IConsoleShell shell, string argStr, string[] args)
+    {
+        switch (args.Length)
+        {
+            case 0:
+            {
+                var current = _cfg.GetCVar(CCVars.BabyJailMaxOverallMinutes);
+                shell.WriteLine(Loc.GetString("babyjail-command-max-overall-minutes-is", ("minutes", current)));
+                break;
+            }
+            case > 1:
+                shell.WriteError(Loc.GetString("shell-need-between-arguments",("lower", 0), ("upper", 1)));
+                return;
+        }
+
+        if (!int.TryParse(args[0], out var hours))
+        {
+            shell.WriteError(Loc.GetString("shell-argument-must-be-number"));
+            return;
+        }
+
+        _cfg.SetCVar(CCVars.BabyJailMaxOverallMinutes, hours);
+        shell.WriteLine(Loc.GetString("babyjail-command-overall-minutes-set", ("hours", hours)));
+    }
+}
index a1a6b33ebcb7fbb8c11eb2a6832ea8e170949963..a12d106880cf57fe79e8d223c3294f59230ca453 100644 (file)
@@ -62,6 +62,7 @@ namespace Content.Server.Administration.Systems
 
         private readonly HashSet<NetUserId> _roundActivePlayers = new();
         public readonly PanicBunkerStatus PanicBunker = new();
+        public readonly BabyJailStatus BabyJail = new();
 
         public override void Initialize()
         {
@@ -70,14 +71,25 @@ namespace Content.Server.Administration.Systems
             _playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
             _adminManager.OnPermsChanged += OnAdminPermsChanged;
 
+            // Panic Bunker Settings
             Subs.CVar(_config, CCVars.PanicBunkerEnabled, OnPanicBunkerChanged, true);
             Subs.CVar(_config, CCVars.PanicBunkerDisableWithAdmins, OnPanicBunkerDisableWithAdminsChanged, true);
             Subs.CVar(_config, CCVars.PanicBunkerEnableWithoutAdmins, OnPanicBunkerEnableWithoutAdminsChanged, true);
             Subs.CVar(_config, CCVars.PanicBunkerCountDeadminnedAdmins, OnPanicBunkerCountDeadminnedAdminsChanged, true);
-            Subs.CVar(_config, CCVars.PanicBunkerShowReason, OnShowReasonChanged, true);
+            Subs.CVar(_config, CCVars.PanicBunkerShowReason, OnPanicBunkerShowReasonChanged, true);
             Subs.CVar(_config, CCVars.PanicBunkerMinAccountAge, OnPanicBunkerMinAccountAgeChanged, true);
             Subs.CVar(_config, CCVars.PanicBunkerMinOverallHours, OnPanicBunkerMinOverallHoursChanged, true);
 
+            /*
+             * TODO: Remove baby jail code once a more mature gateway process is established. This code is only being issued as a stopgap to help with potential tiding in the immediate future.
+             */
+
+            // Baby Jail Settings
+            Subs.CVar(_config, CCVars.BabyJailEnabled, OnBabyJailChanged, true);
+            Subs.CVar(_config, CCVars.BabyJailShowReason, OnBabyJailShowReasonChanged, true);
+            Subs.CVar(_config, CCVars.BabyJailMaxAccountAge, OnBabyJailMaxAccountAgeChanged, true);
+            Subs.CVar(_config, CCVars.BabyJailMaxOverallMinutes, OnBabyJailMaxOverallMinutesChanged, true);
+
             SubscribeLocalEvent<IdentityChangedEvent>(OnIdentityChanged);
             SubscribeLocalEvent<PlayerAttachedEvent>(OnPlayerAttached);
             SubscribeLocalEvent<PlayerDetachedEvent>(OnPlayerDetached);
@@ -249,6 +261,17 @@ namespace Content.Server.Administration.Systems
             SendPanicBunkerStatusAll();
         }
 
+        private void OnBabyJailChanged(bool enabled)
+        {
+            BabyJail.Enabled = enabled;
+            _chat.SendAdminAlert(Loc.GetString(enabled
+                ? "admin-ui-baby-jail-enabled-admin-alert"
+                : "admin-ui-baby-jail-disabled-admin-alert"
+            ));
+
+            SendBabyJailStatusAll();
+        }
+
         private void OnPanicBunkerDisableWithAdminsChanged(bool enabled)
         {
             PanicBunker.DisableWithAdmins = enabled;
@@ -267,24 +290,42 @@ namespace Content.Server.Administration.Systems
             UpdatePanicBunker();
         }
 
-        private void OnShowReasonChanged(bool enabled)
+        private void OnPanicBunkerShowReasonChanged(bool enabled)
         {
             PanicBunker.ShowReason = enabled;
             SendPanicBunkerStatusAll();
         }
 
+        private void OnBabyJailShowReasonChanged(bool enabled)
+        {
+            BabyJail.ShowReason = enabled;
+            SendBabyJailStatusAll();
+        }
+
         private void OnPanicBunkerMinAccountAgeChanged(int minutes)
         {
             PanicBunker.MinAccountAgeHours = minutes / 60;
             SendPanicBunkerStatusAll();
         }
 
+        private void OnBabyJailMaxAccountAgeChanged(int minutes)
+        {
+            BabyJail.MaxAccountAgeMinutes = minutes;
+            SendBabyJailStatusAll();
+        }
+
         private void OnPanicBunkerMinOverallHoursChanged(int hours)
         {
             PanicBunker.MinOverallHours = hours;
             SendPanicBunkerStatusAll();
         }
 
+        private void OnBabyJailMaxOverallMinutesChanged(int minutes)
+        {
+            BabyJail.MaxOverallMinutes = minutes;
+            SendBabyJailStatusAll();
+        }
+
         private void UpdatePanicBunker()
         {
             var admins = PanicBunker.CountDeadminnedAdmins
@@ -326,6 +367,15 @@ namespace Content.Server.Administration.Systems
             }
         }
 
+        private void SendBabyJailStatusAll()
+        {
+            var ev = new BabyJailChangedEvent(BabyJail);
+            foreach (var admin in _adminManager.AllAdmins)
+            {
+                RaiseNetworkEvent(ev, admin);
+            }
+        }
+
         /// <summary>
         ///     Erases a player from the round.
         ///     This removes them and any trace of them from the round, deleting their
index cd89f48d49f7f93ba83e1d2234dbe635a518c97b..2211a245322b7b5e3069270e796f32cf7c7188c3 100644 (file)
@@ -13,6 +13,9 @@ using Robust.Shared.Configuration;
 using Robust.Shared.Network;
 using Robust.Shared.Timing;
 
+/*
+ * TODO: Remove baby jail code once a more mature gateway process is established. This code is only being issued as a stopgap to help with potential tiding in the immediate future.
+ */
 
 namespace Content.Server.Connection
 {
@@ -125,6 +128,10 @@ namespace Content.Server.Connection
             }
         }
 
+        /*
+         * TODO: Jesus H Christ what is this utter mess of a function
+         * TODO: Break this apart into is constituent steps.
+         */
         private async Task<(ConnectionDenyReason, string, List<ServerBanDef>? bansHit)?> ShouldDeny(
             NetConnectingArgs e)
         {
@@ -202,6 +209,14 @@ namespace Content.Server.Connection
                 }
             }
 
+            if (_cfg.GetCVar(CCVars.BabyJailEnabled) && adminData == null)
+            {
+                var result = await IsInvalidConnectionDueToBabyJail(userId, e);
+
+                if (result.IsInvalid)
+                    return (ConnectionDenyReason.BabyJail, result.Reason, null);
+            }
+
             var wasInGame = EntitySystem.TryGet<GameTicker>(out var ticker) &&
                             ticker.PlayerGameStatuses.TryGetValue(userId, out var status) &&
                             status == PlayerGameStatus.JoinedGame;
@@ -231,6 +246,57 @@ namespace Content.Server.Connection
             return null;
         }
 
+        private async Task<(bool IsInvalid, string Reason)> IsInvalidConnectionDueToBabyJail(NetUserId userId, NetConnectingArgs e)
+        {
+            // If you're whitelisted then bypass this whole thing
+            if (await _db.GetWhitelistStatusAsync(userId))
+                return (false, "");
+
+            // Initial cvar retrieval
+            var showReason = _cfg.GetCVar(CCVars.BabyJailShowReason);
+            var reason = _cfg.GetCVar(CCVars.BabyJailCustomReason);
+            var maxAccountAgeMinutes = _cfg.GetCVar(CCVars.BabyJailMaxAccountAge);
+            var maxPlaytimeMinutes = _cfg.GetCVar(CCVars.BabyJailMaxOverallMinutes);
+
+            // Wait some time to lookup data
+            var record = await _dbManager.GetPlayerRecordByUserId(userId);
+
+            var isAccountAgeInvalid = record == null || record.FirstSeenTime.CompareTo(DateTimeOffset.Now - TimeSpan.FromMinutes(maxAccountAgeMinutes)) <= 0;
+            if (isAccountAgeInvalid && showReason)
+            {
+                var locAccountReason = reason != string.Empty
+                    ? reason
+                    : Loc.GetString("baby-jail-account-denied-reason",
+                        ("reason",
+                            Loc.GetString(
+                                "baby-jail-account-reason-account",
+                                ("minutes", maxAccountAgeMinutes))));
+
+                return (true, locAccountReason);
+            }
+
+            var overallTime = ( await _db.GetPlayTimes(e.UserId)).Find(p => p.Tracker == PlayTimeTrackingShared.TrackerOverall);
+            var isTotalPlaytimeInvalid = overallTime == null || overallTime.TimeSpent.TotalMinutes >= maxPlaytimeMinutes;
+
+            if (isTotalPlaytimeInvalid && showReason)
+            {
+                var locPlaytimeReason = reason != string.Empty
+                    ? reason
+                    : Loc.GetString("baby-jail-account-denied-reason",
+                        ("reason",
+                            Loc.GetString(
+                                "baby-jail-account-reason-overall",
+                                ("minutes", maxPlaytimeMinutes))));
+
+                return (true, locPlaytimeReason);
+            }
+
+            if (!showReason && isTotalPlaytimeInvalid || isAccountAgeInvalid)
+                return (true, Loc.GetString("baby-jail-account-denied"));
+
+            return (false, "");
+        }
+
         private bool HasTemporaryBypass(NetUserId user)
         {
             return _temporaryBypasses.TryGetValue(user, out var time) && time > _gameTiming.RealTime;
index fcf5b1c25cd7e6f9c4c91a8a12344222b5cccdea..67367b94b7f5abe10bdab6afba86d8e9f3426fe6 100644 (file)
@@ -46,6 +46,12 @@ namespace Content.Server.GameTicking
                 jObject["players"] = _playerManager.PlayerCount;
                 jObject["soft_max_players"] = _cfg.GetCVar(CCVars.SoftMaxPlayers);
                 jObject["panic_bunker"] = _cfg.GetCVar(CCVars.PanicBunkerEnabled);
+
+                /*
+                 * TODO: Remove baby jail code once a more mature gateway process is established. This code is only being issued as a stopgap to help with potential tiding in the immediate future.
+                 */
+
+                jObject["baby_jail"] = _cfg.GetCVar(CCVars.BabyJailEnabled);
                 jObject["run_level"] = (int) _runLevel;
                 if (preset != null)
                     jObject["preset"] = Loc.GetString(preset.ModeTitle);
diff --git a/Content.Shared/Administration/Events/BabyJailChangedEvent.cs b/Content.Shared/Administration/Events/BabyJailChangedEvent.cs
new file mode 100644 (file)
index 0000000..56d5ce5
--- /dev/null
@@ -0,0 +1,22 @@
+using Robust.Shared.Serialization;
+
+/*
+ * TODO: Remove baby jail code once a more mature gateway process is established. This code is only being issued as a stopgap to help with potential tiding in the immediate future.
+ */
+
+namespace Content.Shared.Administration.Events;
+
+[Serializable, NetSerializable]
+public sealed class BabyJailStatus
+{
+    public bool Enabled;
+    public bool ShowReason;
+    public int MaxAccountAgeMinutes;
+    public int MaxOverallMinutes;
+}
+
+[Serializable, NetSerializable]
+public sealed class BabyJailChangedEvent(BabyJailStatus status) : EntityEventArgs
+{
+    public BabyJailStatus Status = status;
+}
index a872a3d4e7b2193c3b978d18414f62640d33efb0..491e5343959b09f86437ff53d46c868afc654303 100644 (file)
@@ -320,6 +320,48 @@ namespace Content.Shared.CCVar
         public static readonly CVarDef<bool> BypassBunkerWhitelist =
             CVarDef.Create("game.panic_bunker.whitelisted_can_bypass", true, CVar.SERVERONLY);
 
+        /*
+         * TODO: Remove baby jail code once a more mature gateway process is established. This code is only being issued as a stopgap to help with potential tiding in the immediate future.
+         */
+
+        /// <summary>
+        /// Whether the baby jail is currently enabled.
+        /// </summary>
+        public static readonly CVarDef<bool> BabyJailEnabled  =
+            CVarDef.Create("game.baby_jail.enabled", false, CVar.NOTIFY | CVar.REPLICATED | CVar.SERVER);
+
+        /// <summary>
+        /// Show reason of disconnect for user or not.
+        /// </summary>
+        public static readonly CVarDef<bool> BabyJailShowReason =
+            CVarDef.Create("game.baby_jail.show_reason", false, CVar.SERVERONLY);
+
+        /// <summary>
+        /// Maximum age of the account (from server's PoV, so from first-seen date) in minutes that can access baby
+        /// jailed servers.
+        /// </summary>
+        public static readonly CVarDef<int> BabyJailMaxAccountAge =
+            CVarDef.Create("game.baby_jail.max_account_age", 1440, CVar.SERVERONLY);
+
+        /// <summary>
+        /// Maximum overall played time allowed to access baby jailed servers.
+        /// </summary>
+        public static readonly CVarDef<int> BabyJailMaxOverallMinutes =
+            CVarDef.Create("game.baby_jail.max_overall_minutes", 120, CVar.SERVERONLY);
+
+        /// <summary>
+        /// A custom message that will be used for connections denied due to the baby jail.
+        /// If not empty, then will overwrite <see cref="BabyJailShowReason"/>
+        /// </summary>
+        public static readonly CVarDef<string> BabyJailCustomReason =
+            CVarDef.Create("game.baby_jail.custom_reason", string.Empty, CVar.SERVERONLY);
+
+        /// <summary>
+        /// Allow bypassing the baby jail if the user is whitelisted.
+        /// </summary>
+        public static readonly CVarDef<bool> BypassBabyJailWhitelist =
+            CVarDef.Create("game.baby_jail.whitelisted_can_bypass", true, CVar.SERVERONLY);
+
         /// <summary>
         /// Make people bonk when trying to climb certain objects like tables.
         /// </summary>
diff --git a/Resources/Locale/en-US/administration/commands/babyjail.ftl b/Resources/Locale/en-US/administration/commands/babyjail.ftl
new file mode 100644 (file)
index 0000000..5a9d949
--- /dev/null
@@ -0,0 +1,19 @@
+cmd-babyjail-desc = Toggles the baby jail, which enables stricter restrictions on who's allowed to join the server.
+cmd-babyjail-help = Usage: babyjail
+babyjail-command-enabled = Baby jail has been enabled.
+babyjail-command-disabled = Baby jail has been disabled.
+
+cmd-babyjail_show_reason-desc = Toggles whether or not to show connecting clients the reason why the baby jail blocked them from joining.
+cmd-babyjail_show_reason-help = Usage: babyjail_show_reason
+babyjail-command-show-reason-enabled = The baby jail will now show a reason to users it blocks from connecting.
+babyjail-command-show-reason-disabled = The baby jail will no longer show a reason to users it blocks from connecting.
+
+cmd-babyjail_max_account_age-desc = Gets or sets the maximum account age in minutes that an account can have to be allowed to connect with the baby jail enabled.
+cmd-babyjail_max_account_age-help = Usage: babyjail_max_account_age <minutes>
+babyjail-command-max-account-age-is = The maximum account age for the baby jail is {$minutes} minutes.
+babyjail-command-max-account-age-set = Set the maximum account age for the baby jail to {$minutes} minutes.
+
+cmd-babyjail_max_overall_minutes-desc = Gets or sets the maximum overall playtime in minutes that an account can have to be allowed to connect with the baby jail enabled.
+cmd-babyjail_max_overall_minutes-help = Usage: babyjail_max_overall_minutes <minutes>
+babyjail-command-max-overall-minutes-is = The maximum overall playtime for the baby jail is {$minutes} minutes.
+babyjail-command-max-overall-minutes-set = Set the maximum overall playtime for the baby jail to {$minutes} minutes.
index c759e4c2cb16f2b3b857f1a4e8eb259e8667886f..03b2046a9e15ba0344d6948d053b204fd146a59b 100644 (file)
@@ -7,5 +7,6 @@ admin-menu-atmos-tab = Atmos
 admin-menu-round-tab = Round
 admin-menu-server-tab = Server
 admin-menu-panic-bunker-tab = Panic Bunker
+admin-menu-baby-jail-tab = Baby Jail
 admin-menu-players-tab = Players
 admin-menu-objects-tab = Objects
diff --git a/Resources/Locale/en-US/administration/ui/tabs/babyjail-tab.ftl b/Resources/Locale/en-US/administration/ui/tabs/babyjail-tab.ftl
new file mode 100644 (file)
index 0000000..ad58e43
--- /dev/null
@@ -0,0 +1,16 @@
+admin-ui-baby-jail-window-title = Baby Jail
+
+admin-ui-baby-jail-enabled = Baby Jail Enabled
+admin-ui-baby-jail-disabled = Baby Jail Disabled
+admin-ui-baby-jail-tooltip = The baby jail restricts players from joining if their account is too old or they do have too much overall playtime on this server.
+
+admin-ui-baby-jail-show-reason = Show Reason
+admin-ui-baby-jail-show-reason-tooltip = Show the user why they were blocked from connecting by the baby jail.
+
+admin-ui-baby-jail-max-account-age = Max. Account Age
+admin-ui-baby-jail-max-overall-minutes = Max. Overall Playtime
+
+admin-ui-baby-jail-is-enabled = The baby jail is currently enabled.
+
+admin-ui-baby-jail-enabled-admin-alert = The baby jail has been enabled.
+admin-ui-baby-jail-disabled-admin-alert = The baby jail has been disabled.
index 7f4afce8b965f0350ea5a35a68acd954a54e09c0..88b6442e39566fcef28993d24fe5ff8ccba4cfaf 100644 (file)
@@ -39,3 +39,9 @@ panic-bunker-account-denied = This server is in panic bunker mode, often enabled
 panic-bunker-account-denied-reason = This server is in panic bunker mode, often enabled as a precaution against raids. New connections by accounts not meeting certain requirements are temporarily not accepted. Try again later. Reason: "{$reason}"
 panic-bunker-account-reason-account = Your Space Station 14 account is too new. It must be older than {$minutes} minutes
 panic-bunker-account-reason-overall = Your overall playtime on the server must be greater than {$hours} hours
+
+baby-jail-account-denied = This server is a newbie server, intended for new players and those who want to help them. New connections by accounts that are too old or are not on a whitelist are not accepted. Check out some other servers and see everything Space Station 14 has to offer. Have fun!
+baby-jail-account-denied-reason = This server is a newbie server, intended for new players and those who want to help them. New connections by accounts that are too old or are not on a whitelist are not accepted. Check out some other servers and see everything Space Station 14 has to offer. Have fun! Reason: "{$reason}"
+baby-jail-account-reason-account = Your Space Station 14 account is too old. It must be younger than {$minutes} minutes
+baby-jail-account-reason-overall = Your overall playtime on the server must be younger than {$hours} hours
+
index d9c1305e4160b16d8ac6c3173ca378b4faa6ecd2..350409788521c2a92dd9f076557fb80075518af7 100644 (file)
@@ -10,6 +10,7 @@ generic-error = error
 generic-invalid = invalid
 
 generic-hours = hours
+generic-minutes = minutes
 
 generic-playtime-title = Playtime