Files
tbd-station-14/Content.Server/Administration/Commands/AdminWhoCommand.cs
c4llv07e 904d75c8a9 Fix empty lines in adminwho with stealthmins. (#34122)
Don't print newline if admin is hidden.
2025-01-08 10:23:33 -05:00

63 lines
1.8 KiB
C#

using System.Text;
using Content.Server.Administration.Managers;
using Content.Server.Afk;
using Content.Shared.Administration;
using Robust.Shared.Console;
using Robust.Shared.Utility;
namespace Content.Server.Administration.Commands;
[AdminCommand(AdminFlags.AdminWho)]
public sealed class AdminWhoCommand : IConsoleCommand
{
public string Command => "adminwho";
public string Description => "Returns a list of all admins on the server";
public string Help => "Usage: adminwho";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var adminMgr = IoCManager.Resolve<IAdminManager>();
var afk = IoCManager.Resolve<IAfkManager>();
var seeStealth = true;
// If null it (hopefully) means it is being called from the console.
if (shell.Player != null)
{
var playerData = adminMgr.GetAdminData(shell.Player);
seeStealth = playerData != null && playerData.CanStealth();
}
var sb = new StringBuilder();
var first = true;
foreach (var admin in adminMgr.ActiveAdmins)
{
var adminData = adminMgr.GetAdminData(admin)!;
DebugTools.AssertNotNull(adminData);
if (adminData.Stealth && !seeStealth)
continue;
if (!first)
sb.Append('\n');
first = false;
sb.Append(admin.Name);
if (adminData.Title is { } title)
sb.Append($": [{title}]");
if (adminData.Stealth)
sb.Append(" (S)");
if (shell.Player is { } player && adminMgr.HasAdminFlag(player, AdminFlags.Admin))
{
if (afk.IsAfk(admin))
sb.Append(" [AFK]");
}
}
shell.WriteLine(sb.ToString());
}
}