]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
fix ninja hacking not affecting sechud (#28021)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Thu, 16 May 2024 20:51:06 +0000 (20:51 +0000)
committerGitHub <noreply@github.com>
Thu, 16 May 2024 20:51:06 +0000 (16:51 -0400)
minor refactor and fix

Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Client/CriminalRecords/Systems/CriminalRecordsConsoleSystem.cs
Content.Client/CriminalRecords/Systems/CriminalRecordsHackerSystem.cs
Content.Client/CriminalRecords/Systems/CriminalRecordsSystem.cs [new file with mode: 0644]
Content.Server/CriminalRecords/Systems/CriminalRecordsConsoleSystem.cs
Content.Server/CriminalRecords/Systems/CriminalRecordsHackerSystem.cs
Content.Server/CriminalRecords/Systems/CriminalRecordsSystem.cs
Content.Server/StationRecords/Systems/StationRecordsSystem.cs
Content.Shared/CriminalRecords/Systems/SharedCriminalRecordsConsoleSystem.cs
Content.Shared/CriminalRecords/Systems/SharedCriminalRecordsSystem.cs [new file with mode: 0644]

index 2a34376f6a69530506d1d8f13ea7591e2de2773b..4bf9d4c3e1c1ee47ba216704e3cf5220312d28d4 100644 (file)
@@ -2,6 +2,4 @@ using Content.Shared.CriminalRecords.Systems;
 
 namespace Content.Client.CriminalRecords.Systems;
 
-public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleSystem
-{
-}
+public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleSystem;
index 21fccc880daa73a553f55a907c1f3957da5d909d..c895a00c8873179c4a3d638c09fef30b920e2d17 100644 (file)
@@ -2,6 +2,4 @@ using Content.Shared.CriminalRecords.Systems;
 
 namespace Content.Client.CriminalRecords.Systems;
 
-public sealed class CriminalRecordsHackerSystem : SharedCriminalRecordsHackerSystem
-{
-}
+public sealed class CriminalRecordsHackerSystem : SharedCriminalRecordsHackerSystem;
diff --git a/Content.Client/CriminalRecords/Systems/CriminalRecordsSystem.cs b/Content.Client/CriminalRecords/Systems/CriminalRecordsSystem.cs
new file mode 100644 (file)
index 0000000..c0b98d7
--- /dev/null
@@ -0,0 +1,5 @@
+using Content.Shared.CriminalRecords.Systems;
+
+namespace Content.Client.CriminalRecords.Systems;
+
+public sealed class CriminalRecordsSystem : SharedCriminalRecordsSystem;
index 4389c68c0493cb1da461600578e1cb3a4fed2cf0..bbd402b9fad1c39bc4b883a2071384cddf667e3c 100644 (file)
@@ -27,7 +27,7 @@ public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleS
     [Dependency] private readonly PopupSystem _popup = default!;
     [Dependency] private readonly RadioSystem _radio = default!;
     [Dependency] private readonly SharedIdCardSystem _idCard = default!;
-    [Dependency] private readonly StationRecordsSystem _stationRecords = default!;
+    [Dependency] private readonly StationRecordsSystem _records = default!;
     [Dependency] private readonly StationSystem _station = default!;
     [Dependency] private readonly UserInterfaceSystem _ui = default!;
 
@@ -80,7 +80,7 @@ public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleS
         if (!CheckSelected(ent, msg.Actor, out var mob, out var key))
             return;
 
-        if (!_stationRecords.TryGetRecord<CriminalRecord>(key.Value, out var record) || record.Status == msg.Status)
+        if (!_records.TryGetRecord<CriminalRecord>(key.Value, out var record) || record.Status == msg.Status)
             return;
 
         // validate the reason
@@ -106,7 +106,7 @@ public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleS
         // will probably never fail given the checks above
         _criminalRecords.TryChangeStatus(key.Value, msg.Status, msg.Reason);
 
-        var name = RecordName(key.Value);
+        var name = _records.RecordName(key.Value);
         var officer = Loc.GetString("criminal-records-console-unknown-officer");
         if (_idCard.TryFindIdCard(mob.Value, out var id) && id.Comp.FullName is { } fullName)
             officer = fullName;
@@ -145,7 +145,6 @@ public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleS
             ent.Comp.SecurityChannel, ent);
 
         UpdateUserInterface(ent);
