forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SS14-28662 Add Baby Jail: a Jail for Babies (inverse panic bunker) (s…
- Loading branch information
1 parent
f4e80b0
commit 3ceb92a
Showing
19 changed files
with
530 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailStatusWindow.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
18 changes: 18 additions & 0 deletions
18
Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailStatusWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailTab.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
75 changes: 75 additions & 0 deletions
75
Content.Client/Administration/UI/Tabs/BabyJailTab/BabyJailTab.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
Content.Server/Administration/Commands/BabyJailCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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))); | ||
} | ||
} |
Oops, something went wrong.