add device linking logs (#17555)

This commit is contained in:
Chief-Engineer
2023-06-27 20:03:39 -05:00
committed by GitHub
parent abc2e04d62
commit 72607f3066
3 changed files with 50 additions and 2 deletions

View File

@@ -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
/// </summary>
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
/// <summary>
/// Clears the saved devices
/// </summary>
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<DeviceLinkSourceComponent>(configurator.ActiveDeviceLink) && HasComp<DeviceLinkSinkComponent>(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<EntityUid>(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<EntityUid>(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<EntityUid>());
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;