diff --git a/Content.Server/DeviceNetwork/Systems/NetworkConfiguratorSystem.cs b/Content.Server/DeviceNetwork/Systems/NetworkConfiguratorSystem.cs index 63b9c11374..61567adb65 100644 --- a/Content.Server/DeviceNetwork/Systems/NetworkConfiguratorSystem.cs +++ b/Content.Server/DeviceNetwork/Systems/NetworkConfiguratorSystem.cs @@ -1,4 +1,5 @@ using System.Linq; +using Content.Server.Administration.Logs; using Content.Server.DeviceLinking.Systems; using Content.Server.DeviceNetwork.Components; using Content.Server.UserInterface; @@ -33,6 +34,7 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem [Dependency] private readonly AudioSystem _audioSystem = default!; [Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; + [Dependency] private readonly IAdminLogManager _adminLogger = default!; public override void Initialize() { @@ -133,7 +135,10 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem _popupSystem.PopupCursor(Loc.GetString("network-configurator-device-saved", ("address", device.Address), ("device", targetUid)), userUid, PopupType.Medium); - UpdateListUiState(configurator.Owner, configurator); + var configuratorUid = configurator.Owner; + _adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, $"{ToPrettyString(userUid):actor} saved {ToPrettyString(targetUid.Value):subject} to {ToPrettyString(configuratorUid):tool}"); + + UpdateListUiState(configuratorUid, configurator); } private void TryLinkDevice(EntityUid uid, NetworkConfiguratorComponent configurator, EntityUid? target, EntityUid user) @@ -521,6 +526,9 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem /// private void OnRemoveDevice(EntityUid uid, NetworkConfiguratorComponent component, NetworkConfiguratorRemoveDeviceMessage args) { + if (component.Devices.TryGetValue(args.Address, out var removedDevice) && args.Session.AttachedEntity != null) + _adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, + $"{ToPrettyString(args.Session.AttachedEntity.Value):actor} removed buffered device {ToPrettyString(removedDevice):subject} from {ToPrettyString(uid):tool}"); component.Devices.Remove(args.Address); UpdateListUiState(uid, component); } @@ -528,8 +536,11 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem /// /// Clears the saved devices /// - private void OnClearDevice(EntityUid uid, NetworkConfiguratorComponent component, NetworkConfiguratorClearDevicesMessage _) + private void OnClearDevice(EntityUid uid, NetworkConfiguratorComponent component, NetworkConfiguratorClearDevicesMessage args) { + if (args.Session.AttachedEntity != null) + _adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, + $"{ToPrettyString(args.Session.AttachedEntity.Value):actor} cleared buffered devices from {ToPrettyString(uid):tool}"); component.Devices.Clear(); UpdateListUiState(uid, component); } @@ -539,6 +550,10 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem if (!configurator.ActiveDeviceLink.HasValue || !configurator.DeviceLinkTarget.HasValue) return; + if (args.Session.AttachedEntity != null) + _adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, + $"{ToPrettyString(args.Session.AttachedEntity.Value):actor} cleared links between {ToPrettyString(configurator.ActiveDeviceLink.Value):subject} and {ToPrettyString(configurator.DeviceLinkTarget.Value):subject2} with {ToPrettyString(uid):tool}"); + if (HasComp(configurator.ActiveDeviceLink) && HasComp(configurator.DeviceLinkTarget)) { _deviceLinkSystem.RemoveSinkFromSource( @@ -661,15 +676,29 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem switch (args.ButtonKey) { case NetworkConfiguratorButtonKey.Set: + if (args.Session.AttachedEntity != null) + _adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, + $"{ToPrettyString(args.Session.AttachedEntity.Value):actor} set device links to {ToPrettyString(component.ActiveDeviceList.Value):subject} with {ToPrettyString(uid):tool}"); + result = _deviceListSystem.UpdateDeviceList(component.ActiveDeviceList.Value, new HashSet(component.Devices.Values)); break; case NetworkConfiguratorButtonKey.Add: + if (args.Session.AttachedEntity != null) + _adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, + $"{ToPrettyString(args.Session.AttachedEntity.Value):actor} added device links to {ToPrettyString(component.ActiveDeviceList.Value):subject} with {ToPrettyString(uid):tool}"); + result = _deviceListSystem.UpdateDeviceList(component.ActiveDeviceList.Value, new HashSet(component.Devices.Values), true); break; case NetworkConfiguratorButtonKey.Clear: + if (args.Session.AttachedEntity != null) + _adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, + $"{ToPrettyString(args.Session.AttachedEntity.Value):actor} cleared device links from {ToPrettyString(component.ActiveDeviceList.Value):subject} with {ToPrettyString(uid):tool}"); result = _deviceListSystem.UpdateDeviceList(component.ActiveDeviceList.Value, new HashSet()); break; case NetworkConfiguratorButtonKey.Copy: + if (args.Session.AttachedEntity != null) + _adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, + $"{ToPrettyString(args.Session.AttachedEntity.Value):actor} copied devices from {ToPrettyString(component.ActiveDeviceList.Value):subject} to {ToPrettyString(uid):tool}"); component.Devices = _deviceListSystem.GetDeviceList(component.ActiveDeviceList.Value); UpdateListUiState(uid, component); return; diff --git a/Content.Shared.Database/LogType.cs b/Content.Shared.Database/LogType.cs index 48f8bf6a04..99fe568626 100644 --- a/Content.Shared.Database/LogType.cs +++ b/Content.Shared.Database/LogType.cs @@ -87,4 +87,5 @@ public enum LogType EntityDelete = 82, Vote = 83, ItemConfigure = 84, + DeviceLinking = 85, } diff --git a/Content.Shared/DeviceLinking/SharedDeviceLinkSystem.cs b/Content.Shared/DeviceLinking/SharedDeviceLinkSystem.cs index f2b0f57c66..80b00d635c 100644 --- a/Content.Shared/DeviceLinking/SharedDeviceLinkSystem.cs +++ b/Content.Shared/DeviceLinking/SharedDeviceLinkSystem.cs @@ -1,3 +1,5 @@ +using Content.Shared.Administration.Logs; +using Content.Shared.Database; using Content.Shared.DeviceLinking.Events; using Content.Shared.Popups; using Robust.Shared.Prototypes; @@ -9,6 +11,7 @@ public abstract class SharedDeviceLinkSystem : EntitySystem { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly SharedPopupSystem _popupSystem = default!; + [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; private ISawmill _sawmill = default!; public const string InvokedPort = "link_port"; @@ -255,6 +258,11 @@ public abstract class SharedDeviceLinkSystem : EntitySystem if (!Resolve(sourceUid, ref sourceComponent) || !Resolve(sinkUid, ref sinkComponent)) return; + if (userId != null) + _adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, $"{ToPrettyString(userId.Value):actor} is linking defaults between {ToPrettyString(sourceUid):source} and {ToPrettyString(sinkUid):sink}"); + else + _adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, $"linking defaults between {ToPrettyString(sourceUid):source} and {ToPrettyString(sinkUid):sink}"); + var sourcePorts = GetSourcePorts(sourceUid, sourceComponent); var defaults = GetDefaults(sourcePorts); SaveLinks(userId, sourceUid, sinkUid, defaults, sourceComponent, sinkComponent); @@ -413,6 +421,11 @@ public abstract class SharedDeviceLinkSystem : EntitySystem if (linkedPorts.Contains((source, sink))) { + if (userId != null) + _adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, $"{ToPrettyString(userId.Value):actor} unlinked {ToPrettyString(sourceUid):source} {source} and {ToPrettyString(sinkUid):sink} {sink}"); + else + _adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, $"unlinked {ToPrettyString(sourceUid):source} {source} and {ToPrettyString(sinkUid):sink} {sink}"); + RaiseLocalEvent(sourceUid, new PortDisconnectedEvent(source)); RaiseLocalEvent(sinkUid, new PortDisconnectedEvent(sink)); @@ -497,6 +510,11 @@ public abstract class SharedDeviceLinkSystem : EntitySystem private void SendNewLinkEvent(EntityUid? user, EntityUid sourceUid, string source, EntityUid sinkUid, string sink) { + if (user != null) + _adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, $"{ToPrettyString(user.Value):actor} linked {ToPrettyString(sourceUid):source} {source} and {ToPrettyString(sinkUid):sink} {sink}"); + else + _adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, $"linked {ToPrettyString(sourceUid):source} {source} and {ToPrettyString(sinkUid):sink} {sink}"); + var newLinkEvent = new NewLinkEvent(user, sourceUid, source, sinkUid, sink); RaiseLocalEvent(sourceUid, newLinkEvent); RaiseLocalEvent(sinkUid, newLinkEvent);