From 2a8e5d90960088d93d907f409756bb8d07dd0b9b Mon Sep 17 00:00:00 2001 From: Chief-Engineer <119664036+Chief-Engineer@users.noreply.github.com> Date: Tue, 27 Dec 2022 11:01:36 -0600 Subject: [PATCH] Add machine logs (#13185) * add material insert logs * add lathe queue logs * add grav gen power logs * fix count * replace SharedStackComponent with StackComponent and rm unused imports * use TryComp * fix import --- Content.Server/Gravity/GravityGeneratorSystem.cs | 13 +++++++++++-- Content.Server/Lathe/LatheSystem.cs | 10 +++++++++- Content.Server/Materials/MaterialStorageSystem.cs | 14 ++++++++++++-- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Content.Server/Gravity/GravityGeneratorSystem.cs b/Content.Server/Gravity/GravityGeneratorSystem.cs index 45899492c9..930f2a8d4c 100644 --- a/Content.Server/Gravity/GravityGeneratorSystem.cs +++ b/Content.Server/Gravity/GravityGeneratorSystem.cs @@ -1,13 +1,18 @@ +using Content.Server.Administration.Logs; using Content.Server.Audio; using Content.Server.Power.Components; +using Content.Shared.Database; using Content.Shared.Gravity; using Content.Shared.Interaction; using Robust.Server.GameObjects; +using Robust.Server.Player; +using Robust.Shared.Players; namespace Content.Server.Gravity { public sealed class GravityGeneratorSystem : EntitySystem { + [Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly AmbientSoundSystem _ambientSoundSystem = default!; [Dependency] private readonly GravitySystem _gravitySystem = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; @@ -124,11 +129,15 @@ namespace Content.Server.Gravity } } - private void SetSwitchedOn(EntityUid uid, GravityGeneratorComponent component, bool on, ApcPowerReceiverComponent? powerReceiver = null) + private void SetSwitchedOn(EntityUid uid, GravityGeneratorComponent component, bool on, + ApcPowerReceiverComponent? powerReceiver = null, ICommonSession? session = null) { if (!Resolve(uid, ref powerReceiver)) return; + if (session is { AttachedEntity: { } }) + _adminLogger.Add(LogType.Action, on ? LogImpact.Medium : LogImpact.High, $"{ToPrettyString(session.AttachedEntity.Value):player} set ${ToPrettyString(uid):target} to {(on ? "on" : "off")}"); + component.SwitchedOn = on; UpdatePowerState(component, powerReceiver); component.NeedUIUpdate = true; @@ -279,7 +288,7 @@ namespace Content.Server.Gravity GravityGeneratorComponent component, SharedGravityGeneratorComponent.SwitchGeneratorMessage args) { - SetSwitchedOn(uid, component, args.On); + SetSwitchedOn(uid, component, args.On, session:args.Session); } } } diff --git a/Content.Server/Lathe/LatheSystem.cs b/Content.Server/Lathe/LatheSystem.cs index 8d1ddda670..1978c84718 100644 --- a/Content.Server/Lathe/LatheSystem.cs +++ b/Content.Server/Lathe/LatheSystem.cs @@ -1,11 +1,13 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; +using Content.Server.Administration.Logs; using Content.Server.Construction; using Content.Server.Lathe.Components; using Content.Server.Materials; using Content.Server.Power.Components; using Content.Server.Power.EntitySystems; using Content.Server.UserInterface; +using Content.Shared.Database; using Content.Shared.Lathe; using Content.Shared.Materials; using Content.Shared.Research.Components; @@ -22,6 +24,7 @@ namespace Content.Server.Lathe { [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IPrototypeManager _proto = default!; + [Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly UserInterfaceSystem _uiSys = default!; @@ -287,10 +290,15 @@ namespace Content.Server.Lathe { if (_proto.TryIndex(args.ID, out LatheRecipePrototype? recipe)) { + var count = 0; for (var i = 0; i < args.Quantity; i++) { - TryAddToQueue(uid, recipe, component); + if (TryAddToQueue(uid, recipe, component)) + count++; } + if (count > 0 && args.Session.AttachedEntity != null) + _adminLogger.Add(LogType.Action, LogImpact.Low, + $"{ToPrettyString(args.Session.AttachedEntity.Value):player} queued {count} {recipe.Name} at {ToPrettyString(uid):lathe}"); } TryStartProducing(uid, component); UpdateUserInterfaceState(uid, component); diff --git a/Content.Server/Materials/MaterialStorageSystem.cs b/Content.Server/Materials/MaterialStorageSystem.cs index 5215262d72..0f81da4a38 100644 --- a/Content.Server/Materials/MaterialStorageSystem.cs +++ b/Content.Server/Materials/MaterialStorageSystem.cs @@ -1,7 +1,9 @@ -using Content.Shared.Materials; +using Content.Server.Administration.Logs; +using Content.Shared.Materials; using Content.Shared.Popups; using Content.Server.Power.Components; -using Robust.Shared.Player; +using Content.Shared.Database; +using Content.Shared.Stacks; namespace Content.Server.Materials; @@ -10,6 +12,7 @@ namespace Content.Server.Materials; /// public sealed class MaterialStorageSystem : SharedMaterialStorageSystem { + [Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly SharedPopupSystem _popup = default!; @@ -25,6 +28,13 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem _popup.PopupEntity(Loc.GetString("machine-insert-item", ("user", user), ("machine", component.Owner), ("item", toInsert)), component.Owner); QueueDel(toInsert); + + // Logging + TryComp(toInsert, out var stack); + var count = stack?.Count ?? 1; + _adminLogger.Add(LogType.Action, LogImpact.Low, + $"{ToPrettyString(user):player} inserted {count} {ToPrettyString(toInsert):inserted} into {ToPrettyString(receiver):receiver}"); + return true; } }