diff --git a/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs b/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs index 8ed7388947..4feb2afcc7 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs @@ -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 diff --git a/Content.Server/Cargo/Systems/CargoSystem.Funds.cs b/Content.Server/Cargo/Systems/CargoSystem.Funds.cs index bc6571c0cc..10ddcdb54f 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Funds.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Funds.cs @@ -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)), diff --git a/Content.Server/Cargo/Systems/CargoSystem.Orders.cs b/Content.Server/Cargo/Systems/CargoSystem.Orders.cs index 50aefd4572..c6d9af1d8f 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Orders.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Orders.cs @@ -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)), diff --git a/Content.Server/Cargo/Systems/CargoSystem.cs b/Content.Server/Cargo/Systems/CargoSystem.cs index df7e6eda3d..cdf8e2102d 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.cs @@ -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 _xformQuery; private EntityQuery _blacklistQuery; diff --git a/Content.Server/Communications/CommunicationsConsoleSystem.cs b/Content.Server/Communications/CommunicationsConsoleSystem.cs index 3fed807d20..e9b97ab95c 100644 --- a/Content.Server/Communications/CommunicationsConsoleSystem.cs +++ b/Content.Server/Communications/CommunicationsConsoleSystem.cs @@ -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; diff --git a/Content.Server/CriminalRecords/Systems/CriminalRecordsConsoleSystem.cs b/Content.Server/CriminalRecords/Systems/CriminalRecordsConsoleSystem.cs index 8fadeb3c21..94a9f7bfe4 100644 --- a/Content.Server/CriminalRecords/Systems/CriminalRecordsConsoleSystem.cs +++ b/Content.Server/CriminalRecords/Systems/CriminalRecordsConsoleSystem.cs @@ -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 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(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; diff --git a/Content.Server/MassMedia/Systems/NewsSystem.cs b/Content.Server/MassMedia/Systems/NewsSystem.cs index 8834be3848..e0c27105ff 100644 --- a/Content.Server/MassMedia/Systems/NewsSystem.cs +++ b/Content.Server/MassMedia/Systems/NewsSystem.cs @@ -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(); diff --git a/Content.Server/Research/Systems/ResearchSystem.Console.cs b/Content.Server/Research/Systems/ResearchSystem.Console.cs index ee83ee7c95..559bd573e1 100644 --- a/Content.Server/Research/Systems/ResearchSystem.Console.cs +++ b/Content.Server/Research/Systems/ResearchSystem.Console.cs @@ -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); } diff --git a/Content.Shared/Access/Systems/AccessReaderSystem.cs b/Content.Shared/Access/Systems/AccessReaderSystem.cs index 08920dea1b..0ad75e7361 100644 --- a/Content.Shared/Access/Systems/AccessReaderSystem.cs +++ b/Content.Shared/Access/Systems/AccessReaderSystem.cs @@ -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 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")); } diff --git a/Content.Shared/Access/Systems/SharedIdCardSystem.cs b/Content.Shared/Access/Systems/SharedIdCardSystem.cs index 5d5d261bc8..d93ee618cc 100644 --- a/Content.Shared/Access/Systems/SharedIdCardSystem.cs +++ b/Content.Shared/Access/Systems/SharedIdCardSystem.cs @@ -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 ent, ref AfterAutoHandleStateEvent args) diff --git a/Content.Shared/IdentityManagement/IdentitySystem.cs b/Content.Shared/IdentityManagement/IdentitySystem.cs index af3b73a948..af779a95d7 100644 --- a/Content.Shared/IdentityManagement/IdentitySystem.cs +++ b/Content.Shared/IdentityManagement/IdentitySystem.cs @@ -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 + + /// + /// 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. + /// + /// The entity to find the name for. + /// The entity being used to request the target's name. + /// For special IDs that don't leave behind a log trail; It compares toIdCardComponent.BypassLogging. // TODO: This should not be here. + /// A string of the name and ID or null if no valid identity or no ID card was found. + [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; + } } /// diff --git a/Content.Shared/IdentityManagement/TryGetIdentityShortInfoEvent.cs b/Content.Shared/IdentityManagement/TryGetIdentityShortInfoEvent.cs index 1303896e7b..38e6487f1e 100644 --- a/Content.Shared/IdentityManagement/TryGetIdentityShortInfoEvent.cs +++ b/Content.Shared/IdentityManagement/TryGetIdentityShortInfoEvent.cs @@ -1,9 +1,10 @@ namespace Content.Shared.IdentityManagement; /// -/// 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. /// -public sealed class TryGetIdentityShortInfoEvent(EntityUid? whileInteractingWith, EntityUid forActor, bool forLogging = false) : HandledEntityEventArgs +public sealed class TryGetIdentityShortInfoEvent(EntityUid target, EntityUid? whileInteractingWith, bool forLogging) : HandledEntityEventArgs { /// /// Full name of , with JobTitle. @@ -12,21 +13,24 @@ public sealed class TryGetIdentityShortInfoEvent(EntityUid? whileInteractingWith public string? Title; /// - /// 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. /// public readonly EntityUid? WhileInteractingWith = whileInteractingWith; /// - /// Actor for whom title should be collected. + /// The entity for which the name should be collected for. /// - public readonly EntityUid ForActor = forActor; + public readonly EntityUid Target = target; /// /// 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. /// + /// + /// 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. + /// public readonly bool RequestForAccessLogging = forLogging; } diff --git a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs index cf4bb95b61..f87767492e 100644 --- a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs +++ b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs @@ -75,7 +75,7 @@ public abstract partial class SharedBorgSystem : EntitySystem InitializeRelay(); InitializeUI(); - SubscribeLocalEvent(OnTryGetIdentityShortInfo); + SubscribeLocalEvent(OnTryGetIdentityShortInfo); SubscribeLocalEvent(OnStartup); SubscribeLocalEvent(OnMapInit); @@ -100,21 +100,12 @@ public abstract partial class SharedBorgSystem : EntitySystem } - private void OnTryGetIdentityShortInfo(TryGetIdentityShortInfoEvent args) + private void OnTryGetIdentityShortInfo(Entity 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(args.ForActor)) - { - return; - } - - args.Title = Name(args.ForActor).Trim(); + args.Title = Name(args.Target).Trim(); args.Handled = true; } diff --git a/Content.Shared/Silicons/StationAi/SharedStationAiSystem.Held.cs b/Content.Shared/Silicons/StationAi/SharedStationAiSystem.Held.cs index 91dd61d334..d966376c25 100644 --- a/Content.Shared/Silicons/StationAi/SharedStationAiSystem.Held.cs +++ b/Content.Shared/Silicons/StationAi/SharedStationAiSystem.Held.cs @@ -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(OnRadialMessage); @@ -28,21 +25,15 @@ public abstract partial class SharedStationAiSystem SubscribeLocalEvent(OnHeldRelay); SubscribeLocalEvent(OnCoreJump); - SubscribeLocalEvent(OnTryGetIdentityShortInfo); + SubscribeLocalEvent(OnTryGetIdentityShortInfo); } - private void OnTryGetIdentityShortInfo(TryGetIdentityShortInfoEvent args) + private void OnTryGetIdentityShortInfo(Entity ent, ref TryGetIdentityShortInfoEvent args) { if (args.Handled) - { return; - } - if (!HasComp(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; }