CatStation/Content.Server/Administration/Systems/AdminQuickInfoSystem.cs
Doru991 252b5f9b09
Make quick info links in the ahelp window more robust (#44373)
* Store last player whose mind was in container

* Send last player who controlled the entity's session ID along with other quick info

* No more spam

* Display last player info if there is no active player on entity

* Better looking separator

* Better looking separator but I didnt forget to ctrl s this time

* newline

* Address reviews

* cleaning

* Tiny tweaks

---------

Co-authored-by: ScarKy0 <scarky0@onet.eu>
Co-authored-by: Connor Huffine <chuffine@gmail.com>
2026-07-08 08:32:08 +00:00

55 lines
1.9 KiB
C#

using System.Linq;
using Content.Server.Administration.Managers;
using Content.Shared.Administration;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
using Robust.Shared.Network;
namespace Content.Server.Administration.Systems;
/// <summary>
/// Server-side of the quick info system.
/// </summary>
/// <remarks>
/// Just a simple "replies to requests from authorized clients".
/// </remarks>
/// <seealso cref="QuickInfoShared" />
public sealed partial class AdminQuickInfoSystem : EntitySystem
{
[Dependency] private IAdminManager _adminManager = null!;
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<QuickInfoShared.Request>(HandleRequest);
}
private void HandleRequest(QuickInfoShared.Request ev, EntitySessionEventArgs args)
{
if (!_adminManager.HasAdminFlag(args.SenderSession, QuickInfoShared.RequiredFlag))
{
Log.Warning($"{args.SenderSession} tried to fetch entity quick info without required permissions!");
return;
}
var responses = ev.Entities.Select(e =>
{
if (!TryGetEntity(e, out var ent))
return new QuickInfoShared.SingleEntityInfo(e, false, "", "", null);
NetUserId? lastPlayer = null;
// Check the last mind that was attached to the entity and get its userid.
if (TryComp<MindContainerComponent>(ent, out var comp) && TryComp<MindComponent>(comp.LastMind, out var mindComp))
{
lastPlayer = mindComp.UserId;
}
var metadata = MetaData(ent.Value);
return new QuickInfoShared.SingleEntityInfo(e, true, metadata.EntityName, metadata.EntityPrototype?.ID, lastPlayer);
})
.ToArray();
RaiseNetworkEvent(new QuickInfoShared.Response { Entities = responses }, args.SenderSession);
}
}