-        UpdateCriminalIdentity(name, msg.Status);
     }
 
     private void OnAddHistory(Entity<CriminalRecordsConsoleComponent> ent, ref CriminalRecordAddHistory msg)
@@ -189,15 +188,15 @@ public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleS
             return;
         }
 
-        var listing = _stationRecords.BuildListing((owningStation.Value, stationRecords), console.Filter);
+        var listing = _records.BuildListing((owningStation.Value, stationRecords), console.Filter);
 
         var state = new CriminalRecordsConsoleState(listing, console.Filter);
         if (console.ActiveKey is { } id)
         {
             // get records to display when a crewmember is selected
             var key = new StationRecordKey(id, owningStation.Value);
-            _stationRecords.TryGetRecord(key, out state.StationRecord, stationRecords);
-            _stationRecords.TryGetRecord(key, out state.CriminalRecord, stationRecords);
+            _records.TryGetRecord(key, out state.StationRecord, stationRecords);
+            _records.TryGetRecord(key, out state.CriminalRecord, stationRecords);
             state.SelectedKey = id;
         }
 
@@ -232,17 +231,6 @@ public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleS
         return true;
     }
 
-    /// <summary>
-    /// Gets the name from a record, or empty string if this somehow fails.
-    /// </summary>
-    private string RecordName(StationRecordKey key)
-    {
-        if (!_stationRecords.TryGetRecord<GeneralStationRecord>(key, out var record))
-            return "";
-
-        return record.Name;
-    }
-
     /// <summary>
     /// Checks if the new identity's name has a criminal record attached to it, and gives the entity the icon that
     /// belongs to the status if it does.
@@ -255,14 +243,14 @@ public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleS
         // TODO use the entity's station? Not the station of the map that it happens to currently be on?
         var station = _station.GetStationInMap(xform.MapID);
 
