Improve ID modification logs (#12918)

* show modifications in access change logs

* skip logging and updates to name and job when no change was made

* add method to SharedAccessSystem.cs to get access tags

* add ID microwave logs
This commit is contained in:
Chief-Engineer
2022-12-19 21:53:20 -06:00
committed by GitHub
parent 6293c6f359
commit 0d18cec6b5
3 changed files with 29 additions and 1 deletions

View File

@@ -95,12 +95,20 @@ namespace Content.Server.Access.Components
} }
var accessSystem = _entities.EntitySysManager.GetEntitySystem<AccessSystem>(); var accessSystem = _entities.EntitySysManager.GetEntitySystem<AccessSystem>();
var oldTags = accessSystem.TryGetTags(targetIdEntity) ?? new List<string>();
oldTags = oldTags.ToList();
if (oldTags.SequenceEqual(newAccessList))
return;
var addedTags = newAccessList.Except(oldTags).Select(tag => "+" + tag).ToList();
var removedTags = oldTags.Except(newAccessList).Select(tag => "-" + tag).ToList();
accessSystem.TrySetTags(targetIdEntity, newAccessList); accessSystem.TrySetTags(targetIdEntity, newAccessList);
/*TODO: ECS IdCardConsoleComponent and then log on card ejection, together with the save. /*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*/ 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, _adminLogger.Add(LogType.Action, LogImpact.Medium,
$"{_entities.ToPrettyString(player):player} has modified {_entities.ToPrettyString(targetIdEntity):entity} with the following accesses: [{string.Join(", ", newAccessList)}]"); $"{_entities.ToPrettyString(player):player} has modified {_entities.ToPrettyString(targetIdEntity):entity} with the following accesses: [{String.Join(", ", addedTags.Union(removedTags))}] [{string.Join(", ", newAccessList)}]");
UpdateStationRecord(targetIdEntity, newFullName, newJobTitle, newJobProto); UpdateStationRecord(targetIdEntity, newFullName, newJobTitle, newJobProto);
} }

View File

@@ -48,6 +48,8 @@ namespace Content.Server.Access.Systems
EntityManager.SpawnEntity("FoodBadRecipe", EntityManager.SpawnEntity("FoodBadRecipe",
transformComponent.Coordinates); transformComponent.Coordinates);
} }
_adminLogger.Add(LogType.Action, LogImpact.Medium,
$"{ToPrettyString(args.Microwave)} burnt {ToPrettyString(uid):entity}");
EntityManager.QueueDeleteEntity(uid); EntityManager.QueueDeleteEntity(uid);
return; return;
} }
@@ -56,6 +58,8 @@ namespace Content.Server.Access.Systems
{ {
_popupSystem.PopupEntity(Loc.GetString("id-card-component-microwave-bricked", ("id", uid)), uid); _popupSystem.PopupEntity(Loc.GetString("id-card-component-microwave-bricked", ("id", uid)), uid);
access.Tags.Clear(); access.Tags.Clear();
_adminLogger.Add(LogType.Action, LogImpact.Medium,
$"{ToPrettyString(args.Microwave)} cleared access on {ToPrettyString(uid):entity}");
} }
else else
{ {
@@ -65,6 +69,9 @@ namespace Content.Server.Access.Systems
// Give them a wonderful new access to compensate for everything // Give them a wonderful new access to compensate for everything
var random = _random.Pick(_prototypeManager.EnumeratePrototypes<AccessLevelPrototype>().ToArray()); var random = _random.Pick(_prototypeManager.EnumeratePrototypes<AccessLevelPrototype>().ToArray());
access.Tags.Add(random.ID); access.Tags.Add(random.ID);
_adminLogger.Add(LogType.Action, LogImpact.Medium,
$"{ToPrettyString(args.Microwave)} added {random.ID} access to {ToPrettyString(uid):entity}");
} }
} }
@@ -92,6 +99,8 @@ namespace Content.Server.Access.Systems
jobTitle = null; jobTitle = null;
} }
if (id.JobTitle == jobTitle)
return true;
id.JobTitle = jobTitle; id.JobTitle = jobTitle;
Dirty(id); Dirty(id);
UpdateEntityName(uid, id); UpdateEntityName(uid, id);
@@ -127,6 +136,8 @@ namespace Content.Server.Access.Systems
fullName = null; fullName = null;
} }
if (id.FullName == fullName)
return true;
id.FullName = fullName; id.FullName = fullName;
Dirty(id); Dirty(id);
UpdateEntityName(uid, id); UpdateEntityName(uid, id);

View File

@@ -67,6 +67,15 @@ namespace Content.Shared.Access.Systems
return true; return true;
} }
/// <summary>
/// Gets the set of access tags.
/// </summary>
/// <param name="newTags">The new access tags</param>
public IEnumerable<string>? TryGetTags(EntityUid uid, AccessComponent? access = null)
{
return !Resolve(uid, ref access) ? null : access.Tags;
}
public bool TryAddGroups(EntityUid uid, IEnumerable<string> newGroups, AccessComponent? access = null) public bool TryAddGroups(EntityUid uid, IEnumerable<string> newGroups, AccessComponent? access = null)
{ {
if (!Resolve(uid, ref access)) if (!Resolve(uid, ref access))