]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix late join & observe to de-admin admins. (#28319)
authorRepo <47093363+Titian3@users.noreply.github.com>
Tue, 28 May 2024 18:00:42 +0000 (06:00 +1200)
committerGitHub <noreply@github.com>
Tue, 28 May 2024 18:00:42 +0000 (14:00 -0400)
Content.Client/Lobby/UI/ObserveWarningWindow.xaml
Content.Client/Lobby/UI/ObserveWarningWindow.xaml.cs
Content.Server/GameTicking/Commands/JoinGameCommand.cs
Content.Server/GameTicking/Commands/ObserveCommand.cs
Resources/Locale/en-US/lobby/ui/observe-warning-window.ftl

index 3fe8e83f57dfddca75ea13ce4856245bca9d7adb..2feac5792a1ecec530c23f9c9cac299281a98a59 100644 (file)
@@ -4,10 +4,11 @@
     <BoxContainer Orientation="Vertical">
         <Label Text="{Loc 'observe-warning-1'}"/>
         <Label Text="{Loc 'observe-warning-2'}"/>
-        <BoxContainer Orientation="Horizontal" >
+        <BoxContainer Orientation="Horizontal">
             <Button Name="NevermindButton" Text="{Loc 'observe-nevermind'}" SizeFlagsStretchRatio="1"/>
             <Control HorizontalExpand="True" SizeFlagsStretchRatio="2" />
-            <cc:CommandButton  Command="observe" Name="ObserveButton" StyleClasses="Caution" Text="{Loc 'observe-confirm'}" SizeFlagsStretchRatio="1"/>
+            <cc:CommandButton Command="observe" Name="ObserveButton" StyleClasses="Caution" Text="{Loc 'observe-confirm'}" SizeFlagsStretchRatio="1"/>
+            <cc:CommandButton Command="observe admin" Name="ObserveAsAdminButton" Text="{Loc 'observe-as-admin'}" SizeFlagsStretchRatio="1" Visible="False"/>
         </BoxContainer>
     </BoxContainer>
 </DefaultWindow>
index 718f40b2aa064561bfe5ee8832805ff5847566cd..a002043ab114d4a3b5861eb2903a0b5ce3efe98a 100644 (file)
@@ -1,5 +1,7 @@
+using Content.Shared.Administration.Managers;
 using JetBrains.Annotations;
 using Robust.Client.AutoGenerated;
+using Robust.Client.Player;
 using Robust.Client.UserInterface.CustomControls;
 using Robust.Client.UserInterface.XAML;
 
@@ -9,11 +11,22 @@ namespace Content.Client.Lobby.UI;
 [UsedImplicitly]
 public sealed partial class ObserveWarningWindow : DefaultWindow
 {
+    [Dependency] private readonly ISharedAdminManager _adminManager = default!;
+    [Dependency] private readonly IPlayerManager _playerManager = default!;
+
     public ObserveWarningWindow()
     {
         Title = Loc.GetString("observe-warning-window-title");
         RobustXamlLoader.Load(this);
         IoCManager.InjectDependencies(this);
+        var player = _playerManager.LocalSession;
+
+        if (player != null && _adminManager.IsAdmin(player))
+        {
+            ObserveButton.Text = Loc.GetString("observe-as-player");
+            ObserveAsAdminButton.Visible = true;
+            ObserveAsAdminButton.OnPressed += _ => { this.Close(); };
+        }
 
         ObserveButton.OnPressed += _ => { this.Close(); };
         NevermindButton.OnPressed += _ => { this.Close(); };
index 3276b91200324d9fc6492fc63a3a4b0b44508701..a32a2f94955b0a1e1e0d6ef3f44317c03e440b87 100644 (file)
@@ -1,7 +1,10 @@
+using Content.Server.Administration.Managers;
 using Content.Server.Station.Systems;
 using Content.Shared.Administration;
+using Content.Shared.CCVar;
 using Content.Shared.GameTicking;
 using Content.Shared.Roles;
+using Robust.Shared.Configuration;
 using Robust.Shared.Console;
 using Robust.Shared.Prototypes;
 
@@ -12,6 +15,8 @@ namespace Content.Server.GameTicking.Commands
     {
         [Dependency] private readonly IEntityManager _entManager = default!;
         [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
+        [Dependency] private readonly IAdminManager _adminManager = default!;
+        [Dependency] private readonly IConfigurationManager _cfg = default!;
 
         public string Command => "joingame";
         public string Description => "";
@@ -67,6 +72,12 @@ namespace Content.Server.GameTicking.Commands
                     shell.WriteLine($"{jobPrototype.LocalizedName} has no available slots.");
                     return;
                 }
+
+                if (_adminManager.IsAdmin(player) && _cfg.GetCVar(CCVars.AdminDeadminOnJoin))
+                {
+                    _adminManager.DeAdmin(player);
+                }
+
                 ticker.MakeJoinGame(player, station, id);
                 return;
             }
index 16c2c3261dea3ee11b66398ab6a6d74cd8e2bc31..5a035033179b051f5aa990ab4a08a306771dbef6 100644 (file)
@@ -1,3 +1,4 @@
+using Content.Server.Administration.Managers;
 using Content.Shared.Administration;
 using Content.Shared.GameTicking;
 using Robust.Shared.Console;
@@ -8,6 +9,7 @@ namespace Content.Server.GameTicking.Commands
     sealed class ObserveCommand : IConsoleCommand
     {
         [Dependency] private readonly IEntityManager _e = default!;
+        [Dependency] private readonly IAdminManager _adminManager = default!;
 
         public string Command => "observe";
         public string Description => "";
@@ -28,6 +30,13 @@ namespace Content.Server.GameTicking.Commands
                 return;
             }
 
+            var isAdminCommand = args.Length > 0 && args[0].ToLower() == "admin";
+
+            if (!isAdminCommand && _adminManager.IsAdmin(player))
+            {
+                _adminManager.DeAdmin(player);
+            }
+
             if (ticker.PlayerGameStatuses.TryGetValue(player.UserId, out var status) &&
                 status != PlayerGameStatus.JoinedGame)
             {
index 4f1c87f16a7ab29c32eb52b36d97f362ab2c3ba6..be07604c734f1bd9f3d11222e0fda930dc940d45 100644 (file)
@@ -3,3 +3,5 @@ observe-confirm = Observe
 observe-warning-1 = Are you sure you want to observe?
 observe-warning-2 = You cannot play in the round if you do so.
 observe-warning-window-title = Warning
+observe-as-admin = Admin Observe
+observe-as-player = Player Observe