Use dictionary and hashset for admin log entities and players respectively
Add test for duplicate player ids in an admin log not throwing
This commit is contained in:
@@ -35,11 +35,11 @@ public partial class AdminLogSystem
|
||||
_sawmill.Debug($"Admin log converters found: {string.Join(" ", converterNames)}");
|
||||
}
|
||||
|
||||
private (JsonDocument json, List<Guid> players, List<(int id, string? name)> entities) ToJson(
|
||||
private (JsonDocument json, HashSet<Guid> players, Dictionary<int, string?> entities) ToJson(
|
||||
Dictionary<string, object?> properties)
|
||||
{
|
||||
var entities = new List<(int id, string? name)>();
|
||||
var players = new List<Guid>();
|
||||
var entities = new Dictionary<int, string?>();
|
||||
var players = new HashSet<Guid>();
|
||||
var parsed = new Dictionary<string, object?>();
|
||||
|
||||
foreach (var key in properties.Keys)
|
||||
@@ -54,7 +54,7 @@ public partial class AdminLogSystem
|
||||
var parsedKey = NamingPolicy.ConvertName(key);
|
||||
parsed.Add(parsedKey, value);
|
||||
|
||||
EntityUid? entityId = properties[key] switch
|
||||
var entityId = properties[key] switch
|
||||
{
|
||||
EntityUid id => id,
|
||||
EntityStringRepresentation rep => rep.Uid,
|
||||
@@ -72,9 +72,7 @@ public partial class AdminLogSystem
|
||||
? metadata.EntityName
|
||||
: null;
|
||||
|
||||
if (entities.Any(e => e.id == (int) uid)) continue;
|
||||
|
||||
entities.Add(((int) uid, entityName));
|
||||
entities.TryAdd((int) uid, entityName);
|
||||
|
||||
if (_entityManager.TryGetComponent(uid, out ActorComponent? actor))
|
||||
{
|
||||
|
||||
@@ -243,7 +243,7 @@ public partial class AdminLogSystem : SharedAdminLogSystem
|
||||
}
|
||||
}
|
||||
|
||||
private async void Add(LogType type, LogImpact impact, string message, JsonDocument json, List<Guid> players, List<(int id, string? name)> entities)
|
||||
private async void Add(LogType type, LogImpact impact, string message, JsonDocument json, HashSet<Guid> players, Dictionary<int, string?> entities)
|
||||
{
|
||||
var logId = NextLogId;
|
||||
var date = DateTime.UtcNow;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Database;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Server.Administration.Logs;
|
||||
|
||||
public readonly struct QueuedLog
|
||||
{
|
||||
public QueuedLog(AdminLog log, List<(int id, string? name)> entities)
|
||||
public QueuedLog(AdminLog log, Dictionary<int, string?> entities)
|
||||
{
|
||||
Log = log;
|
||||
Entities = entities;
|
||||
@@ -14,9 +13,9 @@ public readonly struct QueuedLog
|
||||
|
||||
public AdminLog Log { get; }
|
||||
|
||||
public List<(int id, string? name)> Entities { get; }
|
||||
public Dictionary<int, string?> Entities { get; }
|
||||
|
||||
public void Deconstruct(out AdminLog log, out List<(int id, string? name)> entities)
|
||||
public void Deconstruct(out AdminLog log, out Dictionary<int, string?> entities)
|
||||
{
|
||||
log = Log;
|
||||
entities = Entities;
|
||||
|
||||
Reference in New Issue
Block a user