From: deltanedas <39013340+deltanedas@users.noreply.github.com> Date: Thu, 16 May 2024 20:51:06 +0000 (+0000) Subject: fix ninja hacking not affecting sechud (#28021) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=b453b9414810ed927228eb563c6b1c491532c5e3;p=space-station-14.git fix ninja hacking not affecting sechud (#28021) minor refactor and fix Co-authored-by: deltanedas <@deltanedas:kde.org> --- diff --git a/Content.Client/CriminalRecords/Systems/CriminalRecordsConsoleSystem.cs b/Content.Client/CriminalRecords/Systems/CriminalRecordsConsoleSystem.cs index 2a34376f6a..4bf9d4c3e1 100644 --- a/Content.Client/CriminalRecords/Systems/CriminalRecordsConsoleSystem.cs +++ b/Content.Client/CriminalRecords/Systems/CriminalRecordsConsoleSystem.cs @@ -2,6 +2,4 @@ using Content.Shared.CriminalRecords.Systems; namespace Content.Client.CriminalRecords.Systems; -public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleSystem -{ -} +public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleSystem; diff --git a/Content.Client/CriminalRecords/Systems/CriminalRecordsHackerSystem.cs b/Content.Client/CriminalRecords/Systems/CriminalRecordsHackerSystem.cs index 21fccc880d..c895a00c88 100644 --- a/Content.Client/CriminalRecords/Systems/CriminalRecordsHackerSystem.cs +++ b/Content.Client/CriminalRecords/Systems/CriminalRecordsHackerSystem.cs @@ -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 index 0000000000..c0b98d7ce3 --- /dev/null +++ b/Content.Client/CriminalRecords/Systems/CriminalRecordsSystem.cs @@ -0,0 +1,5 @@ +using Content.Shared.CriminalRecords.Systems; + +namespace Content.Client.CriminalRecords.Systems; + +public sealed class CriminalRecordsSystem : SharedCriminalRecordsSystem; diff --git a/Content.Server/CriminalRecords/Systems/CriminalRecordsConsoleSystem.cs b/Content.Server/CriminalRecords/Systems/CriminalRecordsConsoleSystem.cs index 4389c68c04..bbd402b9fa 100644 --- a/Content.Server/CriminalRecords/Systems/CriminalRecordsConsoleSystem.cs +++ b/Content.Server/CriminalRecords/Systems/CriminalRecordsConsoleSystem.cs @@ -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(key.Value, out var record) || record.Status == msg.Status) + if (!_records.TryGetRecord(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 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; } - /// - /// Gets the name from a record, or empty string if this somehow fails. - /// - private string RecordName(StationRecordKey key) - { - if (!_stationRecords.TryGetRecord(key, out var record)) - return ""; - - return record.Name; - } - /// /// 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(new StationRecordKey(id, station.Value), + if (_records.TryGetRecord(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; } } diff --git a/Content.Server/CriminalRecords/Systems/CriminalRecordsHackerSystem.cs b/Content.Server/CriminalRecords/Systems/CriminalRecordsHackerSystem.cs index 91285a1ca7..b0181a0adc 100644 --- a/Content.Server/CriminalRecords/Systems/CriminalRecordsHackerSystem.cs +++ b/Content.Server/CriminalRecords/Systems/CriminalRecordsHackerSystem.cs @@ -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(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 diff --git a/Content.Server/CriminalRecords/Systems/CriminalRecordsSystem.cs b/Content.Server/CriminalRecords/Systems/CriminalRecordsSystem.cs index 9ffe944486..a65fb0be9e 100644 --- a/Content.Server/CriminalRecords/Systems/CriminalRecordsSystem.cs +++ b/Content.Server/CriminalRecords/Systems/CriminalRecordsSystem.cs @@ -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 /// -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); } /// /// 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. /// /// True if the status is changed, false if not public bool TryChangeStatus(StationRecordKey key, SecurityStatus status, string? reason) { // don't do anything if its the same status - if (!_stationRecords.TryGetRecord(key, out var record) + if (!_records.TryGetRecord(key, out var record) || status == record.Status) return false; + OverwriteStatus(key, record, status, reason); + + return true; + } + + /// + /// Sets the status without checking previous status or reason nullability. + /// + 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); } /// @@ -59,7 +72,7 @@ public sealed class CriminalRecordsSystem : EntitySystem /// True if adding succeeded, false if not public bool TryAddHistory(StationRecordKey key, CrimeHistory entry) { - if (!_stationRecords.TryGetRecord(key, out var record)) + if (!_records.TryGetRecord(key, out var record)) return false; record.History.Add(entry); @@ -81,7 +94,7 @@ public sealed class CriminalRecordsSystem : EntitySystem /// True if the line was removed, false if not public bool TryDeleteHistory(StationRecordKey key, uint index) { - if (!_stationRecords.TryGetRecord(key, out var record)) + if (!_records.TryGetRecord(key, out var record)) return false; if (index >= record.History.Count) diff --git a/Content.Server/StationRecords/Systems/StationRecordsSystem.cs b/Content.Server/StationRecords/Systems/StationRecordsSystem.cs index 58c4c876c5..8c8ba7132b 100644 --- a/Content.Server/StationRecords/Systems/StationRecordsSystem.cs +++ b/Content.Server/StationRecords/Systems/StationRecordsSystem.cs @@ -223,6 +223,17 @@ public sealed class StationRecordsSystem : SharedStationRecordsSystem return null; } + /// + /// Get the name for a record, or an empty string if it has no record. + /// + public string RecordName(StationRecordKey key) + { + if (!TryGetRecord(key, out var record)) + return string.Empty; + + return record.Name; + } + /// /// Gets all records of a specific type from a station. /// diff --git a/Content.Shared/CriminalRecords/Systems/SharedCriminalRecordsConsoleSystem.cs b/Content.Shared/CriminalRecords/Systems/SharedCriminalRecordsConsoleSystem.cs index 6c51cb77ac..d3d366ecf9 100644 --- a/Content.Shared/CriminalRecords/Systems/SharedCriminalRecordsConsoleSystem.cs +++ b/Content.Shared/CriminalRecords/Systems/SharedCriminalRecordsConsoleSystem.cs @@ -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 -{ - /// - /// 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. - /// - public void UpdateCriminalIdentity(string name, SecurityStatus status) - { - var query = EntityQueryEnumerator(); - - while (query.MoveNext(out var uid, out var identity)) - { - if (!Identity.Name(uid, EntityManager).Equals(name)) - continue; - - if (status == SecurityStatus.None) - RemComp(uid); - else - SetCriminalIcon(name, status, uid); - } - } - - /// - /// Decides the icon that should be displayed on the entity based on the security status - /// - public void SetCriminalIcon(string name, SecurityStatus status, EntityUid characterUid) - { - EnsureComp(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); - } -} +/// +/// Station records aren't predicted, just exists for access. +/// +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 index 0000000000..96b33ab91b --- /dev/null +++ b/Content.Shared/CriminalRecords/Systems/SharedCriminalRecordsSystem.cs @@ -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 +{ + /// + /// 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. + /// + public void UpdateCriminalIdentity(string name, SecurityStatus status) + { + var query = EntityQueryEnumerator(); + + while (query.MoveNext(out var uid, out var identity)) + { + if (!Identity.Name(uid, EntityManager).Equals(name)) + continue; + + if (status == SecurityStatus.None) + RemComp(uid); + else + SetCriminalIcon(name, status, uid); + } + } + + /// + /// Decides the icon that should be displayed on the entity based on the security status + /// + public void SetCriminalIcon(string name, SecurityStatus status, EntityUid characterUid) + { + EnsureComp(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); + } +}