Fix late join & observe to de-admin admins. (#28319)

This commit is contained in:
Repo
2024-05-29 06:00:42 +12:00
committed by GitHub
parent 1777eea9a4
commit eb3f27526b
5 changed files with 38 additions and 2 deletions

View File

@@ -8,6 +8,7 @@
<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 admin" Name="ObserveAsAdminButton" Text="{Loc 'observe-as-admin'}" SizeFlagsStretchRatio="1" Visible="False"/>
</BoxContainer>
</BoxContainer>
</DefaultWindow>

View 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(); };

View 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;
}

View 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)
{

View 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