Small Refactor of getting identity info (#43941)

* Removed TryGetIdentityShortInfoEvent()

* Removed unused using

* cleanup

* .

* Wrong if statement

* Directed Event

* cleanup

* cleanup

* keep this

* refactor: whitespace cleanups + unused usings

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Co-authored-by: Fildrance <fildrance@gmail.com>
This commit is contained in:
riccardi48
2026-05-15 20:49:41 +01:00
committed by GitHub
parent e468f836d8
commit cd0d45cc5a
14 changed files with 60 additions and 89 deletions
@@ -7,7 +7,6 @@ using Content.Shared.Cargo;
using Content.Shared.Cargo.Components;
using Content.Shared.Cargo.Prototypes;
using Content.Shared.Database;
using Content.Shared.IdentityManagement;
using Content.Shared.Labels.EntitySystems;
using Content.Shared.NameIdentifier;
using Content.Shared.Paper;
@@ -474,11 +473,7 @@ public sealed partial class CargoSystem
{
string? actorName = null;
if (actor != null)
{
var getIdentityEvent = new TryGetIdentityShortInfoEvent(ent.Owner, actor.Value);
RaiseLocalEvent(getIdentityEvent);
actorName = getIdentityEvent.Title;
}
actorName = _identity.GetIdentityShortInfo(actor.Value, ent.Owner);
ent.Comp.History.Add(new CargoBountyHistoryData(data,
skipped
@@ -3,7 +3,6 @@ using Content.Shared.Cargo.Components;
using Content.Shared.CCVar;
using Content.Shared.Database;
using Content.Shared.Emag.Systems;
using Content.Shared.IdentityManagement;
using Content.Shared.UserInterface;
namespace Content.Server.Cargo.Systems;
@@ -46,13 +45,12 @@ public sealed partial class CargoSystem
}
ent.Comp.NextAccountActionTime = Timing.CurTime + ent.Comp.AccountActionDelay;
UpdateBankAccount((station, bank), -args.Amount, ent.Comp.Account, dirty: false);
UpdateBankAccount((station, bank), -args.Amount, ent.Comp.Account, dirty: false);
_audio.PlayPvs(ApproveSound, ent);
var tryGetIdentityShortInfoEvent = new TryGetIdentityShortInfoEvent(ent, args.Actor);
RaiseLocalEvent(tryGetIdentityShortInfoEvent);
var ourAccount = _protoMan.Index(ent.Comp.Account);
var name = _identity.GetIdentityShortInfo(args.Actor, ent)
?? Loc.GetString("cargo-console-fund-transfer-user-unknown");
if (args.Account == null)
{
var stackPrototype = _protoMan.Index(ent.Comp.CashType);
@@ -61,7 +59,7 @@ public sealed partial class CargoSystem
if (!_emag.CheckFlag(ent, EmagType.Interaction))
{
var msg = Loc.GetString("cargo-console-fund-withdraw-broadcast",
("name", tryGetIdentityShortInfoEvent.Title ?? Loc.GetString("cargo-console-fund-transfer-user-unknown")),
("name", name),
("amount", args.Amount),
("name1", Loc.GetString(ourAccount.Name)),
("code1", Loc.GetString(ourAccount.Code)));
@@ -76,7 +74,7 @@ public sealed partial class CargoSystem
if (!_emag.CheckFlag(ent, EmagType.Interaction))
{
var msg = Loc.GetString("cargo-console-fund-transfer-broadcast",
("name", tryGetIdentityShortInfoEvent.Title ?? Loc.GetString("cargo-console-fund-transfer-user-unknown")),
("name", name),
("amount", args.Amount),
("name1", Loc.GetString(ourAccount.Name)),
("code1", Loc.GetString(ourAccount.Code)),
@@ -8,7 +8,6 @@ using Content.Shared.Cargo.Events;
using Content.Shared.Cargo.Prototypes;
using Content.Shared.Database;
using Content.Shared.Emag.Systems;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Labels.Components;
using Content.Shared.Paper;
@@ -18,7 +17,6 @@ using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using Robust.Shared.Random;
namespace Content.Server.Cargo.Systems
{
@@ -234,9 +232,7 @@ namespace Content.Server.Cargo.Systems
if (!_emag.CheckFlag(uid, EmagType.Interaction))
{
var tryGetIdentityShortInfoEvent = new TryGetIdentityShortInfoEvent(uid, player);
RaiseLocalEvent(tryGetIdentityShortInfoEvent);
order.SetApproverData(tryGetIdentityShortInfoEvent.Title);
order.SetApproverData(_identity.GetIdentityShortInfo(player, uid));
var message = Loc.GetString("cargo-console-unlock-approved-order-broadcast",
("productName", Loc.GetString(product.Name)),
+3 -1
View File
@@ -1,14 +1,15 @@
using Content.Server.Cargo.Components;
using Content.Server.DeviceLinking.Systems;
using Content.Server.Popups;
using Content.Server.Radio.EntitySystems;
using Content.Server.Stack;
using Content.Server.Station.Systems;
using Content.Shared.Access.Systems;
using Content.Shared.Administration.Logs;
using Content.Server.Radio.EntitySystems;
using Content.Shared.Cargo;
using Content.Shared.Cargo.Components;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.IdentityManagement;
using Content.Shared.Mobs.Components;
using Content.Shared.Paper;
using Robust.Server.GameObjects;
@@ -39,6 +40,7 @@ public sealed partial class CargoSystem : SharedCargoSystem
[Dependency] private UserInterfaceSystem _uiSystem = default!;
[Dependency] private MetaDataSystem _metaSystem = default!;
[Dependency] private RadioSystem _radio = default!;
[Dependency] private IdentitySystem _identity = default!;
private EntityQuery<TransformComponent> _xformQuery;
private EntityQuery<CargoSellBlacklistComponent> _blacklistQuery;
@@ -35,6 +35,7 @@ namespace Content.Server.Communications
[Dependency] private UserInterfaceSystem _uiSystem = default!;
[Dependency] private IConfigurationManager _cfg = default!;
[Dependency] private IAdminLogManager _adminLogger = default!;
[Dependency] private IdentitySystem _identity = default!;
private const float UIUpdateInterval = 5.0f;
@@ -244,9 +245,7 @@ namespace Content.Server.Communications
return;
}
var tryGetIdentityShortInfoEvent = new TryGetIdentityShortInfoEvent(uid, mob);
RaiseLocalEvent(tryGetIdentityShortInfoEvent);
author = tryGetIdentityShortInfoEvent.Title;
author = _identity.GetIdentityShortInfo(mob, uid) ?? author;
}
comp.AnnouncementCooldownRemaining = comp.Delay;
@@ -33,6 +33,7 @@ public sealed partial class CriminalRecordsConsoleSystem : SharedCriminalRecords
[Dependency] private StationRecordsSystem _records = default!;
[Dependency] private StationSystem _station = default!;
[Dependency] private UserInterfaceSystem _ui = default!;
[Dependency] private IdentitySystem _identity = default!;
public override void Initialize()
{
@@ -79,13 +80,6 @@ public sealed partial class CriminalRecordsConsoleSystem : SharedCriminalRecords
}
}
private void GetOfficer(EntityUid uid, out string officer)
{
var tryGetIdentityShortInfoEvent = new TryGetIdentityShortInfoEvent(null, uid);
RaiseLocalEvent(tryGetIdentityShortInfoEvent);
officer = tryGetIdentityShortInfoEvent.Title ?? Loc.GetString("criminal-records-console-unknown-officer");
}
private void OnChangeStatus(Entity<CriminalRecordsConsoleComponent> ent, ref CriminalRecordChangeStatus msg)
{
// prevent malf client violating wanted/reason nullability
@@ -111,8 +105,8 @@ public sealed partial class CriminalRecordsConsoleSystem : SharedCriminalRecords
var oldStatus = record.Status;
var name = _records.RecordName(key.Value);
GetOfficer(mob.Value, out var officer);
var officer = _identity.GetIdentityShortInfo(mob.Value, ent)
?? Loc.GetString("criminal-records-console-unknown-officer");
// when arresting someone add it to history automatically
// fallback exists if the player was not set to wanted beforehand
@@ -124,19 +118,13 @@ public sealed partial class CriminalRecordsConsoleSystem : SharedCriminalRecords
}
// will probably never fail given the checks above
name = _records.RecordName(key.Value);
officer = Loc.GetString("criminal-records-console-unknown-officer");
var name = _records.RecordName(key.Value);
var jobName = "Unknown";
_records.TryGetRecord<GeneralStationRecord>(key.Value, out var entry);
if (entry != null)
jobName = entry.JobTitle;
var tryGetIdentityShortInfoEvent = new TryGetIdentityShortInfoEvent(null, mob.Value);
RaiseLocalEvent(tryGetIdentityShortInfoEvent);
if (tryGetIdentityShortInfoEvent.Title != null)
officer = tryGetIdentityShortInfoEvent.Title;
_criminalRecords.TryChangeStatus(key.Value, msg.Status, msg.Reason, officer);
(string, object)[] args;
@@ -192,7 +180,8 @@ public sealed partial class CriminalRecordsConsoleSystem : SharedCriminalRecords
if (line.Length < 1 || line.Length > ent.Comp.MaxStringLength)
return;
GetOfficer(mob.Value, out var officer);
var officer = _identity.GetIdentityShortInfo(mob.Value, ent)
?? Loc.GetString("criminal-records-console-unknown-officer");
if (!_criminalRecords.TryAddHistory(key.Value, line, officer))
return;
@@ -46,6 +46,7 @@ public sealed partial class NewsSystem : SharedNewsSystem
[Dependency] private DiscordWebhook _discord = default!;
[Dependency] private IConfigurationManager _cfg = default!;
[Dependency] private IBaseServer _baseServer = default!;
[Dependency] private IdentitySystem _identity = default!;
private WebhookIdentifier? _webhookId = null;
private Color _webhookEmbedColor;
@@ -170,9 +171,7 @@ public sealed partial class NewsSystem : SharedNewsSystem
ent.Comp.PublishEnabled = false;
ent.Comp.NextPublish = _timing.CurTime + TimeSpan.FromSeconds(ent.Comp.PublishCooldown);
var tryGetIdentityShortInfoEvent = new TryGetIdentityShortInfoEvent(ent, msg.Actor);
RaiseLocalEvent(tryGetIdentityShortInfoEvent);
string? authorName = tryGetIdentityShortInfoEvent.Title;
var authorName = _identity.GetIdentityShortInfo(msg.Actor, ent);
var title = msg.Title.Trim();
var content = msg.Content.Trim();
@@ -13,6 +13,7 @@ namespace Content.Server.Research.Systems;
public sealed partial class ResearchSystem
{
[Dependency] private EmagSystem _emag = default!;
[Dependency] private IdentitySystem _identity = default!;
private void InitializeConsole()
{
@@ -46,14 +47,12 @@ public sealed partial class ResearchSystem
if (!_emag.CheckFlag(uid, EmagType.Interaction))
{
var getIdentityEvent = new TryGetIdentityShortInfoEvent(uid, act);
RaiseLocalEvent(getIdentityEvent);
var message = Loc.GetString(
"research-console-unlock-technology-radio-broadcast",
("technology", Loc.GetString(technologyPrototype.Name)),
("amount", technologyPrototype.Cost),
("approver", getIdentityEvent.Title ?? string.Empty)
("approver", _identity.GetIdentityShortInfo(act, uid) ?? string.Empty)
);
_radio.SendRadioMessage(uid, message, component.AnnouncementChannel, uid, escapeMarkup: false);
}
@@ -34,6 +34,7 @@ public sealed partial class AccessReaderSystem : EntitySystem
[Dependency] private SharedHandsSystem _handsSystem = default!;
[Dependency] private SharedContainerSystem _containerSystem = default!;
[Dependency] private SharedStationRecordsSystem _recordsSystem = default!;
[Dependency] private IdentitySystem _identity = default!;
private static readonly ProtoId<TagPrototype> PreventAccessLoggingTag = "PreventAccessLogging";
@@ -920,12 +921,7 @@ public sealed partial class AccessReaderSystem : EntitySystem
// TODO pass the ID card on IsAllowed() instead of using this expensive method
// Set name if the accessor has a card and that card has a name and allows itself to be recorded
var getIdentityShortInfoEvent = new TryGetIdentityShortInfoEvent(ent, accessor, true);
RaiseLocalEvent(getIdentityShortInfoEvent);
if (getIdentityShortInfoEvent.Title != null)
{
name = getIdentityShortInfoEvent.Title;
}
name = _identity.GetIdentityShortInfo(accessor, ent, true) ?? name;
LogAccess(ent, name ?? Loc.GetString("access-reader-unknown-id"));
}
@@ -65,18 +65,13 @@ public abstract partial class SharedIdCardSystem : EntitySystem
private void OnTryGetIdentityShortInfo(TryGetIdentityShortInfoEvent ev)
{
if (ev.Handled)
{
return;
}
string? title = null;
if (TryFindIdCard(ev.ForActor, out var idCard) && !(ev.RequestForAccessLogging && idCard.Comp.BypassLogging))
if (TryFindIdCard(ev.Target, out var idCard) && !(ev.RequestForAccessLogging && idCard.Comp.BypassLogging))
{
title = ExtractFullTitle(idCard);
ev.Title = ExtractFullTitle(idCard);
ev.Handled = true;
}
ev.Title = title;
ev.Handled = true;
}
private void OnHandleState(Entity<IdCardComponent> ent, ref AfterAutoHandleStateEvent args)
@@ -9,9 +9,10 @@ using Content.Shared.Humanoid;
using Content.Shared.IdentityManagement.Components;
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Content.Shared.Verbs;
using Content.Shared.Preferences;
using Content.Shared.Verbs;
using Content.Shared.VoiceMask;
using JetBrains.Annotations;
using Robust.Shared.Containers;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects.Components.Localization;
@@ -283,6 +284,22 @@ public sealed partial class IdentitySystem : EntitySystem
}
#endregion
/// <summary>
/// Attempts to get a display name and ID title for the given entity.
/// For example "Urist McHands (Captain)" for players or "Robby (SI-123)" for silicons.
/// </summary>
/// <param name="target"> The entity to find the name for.</param>
/// <param name="whileInteractingWith"> The entity being used to request the target's name.</param>
/// <param name="forLogging"> For special IDs that don't leave behind a log trail; It compares to<c>IdCardComponent.BypassLogging</c>.</param> // TODO: This should not be here.
/// <returns> A string of the name and ID or null if no valid identity or no ID card was found.</returns>
[PublicAPI]
public string? GetIdentityShortInfo(EntityUid target, EntityUid? whileInteractingWith = null, bool forLogging = false)
{
var tryGetIdentityShortInfoEvent = new TryGetIdentityShortInfoEvent(target, whileInteractingWith, forLogging);
RaiseLocalEvent(target, tryGetIdentityShortInfoEvent, true);
return tryGetIdentityShortInfoEvent.Title;
}
}
/// <summary>
@@ -1,9 +1,10 @@
namespace Content.Shared.IdentityManagement;
/// <summary>
/// Event of attempt to collect actor full title - full name + job from id card for employee or entity name for borgs.
/// Event to collect a full title (full name + job from id card for employee or entity name for borgs).
/// For example "Urist McHands (Captain)" for players or "Robby (SI-123)" for silicons.
/// </summary>
public sealed class TryGetIdentityShortInfoEvent(EntityUid? whileInteractingWith, EntityUid forActor, bool forLogging = false) : HandledEntityEventArgs
public sealed class TryGetIdentityShortInfoEvent(EntityUid target, EntityUid? whileInteractingWith, bool forLogging) : HandledEntityEventArgs
{
/// <summary>
/// Full name of <see cref="ForActor"/>, with JobTitle.
@@ -12,21 +13,24 @@ public sealed class TryGetIdentityShortInfoEvent(EntityUid? whileInteractingWith
public string? Title;
/// <summary>
/// Entity for interacting with which title should be collected.
/// The entity that was used to get the name information.
/// Could be used to black-out name of people when announcing actions
/// on e-magged devices.
/// </summary>
public readonly EntityUid? WhileInteractingWith = whileInteractingWith;
/// <summary>
/// Actor for whom title should be collected.
/// The entity for which the name should be collected for.
/// </summary>
public readonly EntityUid ForActor = forActor;
public readonly EntityUid Target = target;
/// <summary>
/// Marker that title info was requested for access logging.
/// Is required as event handlers can determine, if they don't need
/// to place title info due to access logging restrictions.
/// </summary>
/// <remarks>
/// TODO: This should not be in here. Just check the id card used to access the access reader instead of making the event fail to get the info.
/// </remarks>
public readonly bool RequestForAccessLogging = forLogging;
}
@@ -75,7 +75,7 @@ public abstract partial class SharedBorgSystem : EntitySystem
InitializeRelay();
InitializeUI();
SubscribeLocalEvent<TryGetIdentityShortInfoEvent>(OnTryGetIdentityShortInfo);
SubscribeLocalEvent<BorgChassisComponent, TryGetIdentityShortInfoEvent>(OnTryGetIdentityShortInfo);
SubscribeLocalEvent<BorgChassisComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<BorgChassisComponent, MapInitEvent>(OnMapInit);
@@ -100,21 +100,12 @@ public abstract partial class SharedBorgSystem : EntitySystem
}
private void OnTryGetIdentityShortInfo(TryGetIdentityShortInfoEvent args)
private void OnTryGetIdentityShortInfo(Entity<BorgChassisComponent> chassis, ref TryGetIdentityShortInfoEvent args)
{
if (args.Handled)
{
return;
}
// TODO: Why the hell is this only broadcasted and not raised directed on the entity?
// This is doing a ton of HasComps/TryComps.
if (!HasComp<BorgChassisComponent>(args.ForActor))
{
return;
}
args.Title = Name(args.ForActor).Trim();
args.Title = Name(args.Target).Trim();
args.Handled = true;
}
@@ -15,9 +15,6 @@ public abstract partial class SharedStationAiSystem
* Added when an entity is inserted into a StationAiCore.
*/
//TODO: Fix this, please
private const string JobNameLocId = "job-name-station-ai";
private void InitializeHeld()
{
SubscribeLocalEvent<StationAiRadialMessage>(OnRadialMessage);
@@ -28,21 +25,15 @@ public abstract partial class SharedStationAiSystem
SubscribeLocalEvent<StationAiHeldComponent, AttemptRelayActionComponentChangeEvent>(OnHeldRelay);
SubscribeLocalEvent<StationAiHeldComponent, JumpToCoreEvent>(OnCoreJump);
SubscribeLocalEvent<TryGetIdentityShortInfoEvent>(OnTryGetIdentityShortInfo);
SubscribeLocalEvent<StationAiHeldComponent, TryGetIdentityShortInfoEvent>(OnTryGetIdentityShortInfo);
}
private void OnTryGetIdentityShortInfo(TryGetIdentityShortInfoEvent args)
private void OnTryGetIdentityShortInfo(Entity<StationAiHeldComponent> ent, ref TryGetIdentityShortInfoEvent args)
{
if (args.Handled)
{
return;
}
if (!HasComp<StationAiHeldComponent>(args.ForActor))
{
return;
}
args.Title = $"{Name(args.ForActor)} ({Loc.GetString(JobNameLocId)})";
args.Title = $"{Name(args.Target)} ({Loc.GetString("job-name-station-ai")})";
args.Handled = true;
}