Id[entity] 2.0 (real) (#9612)
* starter API * network ID cards * Port more stuff from old identity * Re-implement identity representation + name updating * move * proper name returning for `IdentityName` * move everything important to server, give in to temptation * shared / server / client split sadly. move ensure to shared and spawn to server * identity update queueing + identityblocker * fixes * and just like that it's usable for admins * huge identity pass * pass dos * jesus christ * figs :D * fuck u * fix bad merge. Co-authored-by: Moony <moonheart08@users.noreply.github.com>
This commit is contained in:
60
Content.Shared/IdentityManagement/Identity.cs
Normal file
60
Content.Shared/IdentityManagement/Identity.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using Content.Shared.Ghost;
|
||||
using Content.Shared.IdentityManagement.Components;
|
||||
|
||||
namespace Content.Shared.IdentityManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Static content API for getting the identity entities/names for a given entity.
|
||||
/// This should almost always be used in favor of metadata name, if the entity in question is a human player that
|
||||
/// can have identity.
|
||||
/// </summary>
|
||||
public static class Identity
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the name that should be used for this entity for identity purposes.
|
||||
/// </summary>
|
||||
public static string Name(EntityUid uid, IEntityManager ent, EntityUid? viewer=null)
|
||||
{
|
||||
var uidName = ent.GetComponent<MetaDataComponent>(uid).EntityName;
|
||||
|
||||
if (!ent.TryGetComponent<IdentityComponent>(uid, out var identity))
|
||||
return uidName;
|
||||
|
||||
var ident = identity.IdentityEntitySlot.ContainedEntity;
|
||||
if (ident is null)
|
||||
return uidName;
|
||||
|
||||
var identName = ent.GetComponent<MetaDataComponent>(ident.Value).EntityName;
|
||||
if (viewer == null || !CanSeeThroughIdentity(uid, viewer.Value, ent))
|
||||
{
|
||||
return identName;
|
||||
}
|
||||
if (uidName == identName)
|
||||
{
|
||||
return uidName;
|
||||
}
|
||||
|
||||
return uidName + $" ({identName})";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the entity that should be used for identity purposes, for example to pass into localization.
|
||||
/// This is an extension method because of its simplicity, and if it was any harder to call it might not
|
||||
/// be used enough for loc.
|
||||
/// </summary>
|
||||
public static EntityUid Entity(EntityUid uid, IEntityManager ent)
|
||||
{
|
||||
if (!ent.TryGetComponent<IdentityComponent>(uid, out var identity))
|
||||
return uid;
|
||||
|
||||
return identity.IdentityEntitySlot.ContainedEntity ?? uid;
|
||||
}
|
||||
|
||||
public static bool CanSeeThroughIdentity(EntityUid uid, EntityUid viewer, IEntityManager ent)
|
||||
{
|
||||
// Would check for uid == viewer here but I think it's better for you to see yourself
|
||||
// how everyone else will see you, otherwise people will probably get confused and think they aren't disguised
|
||||
return ent.HasComponent<SharedGhostComponent>(viewer);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user