-        if (station != null && _stationRecords.GetRecordByName(station.Value, name) is { } id)
+        if (station != null && _records.GetRecordByName(station.Value, name) is { } id)
         {
-            if (_stationRecords.TryGetRecord<CriminalRecord>(new StationRecordKey(id, station.Value),
+            if (_records.TryGetRecord<CriminalRecord>(new StationRecordKey(id, station.Value),
                     out var record))
             {
                 if (record.Status != SecurityStatus.None)
                 {
-                    SetCriminalIcon(name, record.Status, uid);
+                    _criminalRecords.SetCriminalIcon(name, record.Status, uid);
                     return;
                 }
             }
index 91285a1ca73eb8efa362cc7c82eaaed1656500f6..b0181a0adc0855f983ec46c0d19b208242885762 100644 (file)
@@ -6,6 +6,7 @@ using Content.Shared.CriminalRecords.Components;
 using Content.Shared.CriminalRecords.Systems;
 using Content.Shared.Dataset;
 using Content.Shared.Security;
+using Content.Shared.StationRecords;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
 
@@ -14,6 +15,7 @@ namespace Content.Server.CriminalRecords.Systems;
 public sealed class CriminalRecordsHackerSystem : SharedCriminalRecordsHackerSystem
 {
     [Dependency] private readonly ChatSystem _chat = default!;
+    [Dependency] private readonly CriminalRecordsSystem _criminalRecords = default!;
     [Dependency] private readonly IPrototypeManager _proto = default!;
     [Dependency] private readonly IRobustRandom _random = default!;
     [Dependency] private readonly StationSystem _station = default!;
@@ -38,8 +40,7 @@ public sealed class CriminalRecordsHackerSystem : SharedCriminalRecordsHackerSys
         foreach (var (key, record) in _records.GetRecordsOfType<CriminalRecord>(station))
         {
             var reason = _random.Pick(reasons.Values);
-            record.Status = SecurityStatus.Wanted;
-            record.Reason = reason;
+            _criminalRecords.OverwriteStatus(new StationRecordKey(key, station), record, SecurityStatus.Wanted, reason);
             // no radio message since spam
             // no history since lazy and its easy to remove anyway
             // main damage with this is existing arrest warrants are lost and to anger beepsky
index 9ffe94448674647a9cf33ad2ca06fcea6ff65a69..a65fb0be9e1a7021ce32218eff2089aa96b83f28 100644 (file)
@@ -1,6 +1,7 @@
 using System.Diagnostics.CodeAnalysis;
 using Content.Server.StationRecords.Systems;
 using Content.Shared.CriminalRecords;
+using Content.Shared.CriminalRecords.Systems;
 using Content.Shared.Security;
 using Content.Shared.StationRecords;
 using Content.Server.GameTicking;
@@ -15,10 +16,10 @@ namespace Content.Server.CriminalRecords.Systems;
 ///         - See security officers' actions in Criminal Records in the radio
 ///         - See reasons for any action with no need to ask the officer personally
 /// </summary>
-public sealed class CriminalRecordsSystem : EntitySystem
+public sealed class CriminalRecordsSystem : SharedCriminalRecordsSystem
 {
     [Dependency] private readonly GameTicker _ticker = default!;
-    [Dependency] private readonly StationRecordsSystem _stationRecords = default!;
+    [Dependency] private readonly StationRecordsSystem _records = default!;
 
     public override void Initialize()
     {
@@ -29,28 +30,40 @@ public sealed class CriminalRecordsSystem : EntitySystem
 
     private void OnGeneralRecordCreated(AfterGeneralRecordCreatedEvent ev)
     {
-        _stationRecords.AddRecordEntry(ev.Key, new CriminalRecord());
-        _stationRecords.Synchronize(ev.Key);
+        _records.AddRecordEntry(ev.Key, new CriminalRecord());
+        _records.Synchronize(ev.Key);
     }
 
     /// <summary>
     /// Tries to change the status of the record found by the StationRecordKey.
-    /// Reason should only be passed if status is Wanted.
+    /// Reason should only be passed if status is Wanted, nullability isn't checked.
     /// </summary>
     /// <returns>True if the status is changed, false if not</returns>
     public bool TryChangeStatus(StationRecordKey key, SecurityStatus status, string? reason)
     {
         // don't do anything if its the same status
-        if (!_stationRecords.TryGetRecord<CriminalRecord>(key, out var record)
+        if (!_records.TryGetRecord<CriminalRecord>(key, out var record)
             || status == record.Status)
             return false;
 
+        OverwriteStatus(key, record, status, reason);
+
+        return true;
+    }
+
+    /// <summary>
+    /// Sets the status without checking previous status or reason nullability.
+    /// </summary>
+    public void OverwriteStatus(StationRecordKey key, CriminalRecord record, SecurityStatus status, string? reason)
+    {
         record.Status = status;
         record.Reason = reason;
 
-        _stationRecords.Synchronize(key);
+        var name = _records.RecordName(key);
+        if (name != string.Empty)
+            UpdateCriminalIdentity(name, status);
 
-        return true;
+        _records.Synchronize(key);
     }
 
     /// <summary>
@@ -59,7 +72,7 @@ public sealed class CriminalRecordsSystem : EntitySystem
     /// <returns>True if adding succeeded, false if not</returns>
     public bool TryAddHistory(StationRecordKey key, CrimeHistory entry)
     {
-        if (!_stationRecords.TryGetRecord<CriminalRecord>(key, out var record))
+        if (!_records.TryGetRecord<CriminalRecord>(key, out var record))
             return false;
 
         record.History.Add(entry);
@@ -81,7 +94,7 @@ public sealed class CriminalRecordsSystem : EntitySystem
     /// <returns>True if the line was removed, false if not</returns>
     public bool TryDeleteHistory(StationRecordKey key, uint index)
     {
-        if (!_stationRecords.TryGetRecord<CriminalRecord>(key, out var record))
+        if (!_records.TryGetRecord<CriminalRecord>(key, out var record))
             return false;
 
         if (index >= record.History.Count)
index 58c4c876c508daf69f45c1b1ace8452015104531..8c8ba7132bb54d6823d30a2ec897c39fa384c8df 100644 (file)
@@ -223,6 +223,17 @@ public sealed class StationRecordsSystem : SharedStationRecordsSystem
         return null;
     }
 
+    /// <summary>
+    /// Get the name for a record, or an empty string if it has no record.
+    /// </summary>
+    public string RecordName(StationRecordKey key)
+    {
+        if (!TryGetRecord<GeneralStationRecord>(key, out var record))
+           return string.Empty;
+
+        return record.Name;
+    }
+
     /// <summary>
     ///     Gets all records of a specific type from a station.
     /// </summary>
index 6c51cb77acc4bfa06e4b0fa4027bbad41830e4b3..d3d366ecf95d102a09e1acb1233fdf589d2a8736 100644 (file)
@@ -1,52 +1,6 @@
-using Content.Shared.IdentityManagement;
-using Content.Shared.IdentityManagement.Components;
-using Content.Shared.Security;
-using Content.Shared.Security.Components;
-
 namespace Content.Shared.CriminalRecords.Systems;
 
-public abstract class SharedCriminalRecordsConsoleSystem : EntitySystem
-{
-    /// <summary>
-    /// Any entity that has a the name of the record that was just changed as their visible name will get their icon
-    /// updated with the new status, if the record got removed their icon will be removed too.
-    /// </summary>
-    public void UpdateCriminalIdentity(string name, SecurityStatus status)
-    {
-        var query = EntityQueryEnumerator<IdentityComponent>();
-
-        while (query.MoveNext(out var uid, out var identity))
-        {
-            if (!Identity.Name(uid, EntityManager).Equals(name))
-                continue;
-
-            if (status == SecurityStatus.None)
-                RemComp<CriminalRecordComponent>(uid);
-            else
-                SetCriminalIcon(name, status, uid);
-        }
-    }
-
-    /// <summary>
-    /// Decides the icon that should be displayed on the entity based on the security status
-    /// </summary>
-    public void SetCriminalIcon(string name, SecurityStatus status, EntityUid characterUid)
-    {
-        EnsureComp<CriminalRecordComponent>(characterUid, out var record);
-
-        var previousIcon = record.StatusIcon;
-
-        record.StatusIcon = status switch
-        {
-            SecurityStatus.Paroled => "SecurityIconParoled",
-            SecurityStatus.Wanted => "SecurityIconWanted",
-            SecurityStatus.Detained => "SecurityIconIncarcerated",
-            SecurityStatus.Discharged => "SecurityIconDischarged",
-            SecurityStatus.Suspected => "SecurityIconSuspected",
-            _ => record.StatusIcon
-        };
-
-        if(previousIcon != record.StatusIcon)
-            Dirty(characterUid, record);
-    }
-}
+/// <summary>
+/// Station records aren't predicted, just exists for access.
+/// </summary>
+public abstract class SharedCriminalRecordsConsoleSystem : EntitySystem;
diff --git a/Content.Shared/CriminalRecords/Systems/SharedCriminalRecordsSystem.cs b/Content.Shared/CriminalRecords/Systems/SharedCriminalRecordsSystem.cs
new file mode 100644 (file)
index 0000000..96b33ab
--- /dev/null
@@ -0,0 +1,52 @@
+using Content.Shared.IdentityManagement;
+using Content.Shared.IdentityManagement.Components;
+using Content.Shared.Security;
+using Content.Shared.Security.Components;
+
+namespace Content.Shared.CriminalRecords.Systems;
+
+public abstract class SharedCriminalRecordsSystem : EntitySystem
+{
+    /// <summary>
+    /// Any entity that has a the name of the record that was just changed as their visible name will get their icon
+    /// updated with the new status, if the record got removed their icon will be removed too.
+    /// </summary>
+    public void UpdateCriminalIdentity(string name, SecurityStatus status)
+    {
+        var query = EntityQueryEnumerator<IdentityComponent>();
+
+        while (query.MoveNext(out var uid, out var identity))
+        {
+            if (!Identity.Name(uid, EntityManager).Equals(name))
+                continue;
+
+            if (status == SecurityStatus.None)
+                RemComp<CriminalRecordComponent>(uid);
+            else
+                SetCriminalIcon(name, status, uid);
+        }
+    }
+
+    /// <summary>
+    /// Decides the icon that should be displayed on the entity based on the security status
+    /// </summary>
+    public void SetCriminalIcon(string name, SecurityStatus status, EntityUid characterUid)
+    {
+        EnsureComp<CriminalRecordComponent>(characterUid, out var record);
+
+        var previousIcon = record.StatusIcon;
+
+        record.StatusIcon = status switch
+        {
+            SecurityStatus.Paroled => "SecurityIconParoled",
+            SecurityStatus.Wanted => "SecurityIconWanted",
+            SecurityStatus.Detained => "SecurityIconIncarcerated",
+            SecurityStatus.Discharged => "SecurityIconDischarged",
+            SecurityStatus.Suspected => "SecurityIconSuspected",
+            _ => record.StatusIcon
+        };
+
+        if (previousIcon != record.StatusIcon)
+            Dirty(characterUid, record);
+    }
+}