Add EntityUid AdminLogConverter
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
using System.Text.Json;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Administration.Logs.Converters;
|
||||
|
||||
[AdminLogConverter]
|
||||
public class EntityConverter : AdminLogConverter<Entity>
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Entity value, JsonSerializerOptions options)
|
||||
{
|
||||
EntityUidConverter.Write(writer, value.Uid, options, _entities);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Administration.Logs.Converters;
|
||||
|
||||
[AdminLogConverter]
|
||||
public class EntityJsonConverter : AdminLogConverter<Entity>
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Entity value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
|
||||
writer.WriteNumber("id", (int) value.Uid);
|
||||
writer.WriteString("name", value.Name);
|
||||
|
||||
if (_entities.TryGetComponent(value.Uid, out ActorComponent? actor))
|
||||
{
|
||||
writer.WriteString("player", actor.PlayerSession.UserId.UserId);
|
||||
}
|
||||
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Text.Json;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Administration.Logs.Converters;
|
||||
|
||||
[AdminLogConverter]
|
||||
public class EntityUidConverter : AdminLogConverter<EntityUid>
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public static void Write(Utf8JsonWriter writer, EntityUid value, JsonSerializerOptions options, IEntityManager entities)
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
|
||||
writer.WriteNumber("id", (int) value);
|
||||
|
||||
if (entities.TryGetEntity(value, out var entity))
|
||||
{
|
||||
writer.WriteString("name", entity.Name);
|
||||
}
|
||||
|
||||
if (entities.TryGetComponent(value, out ActorComponent? actor))
|
||||
{
|
||||
writer.WriteString("player", actor.PlayerSession.UserId.UserId);
|
||||
}
|
||||
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, EntityUid value, JsonSerializerOptions options)
|
||||
{
|
||||
Write(writer, value, options, _entities);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user