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
This commit is contained in:
Chief-Engineer
2022-12-27 11:01:36 -06:00
committed by GitHub
parent 1db51e93b1
commit 2a8e5d9096
3 changed files with 32 additions and 5 deletions

View File

@@ -1,13 +1,18 @@
using Content.Server.Administration.Logs;
using Content.Server.Audio; using Content.Server.Audio;
using Content.Server.Power.Components; using Content.Server.Power.Components;
using Content.Shared.Database;
using Content.Shared.Gravity; using Content.Shared.Gravity;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Players;
namespace Content.Server.Gravity namespace Content.Server.Gravity
{ {
public sealed class GravityGeneratorSystem : EntitySystem public sealed class GravityGeneratorSystem : EntitySystem
{ {
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly AmbientSoundSystem _ambientSoundSystem = default!; [Dependency] private readonly AmbientSoundSystem _ambientSoundSystem = default!;
[Dependency] private readonly GravitySystem _gravitySystem = default!; [Dependency] private readonly GravitySystem _gravitySystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = 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)) if (!Resolve(uid, ref powerReceiver))
return; 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; component.SwitchedOn = on;
UpdatePowerState(component, powerReceiver); UpdatePowerState(component, powerReceiver);
component.NeedUIUpdate = true; component.NeedUIUpdate = true;
@@ -279,7 +288,7 @@ namespace Content.Server.Gravity
GravityGeneratorComponent component, GravityGeneratorComponent component,
SharedGravityGeneratorComponent.SwitchGeneratorMessage args) SharedGravityGeneratorComponent.SwitchGeneratorMessage args)
{ {
SetSwitchedOn(uid, component, args.On); SetSwitchedOn(uid, component, args.On, session:args.Session);
} }
} }
} }

View File

@@ -1,11 +1,13 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Content.Server.Administration.Logs;
using Content.Server.Construction; using Content.Server.Construction;
using Content.Server.Lathe.Components; using Content.Server.Lathe.Components;
using Content.Server.Materials; using Content.Server.Materials;
using Content.Server.Power.Components; using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems; using Content.Server.Power.EntitySystems;
using Content.Server.UserInterface; using Content.Server.UserInterface;
using Content.Shared.Database;
using Content.Shared.Lathe; using Content.Shared.Lathe;
using Content.Shared.Materials; using Content.Shared.Materials;
using Content.Shared.Research.Components; using Content.Shared.Research.Components;
@@ -22,6 +24,7 @@ namespace Content.Server.Lathe
{ {
[Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPrototypeManager _proto = default!; [Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly UserInterfaceSystem _uiSys = default!; [Dependency] private readonly UserInterfaceSystem _uiSys = default!;
@@ -287,10 +290,15 @@ namespace Content.Server.Lathe
{ {
if (_proto.TryIndex(args.ID, out LatheRecipePrototype? recipe)) if (_proto.TryIndex(args.ID, out LatheRecipePrototype? recipe))
{ {
var count = 0;
for (var i = 0; i < args.Quantity; i++) 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); TryStartProducing(uid, component);
UpdateUserInterfaceState(uid, component); UpdateUserInterfaceState(uid, component);

View File

@@ -1,7 +1,9 @@
using Content.Shared.Materials; using Content.Server.Administration.Logs;
using Content.Shared.Materials;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Server.Power.Components; using Content.Server.Power.Components;
using Robust.Shared.Player; using Content.Shared.Database;
using Content.Shared.Stacks;
namespace Content.Server.Materials; namespace Content.Server.Materials;
@@ -10,6 +12,7 @@ namespace Content.Server.Materials;
/// </summary> /// </summary>
public sealed class MaterialStorageSystem : SharedMaterialStorageSystem public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
{ {
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedPopupSystem _popup = 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), _popup.PopupEntity(Loc.GetString("machine-insert-item", ("user", user), ("machine", component.Owner),
("item", toInsert)), component.Owner); ("item", toInsert)), component.Owner);
QueueDel(toInsert); QueueDel(toInsert);
// Logging
TryComp<StackComponent>(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; return true;
} }
} }