Skip to content

Commit

Permalink
Adds even more important Admin Logging (#10268)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirino97 authored Aug 7, 2022
1 parent a2d8e96 commit ee969c9
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 49 deletions.
21 changes: 16 additions & 5 deletions Content.Server/Access/Components/IdCardConsoleComponent.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System.Linq;
using Content.Server.Access.Systems;
using Content.Server.Administration.Logs;
using Content.Server.UserInterface;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Database;
using Robust.Server.GameObjects;

namespace Content.Server.Access.Components
Expand All @@ -12,6 +15,7 @@ namespace Content.Server.Access.Components
public sealed class IdCardConsoleComponent : SharedIdCardConsoleComponent
{
[Dependency] private readonly IEntityManager _entities = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;

[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(IdCardConsoleUiKey.Key);

Expand All @@ -26,6 +30,7 @@ protected override void Initialize()
{
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
}

}

private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
Expand All @@ -38,7 +43,7 @@ private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
switch (obj.Message)
{
case WriteToTargetIdMessage msg:
TryWriteToTargetId(msg.FullName, msg.JobTitle, msg.AccessList);
TryWriteToTargetId(msg.FullName, msg.JobTitle, msg.AccessList, player);
UpdateUserInterface();
break;
}
Expand All @@ -60,17 +65,17 @@ private bool PrivilegedIdIsAuthorized()
}

/// <summary>
/// Called when the "Submit" button in the UI gets pressed.
/// Called whenever an access button is pressed, adding or removing that access from the target ID card.
/// Writes data passed from the UI into the ID stored in <see cref="TargetIdSlot"/>, if present.
/// </summary>
private void TryWriteToTargetId(string newFullName, string newJobTitle, List<string> newAccessList)
private void TryWriteToTargetId(string newFullName, string newJobTitle, List<string> newAccessList, EntityUid player)
{
if (TargetIdSlot.Item is not {Valid: true} targetIdEntity || !PrivilegedIdIsAuthorized())
return;

var cardSystem = EntitySystem.Get<IdCardSystem>();
cardSystem.TryChangeFullName(targetIdEntity, newFullName);
cardSystem.TryChangeJobTitle(targetIdEntity, newJobTitle);
cardSystem.TryChangeFullName(targetIdEntity, newFullName, player: player);
cardSystem.TryChangeJobTitle(targetIdEntity, newJobTitle, player: player);

if (!newAccessList.TrueForAll(x => AccessLevels.Contains(x)))
{
Expand All @@ -80,6 +85,12 @@ private void TryWriteToTargetId(string newFullName, string newJobTitle, List<str

var accessSystem = EntitySystem.Get<AccessSystem>();
accessSystem.TrySetTags(targetIdEntity, newAccessList);

/*TODO: ECS IdCardConsoleComponent and then log on card ejection, together with the save.
This current implementation is pretty shit as it logs 27 entries (27 lines) if someone decides to give themselves AA*/
_adminLogger.Add(LogType.Action, LogImpact.Medium,
$"{_entities.ToPrettyString(player):player} has modified {_entities.ToPrettyString(targetIdEntity):entity} with the following accesses: [{string.Join(", ", newAccessList)}]");

}

public void UpdateUserInterface()
Expand Down
30 changes: 27 additions & 3 deletions Content.Server/Access/Systems/IdCardSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
using Content.Shared.Inventory;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Server.Administration.Logs;
using Content.Server.Kitchen.Components;
using Content.Server.Popups;
using Content.Shared.Access;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Database;
using Content.Shared.PDA;
using Content.Shared.Popups;
using Robust.Shared.Player;
Expand All @@ -21,6 +23,7 @@ public sealed class IdCardSystem : SharedIdCardSystem
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -73,22 +76,39 @@ private void OnMicrowaved(EntityUid uid, IdCardComponent component, BeingMicrowa
}
}

public bool TryChangeJobTitle(EntityUid uid, string jobTitle, IdCardComponent? id = null)
/// <summary>
/// Attempts to change the job title of a card.
/// Returns true/false.
/// </summary>
/// <remarks>
/// If provided with a player's EntityUid to the player parameter, adds the change to the admin logs.
/// </remarks>
public bool TryChangeJobTitle(EntityUid uid, string jobTitle, IdCardComponent? id = null, EntityUid? player = null)
{
if (!Resolve(uid, ref id))
return false;

// TODO: Whenever we get admin logging these should be logged
if (jobTitle.Length > SharedIdCardConsoleComponent.MaxJobTitleLength)
jobTitle = jobTitle[..SharedIdCardConsoleComponent.MaxJobTitleLength];

id.JobTitle = jobTitle;
Dirty(id);
UpdateEntityName(uid, id);

if (player != null)
_adminLogger.Add(LogType.Identity, LogImpact.Low,
$"{ToPrettyString(player.Value):player} has changed the job title of {ToPrettyString(id.Owner):entity} to {jobTitle} ");
return true;
}

public bool TryChangeFullName(EntityUid uid, string fullName, IdCardComponent? id = null)
/// <summary>
/// Attempts to change the full name of a card.
/// Returns true/false.
/// </summary>
/// <remarks>
/// If provided with a player's EntityUid to the player parameter, adds the change to the admin logs.
/// </remarks>
public bool TryChangeFullName(EntityUid uid, string fullName, IdCardComponent? id = null, EntityUid? player = null)
{
if (!Resolve(uid, ref id))
return false;
Expand All @@ -99,6 +119,10 @@ public bool TryChangeFullName(EntityUid uid, string fullName, IdCardComponent? i
id.FullName = fullName;
Dirty(id);
UpdateEntityName(uid, id);

if (player != null)
_adminLogger.Add(LogType.Identity, LogImpact.Low,
$"{ToPrettyString(player.Value):player} has changed the name of {ToPrettyString(id.Owner):entity} to {fullName} ");
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,15 @@ private void OnCanisterChangeReleaseValve(EntityUid uid, GasCanisterComponent ca
&& containerManager.TryGetContainer(canister.ContainerName, out var container))
impact = container.ContainedEntities.Count != 0 ? LogImpact.Medium : LogImpact.High;

_adminLogger.Add(LogType.CanisterValve, impact, $"{ToPrettyString(args.Session.AttachedEntity.GetValueOrDefault()):player} set the valve on {ToPrettyString(uid):canister} to {args.Valve:valveState}");
var containedGasDict = new Dictionary<Gas, float>();
var containedGasArray = Gas.GetValues(typeof(Gas));

for (int i = 0; i < containedGasArray.Length; i++)
{
containedGasDict.Add((Gas)i, canister.Air.Moles[i]);
}

_adminLogger.Add(LogType.CanisterValve, impact, $"{ToPrettyString(args.Session.AttachedEntity.GetValueOrDefault()):player} set the valve on {ToPrettyString(uid):canister} to {args.Valve:valveState} while it contained [{string.Join(", ", containedGasDict)}]");

canister.ReleaseValve = args.Valve;
DirtyUI(uid, canister);
Expand Down
12 changes: 9 additions & 3 deletions Content.Server/Chat/Systems/ChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Content.Server.Chat.Managers;
using Content.Server.GameTicking;
using Content.Server.Ghost.Components;
using Content.Server.Mind.Components;
using Content.Server.Players;
using Content.Server.Popups;
using Content.Server.Radio.EntitySystems;
Expand All @@ -18,6 +19,7 @@
using Content.Shared.Database;
using Content.Shared.IdentityManagement;
using Content.Shared.Inventory;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Audio;
using Robust.Shared.Configuration;
Expand Down Expand Up @@ -268,6 +270,10 @@ private void SendEntitySpeak(EntityUid source, string originalMessage, bool hide
var ev = new EntitySpokeEvent(message);
RaiseLocalEvent(source, ev);

// To avoid logging any messages sent by entities that are not players, like vendors, cloning, etc.
if (!TryComp(source, out ActorComponent? mind))
return;

if (originalMessage == message)
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Say from {ToPrettyString(source):user}: {originalMessage}.");
else
Expand Down Expand Up @@ -362,18 +368,18 @@ private void SendDeadChat(EntityUid source, IPlayerSession player, string messag
messageWrap = Loc.GetString("chat-manager-send-admin-dead-chat-wrap-message",
("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")),
("userName", player.ConnectedClient.UserName));
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Dead chat from {player:Player}: {message}");
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Admin dead chat from {player:Player}: {message}");
}
else
{
messageWrap = Loc.GetString("chat-manager-send-dead-chat-wrap-message",
("deadChannelName", Loc.GetString("chat-manager-dead-channel-name")),
("playerName", (playerName)));
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Admin dead chat from {player:Player}: {message}");
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Dead chat from {player:Player}: {message}");
}

_chatManager.ChatMessageToMany(ChatChannel.Dead, message, messageWrap, source, hideChat, clients.ToList());
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Dead chat from {player:Player}: {message}");

}
#endregion

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Linq;
using Content.Server.Administration.Logs;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Power.Components;
using Content.Server.UserInterface;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Dispenser;
using Content.Shared.Database;
using Content.Shared.FixedPoint;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
Expand All @@ -29,6 +31,7 @@ public sealed class ReagentDispenserComponent : SharedReagentDispenserComponent

[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IEntityManager _entities = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;

[ViewVariables] [DataField("pack", customTypeSerializer:typeof(PrototypeIdSerializer<ReagentDispenserInventoryPrototype>))] private string _packPrototypeId = "";

Expand Down Expand Up @@ -171,8 +174,11 @@ private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
if (BeakerSlot.HasItem)
{
TryDispense(msg.DispenseIndex);
// Ew
if (BeakerSlot.Item != null)
_adminLogger.Add(LogType.ChemicalReaction, LogImpact.Medium,
$"{_entities.ToPrettyString(obj.Session.AttachedEntity.Value):player} dispensed {_dispenseAmount}u of {Inventory[msg.DispenseIndex].ID} into {_entities.ToPrettyString(BeakerSlot.Item.Value):entity}");
}
Logger.Info($"User {obj.Session.UserId.UserId} ({obj.Session.Name}) dispensed {_dispenseAmount}u of {Inventory[msg.DispenseIndex].ID}");

break;
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Content.Server.Administration.Logs;
using Content.Shared.Verbs;
using Content.Server.Chemistry.Components;
using Content.Server.Chemistry.Components.SolutionManager;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Content.Shared.Chemistry.Components;
using Content.Shared.Database;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
using Content.Shared.Popups;
Expand All @@ -14,6 +16,7 @@ namespace Content.Server.Chemistry.EntitySystems
public sealed class SolutionTransferSystem : EntitySystem
{
[Dependency] private readonly SolutionContainerSystem _solutionContainer = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;

/// <summary>
/// Default transfer amounts for the set-transfer verb.
Expand Down Expand Up @@ -181,6 +184,9 @@ public FixedPoint2 Transfer(EntityUid user,
var solution = solutionSystem.Drain(sourceEntity, source, actualAmount);
solutionSystem.Refill(targetEntity, target, solution);

_adminLogger.Add(LogType.Action, LogImpact.Medium,
$"{EntityManager.ToPrettyString(user):player} transferred {string.Join(", ", solution.Contents)} to {EntityManager.ToPrettyString(targetEntity):entity}, which now contains {string.Join(", ", target.Contents)}");

return actualAmount;
}
}
Expand Down
12 changes: 12 additions & 0 deletions Content.Server/Communications/CommunicationsConsoleSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Globalization;
using System.Linq;
using Content.Server.Access.Systems;
using Content.Server.Administration.Logs;
using Content.Server.AlertLevel;
using Content.Server.Chat;
using Content.Server.Chat.Systems;
Expand All @@ -13,6 +14,7 @@
using Content.Shared.Access.Systems;
using Content.Shared.CCVar;
using Content.Shared.Communications;
using Content.Shared.Database;
using Content.Shared.Examine;
using Content.Shared.Popups;
using Robust.Server.GameObjects;
Expand All @@ -33,6 +35,7 @@ public sealed class CommunicationsConsoleSystem : EntitySystem
[Dependency] private readonly ShuttleSystem _shuttle = default!;
[Dependency] private readonly StationSystem _stationSystem = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;

private const int MaxMessageLength = 256;
private const float UIUpdateInterval = 5.0f;
Expand Down Expand Up @@ -251,9 +254,16 @@ private void OnAnnounceMessage(EntityUid uid, CommunicationsConsoleComponent com
if (comp.AnnounceGlobal)
{
_chatSystem.DispatchGlobalAnnouncement(msg, title, announcementSound: comp.AnnouncementSound, colorOverride: comp.AnnouncementColor);

if (message.Session.AttachedEntity != null)
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"{ToPrettyString(message.Session.AttachedEntity.Value):player} has sent the following global announcement: {msg}");

return;
}
_chatSystem.DispatchStationAnnouncement(uid, msg, title, colorOverride: comp.AnnouncementColor);

if (message.Session.AttachedEntity != null)
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"{ToPrettyString(message.Session.AttachedEntity.Value):player} has sent the following station announcement: {msg}");
}

private void OnCallShuttleMessage(EntityUid uid, CommunicationsConsoleComponent comp, CommunicationsConsoleCallEmergencyShuttleMessage message)
Expand All @@ -266,6 +276,7 @@ private void OnCallShuttleMessage(EntityUid uid, CommunicationsConsoleComponent
return;
}
_roundEndSystem.RequestRoundEnd(uid);
_adminLogger.Add(LogType.Action, LogImpact.Extreme, $"{ToPrettyString(mob):player} has called the shuttle.");
}

private void OnRecallShuttleMessage(EntityUid uid, CommunicationsConsoleComponent comp, CommunicationsConsoleRecallEmergencyShuttleMessage message)
Expand All @@ -279,6 +290,7 @@ private void OnRecallShuttleMessage(EntityUid uid, CommunicationsConsoleComponen
}

_roundEndSystem.CancelRoundEndCountdown(uid);
_adminLogger.Add(LogType.Action, LogImpact.Extreme, $"{ToPrettyString(mob):player} has recalled the shuttle.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using Content.Server.Administration.Logs;
using Content.Server.Construction.Components;
using Content.Server.DoAfter;
using Content.Shared.Construction;
using Content.Shared.Construction.EntitySystems;
using Content.Shared.Construction.Steps;
using Content.Shared.Database;
using Content.Shared.Interaction;
using Robust.Shared.Containers;

namespace Content.Server.Construction
{
public sealed partial class ConstructionSystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;

private readonly HashSet<EntityUid> _constructionUpdateQueue = new();

private void InitializeInteractions()
Expand Down Expand Up @@ -38,7 +42,7 @@ private void InitializeInteractions()
/// <remarks>When <see cref="validation"/> is true, this method will simply return whether the interaction
/// would be handled by the entity or not. It essentially becomes a pure method that modifies nothing.</remarks>
/// <returns>The result of this interaction with the entity.</returns>
private HandleResult HandleEvent(EntityUid uid, object ev, bool validation, ConstructionComponent? construction = null)
private HandleResult HandleEvent(EntityUid uid, object ev, bool validation, ConstructionComponent? construction = null, InteractUsingEvent? args = null)
{
if (!Resolve(uid, ref construction))
return HandleResult.False;
Expand Down Expand Up @@ -160,6 +164,9 @@ private HandleResult HandleEdge(EntityUid uid, object ev, ConstructionGraphEdge

// We change the node now.
ChangeNode(uid, user, edge.Target, true, construction);

if (ev is ConstructionDoAfterComplete event1 && event1.WrappedEvent is InteractUsingEvent event2)
_adminLogger.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(event2.User):player} changed {ToPrettyString(uid):entity}'s node to {edge.Target}");
}

return HandleResult.True;
Expand Down
Loading

0 comments on commit ee969c9

Please sign in to comment.