Skip to content

Commit

Permalink
now using event to check access to fingerprint
Browse files Browse the repository at this point in the history
  • Loading branch information
YourUsername committed Sep 5, 2024
1 parent 1335a11 commit 2423f17
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
20 changes: 20 additions & 0 deletions Content.Server/Forensics/Systems/FingerprintMaskSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Content.Shared.Forensics;
using Content.Shared.Inventory;

namespace Content.Server.Forensics;

public sealed class FingerprintMaskSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<FingerprintMaskComponent, InventoryRelayedEvent<TryAccessFingerprintEvent>>(OnTryAccessFingerprint);
}

private void OnTryAccessFingerprint(EntityUid uid, FingerprintMaskComponent comp, ref InventoryRelayedEvent<TryAccessFingerprintEvent> args)
{
args.Args.Blocker = uid;
args.Args.Cancel();
}
}
10 changes: 8 additions & 2 deletions Content.Server/Forensics/Systems/ForensicPadSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public sealed class ForensicPadSystem : EntitySystem
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly ForensicsSystem _forensics = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -56,9 +57,14 @@ private void OnAfterInteract(EntityUid uid, ForensicPadComponent component, Afte
return;
}

if (_inventory.TryGetSlotEntity(args.Target.Value, "gloves", out var gloves))
if (!_forensics.CanAccessFingerprint(args.Target.Value, out var blocker))
{
_popupSystem.PopupEntity(Loc.GetString("forensic-pad-gloves", ("target", Identity.Entity(args.Target.Value, EntityManager))), args.Target.Value, args.User);

if (blocker is { } item)
_popupSystem.PopupEntity(Loc.GetString("forensic-pad-no-access-due", ("entity", Identity.Entity(item, EntityManager))), args.Target.Value, args.User);
else
_popupSystem.PopupEntity(Loc.GetString("forensic-pad-no-access"), args.Target.Value, args.User);

return;
}

Expand Down
23 changes: 19 additions & 4 deletions Content.Server/Forensics/Systems/ForensicsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,9 @@ private void ApplyEvidence(EntityUid user, EntityUid target)
{
if (TryComp<FiberComponent>(gloves, out var fiber) && !string.IsNullOrEmpty(fiber.FiberMaterial))
component.Fibers.Add(string.IsNullOrEmpty(fiber.FiberColor) ? Loc.GetString("forensic-fibers", ("material", fiber.FiberMaterial)) : Loc.GetString("forensic-fibers-colored", ("color", fiber.FiberColor), ("material", fiber.FiberMaterial)));

if (HasComp<FingerprintMaskComponent>(gloves))
return;
}
if (TryComp<FingerprintComponent>(user, out var fingerprint))

if (TryComp<FingerprintComponent>(user, out var fingerprint) && CanAccessFingerprint(user, out var _))
component.Fingerprints.Add(fingerprint.Fingerprint ?? "");
}

Expand Down Expand Up @@ -322,6 +320,23 @@ public void TransferDna(EntityUid recipient, EntityUid donor, bool canDnaBeClean
}
}

/// <summary>
/// Checks if there's an access to the fingerprint of the target entity.
/// </summary>
/// <param name="target">The entity with the fingerprint</param>
/// <param name="blocker">The entity that blocked accessing the fingerprint</param>
public bool CanAccessFingerprint(EntityUid target, out EntityUid? blocker)
{
var ev = new TryAccessFingerprintEvent();

RaiseLocalEvent(target, ev);
if (!ev.Cancelled && TryComp<InventoryComponent>(target, out var inv))
_inventory.RelayEvent((target, inv), ev);

blocker = ev.Blocker;
return !ev.Cancelled;
}

#endregion
}
}
11 changes: 11 additions & 0 deletions Content.Shared/Forensics/Events.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared.DoAfter;
using Content.Shared.Inventory;
using Robust.Shared.Serialization;

namespace Content.Shared.Forensics;
Expand Down Expand Up @@ -68,3 +69,13 @@ public record struct GenerateDnaEvent()
/// </summary>
public string DNA;
}

/// <summary>
/// An event to check if the fingerprint is accessible.
/// </summary>
public sealed class TryAccessFingerprintEvent : CancellableEntityEventArgs, IInventoryRelayEvent
{
SlotFlags IInventoryRelayEvent.TargetSlots => ~SlotFlags.POCKET;

public EntityUid? Blocker;
}
3 changes: 2 additions & 1 deletion Resources/Locale/en-US/forensics/forensics.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ forensic-scanner-interface-clear = Clear
forensic-scanner-report-title = Forensics Report: {$entity}
forensic-pad-unused = It hasn't been used.
forensic-pad-sample = It has a sample: {$sample}
forensic-pad-gloves = {CAPITALIZE($target)} is wearing gloves.
forensic-pad-no-access-due = Can't access the fingerprint due to {THE($entity)}.
forensic-pad-no-access = Can't access the fingerprint.
forensic-pad-start-scan-target = {CAPITALIZE($user)} is trying to take a sample of your fingerprints.
forensic-pad-start-scan-user = You start taking a sample of {CAPITALIZE($target)}'s fingerprints.
forensic-pad-already-used = This pad has already been used.
Expand Down

0 comments on commit 2423f17

Please sign in to comment.