# Conflicts: # Content.Client/Entry/EntryPoint.cs # Content.Client/Stylesheets/StyleNano.cs # Content.Server/Nutrition/EntitySystems/CreamPieSystem.cs # Content.Server/Nutrition/EntitySystems/FoodSystem.cs # Content.Shared/Follower/FollowerSystem.cs # Content.Shared/Humanoid/SharedHumanoidAppearanceSystem.cs # Content.Shared/Inventory/InventorySystem.Relay.cs # Content.Shared/PAI/SharedPAISystem.cs # Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs # Resources/Locale/en-US/_strings/access/components/genpop.ftl # Resources/Locale/en-US/_strings/doors/components/turnstile.ftl # Resources/Locale/en-US/_strings/power/battery.ftl # Resources/Locale/en-US/_strings/store/pai-catalog.ftl # Resources/Locale/en-US/_strings/tools/simple-tool-usage.ftl # Resources/Locale/en-US/_strings/ui/controls.ftl # Resources/Locale/en-US/_strings/weapons/ranged/upgrades.ftl # Resources/Prototypes/Access/misc.yml # Resources/Prototypes/Catalog/Cargo/cargo_vending.yml # Resources/Prototypes/Entities/Clothing/OuterClothing/coats.yml # Resources/Prototypes/Entities/Clothing/OuterClothing/hardsuits.yml # Resources/Prototypes/Entities/Markers/Spawners/Random/crates.yml # Resources/Prototypes/Entities/Mobs/Player/admin_ghost.yml # Resources/Prototypes/Entities/Mobs/Player/dragon.yml # Resources/Prototypes/Entities/Mobs/Player/humanoid.yml # Resources/Prototypes/Entities/Objects/Fun/toys.yml # Resources/Prototypes/Entities/Objects/Misc/paper.yml # Resources/Prototypes/Entities/Objects/Specific/Robotics/borg_modules.yml # Resources/Prototypes/Entities/Objects/Tools/access_configurator.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/shotgun.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml # Resources/Prototypes/Entities/Stations/base.yml # Resources/Prototypes/Entities/Structures/Walls/asteroid.yml # Resources/Prototypes/Loadouts/role_loadouts.yml # Resources/Prototypes/Recipes/Lathes/Packs/science.yml # Resources/Prototypes/Research/industrial.yml # Resources/Prototypes/Species/vox.yml # Resources/Prototypes/Store/currency.yml # Resources/Prototypes/Voice/speech_emotes.yml # Resources/Prototypes/ai_factions.yml # Resources/Prototypes/borg_types.yml # Resources/Textures/Clothing/Head/Hats/captain.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpskirt/capformaldress.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpskirt/captain.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpskirt/paramedic.rsi/equipped-INNERCLOTHING.png # Resources/Textures/Clothing/Uniforms/Jumpskirt/paramedic.rsi/icon.png # Resources/Textures/Clothing/Uniforms/Jumpsuit/capformal.rsi/equipped-INNERCLOTHING-monkey.png # Resources/Textures/Clothing/Uniforms/Jumpsuit/capformal.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpsuit/captain.rsi/equipped-INNERCLOTHING-monkey.png # Resources/Textures/Clothing/Uniforms/Jumpsuit/captain.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpsuit/paramedic.rsi/equipped-INNERCLOTHING-monkey.png # Resources/Textures/Clothing/Uniforms/Jumpsuit/paramedic.rsi/equipped-INNERCLOTHING.png # Resources/Textures/Clothing/Uniforms/Jumpsuit/paramedic.rsi/icon.png # Resources/Textures/Clothing/Uniforms/Jumpsuit/paramedic.rsi/meta.json # Resources/Textures/Objects/Weapons/Melee/captain_sabre.rsi/meta.json # Resources/Textures/Objects/Weapons/Melee/energykatana.rsi/meta.json # Resources/Textures/Objects/Weapons/Melee/katana.rsi/meta.json # Resources/Textures/Objects/Weapons/Melee/machete.rsi/meta.json # Resources/Textures/Structures/Doors/Airlocks/Glass/firelock.rsi/closed.png # Resources/Textures/Structures/Doors/Airlocks/Glass/firelock.rsi/closing.png # Resources/Textures/Structures/Doors/Airlocks/Glass/firelock.rsi/deny.png # Resources/Textures/Structures/Doors/Airlocks/Glass/firelock.rsi/locked.png # Resources/Textures/Structures/Doors/Airlocks/Glass/firelock.rsi/opening.png # Resources/Textures/Structures/Doors/Airlocks/Standard/atmospherics.rsi/assembly.png # Resources/Textures/Structures/Doors/Airlocks/Standard/atmospherics.rsi/closed.png # Resources/Textures/Structures/Doors/Airlocks/Standard/atmospherics.rsi/closing.png # Resources/Textures/Structures/Doors/Airlocks/Standard/atmospherics.rsi/meta.json # Resources/Textures/Structures/Doors/Airlocks/Standard/atmospherics.rsi/open.png # Resources/Textures/Structures/Doors/Airlocks/Standard/atmospherics.rsi/opening.png # Resources/Textures/Structures/Doors/Airlocks/Standard/firelock.rsi/closed.png # Resources/Textures/Structures/Doors/Airlocks/Standard/firelock.rsi/closing.png # Resources/Textures/Structures/Doors/Airlocks/Standard/firelock.rsi/opening.png # Resources/Textures/Structures/Wallmounts/posters.rsi/poster4_contraband.png # Resources/migration.yml
351 lines
11 KiB
C#
351 lines
11 KiB
C#
using System.Globalization;
|
|
using System.Linq;
|
|
using Content.Shared.Access.Components;
|
|
using Content.Shared.Administration.Logs;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.Hands.Components;
|
|
using Content.Shared.IdentityManagement;
|
|
using Content.Shared.Inventory;
|
|
using Content.Shared.PDA;
|
|
using Content.Shared.Roles;
|
|
using Content.Shared.StatusIcon;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Shared.Access.Systems;
|
|
|
|
public abstract class SharedIdCardSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly SharedAccessSystem _access = default!;
|
|
[Dependency] private readonly InventorySystem _inventorySystem = default!;
|
|
[Dependency] private readonly MetaDataSystem _metaSystem = default!;
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<IdCardComponent, MapInitEvent>(OnMapInit);
|
|
SubscribeLocalEvent<TryGetIdentityShortInfoEvent>(OnTryGetIdentityShortInfo);
|
|
SubscribeLocalEvent<EntityRenamedEvent>(OnRename);
|
|
}
|
|
|
|
private void OnRename(ref EntityRenamedEvent ev)
|
|
{
|
|
// When a player gets renamed their id card is renamed as well to match.
|
|
// Unfortunately since TryFindIdCard will succeed if the entity is also a card this means that the card will
|
|
// keep renaming itself unless we return early.
|
|
// We also do not include the PDA itself being renamed, as that triggers the same event (e.g. for chameleon PDAs).
|
|
if (HasComp<IdCardComponent>(ev.Uid) || HasComp<PdaComponent>(ev.Uid))
|
|
return;
|
|
|
|
if (TryFindIdCard(ev.Uid, out var idCard))
|
|
TryChangeFullName(idCard, ev.NewName, idCard);
|
|
}
|
|
|
|
private void OnMapInit(EntityUid uid, IdCardComponent id, MapInitEvent args)
|
|
{
|
|
UpdateEntityName(uid, id);
|
|
}
|
|
|
|
private void OnTryGetIdentityShortInfo(TryGetIdentityShortInfoEvent ev)
|
|
{
|
|
if (ev.Handled)
|
|
{
|
|
return;
|
|
}
|
|
|
|
string? title = null;
|
|
if (TryFindIdCard(ev.ForActor, out var idCard) && !(ev.RequestForAccessLogging && idCard.Comp.BypassLogging))
|
|
{
|
|
title = ExtractFullTitle(idCard);
|
|
}
|
|
|
|
ev.Title = title;
|
|
ev.Handled = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempt to find an ID card on an entity. This will look in the entity itself, in the entity's hands, and
|
|
/// in the entity's inventory.
|
|
/// </summary>
|
|
public bool TryFindIdCard(EntityUid uid, out Entity<IdCardComponent> idCard)
|
|
{
|
|
// check held item?
|
|
if (TryComp(uid, out HandsComponent? hands) &&
|
|
hands.ActiveHandEntity is EntityUid heldItem &&
|
|
TryGetIdCard(heldItem, out idCard))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
// check entity itself
|
|
if (TryGetIdCard(uid, out idCard))
|
|
return true;
|
|
|
|
// check inventory slot?
|
|
if (_inventorySystem.TryGetSlotEntity(uid, "id", out var idUid) && TryGetIdCard(idUid.Value, out idCard))
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempt to get an id card component from an entity, either by getting it directly from the entity, or by
|
|
/// getting the contained id from a <see cref="PdaComponent"/>.
|
|
/// </summary>
|
|
public bool TryGetIdCard(EntityUid uid, out Entity<IdCardComponent> idCard)
|
|
{
|
|
if (TryComp(uid, out IdCardComponent? idCardComp))
|
|
{
|
|
idCard = (uid, idCardComp);
|
|
return true;
|
|
}
|
|
|
|
if (TryComp(uid, out PdaComponent? pda)
|
|
&& TryComp(pda.ContainedId, out idCardComp))
|
|
{
|
|
idCard = (pda.ContainedId.Value, idCardComp);
|
|
return true;
|
|
}
|
|
|
|
idCard = default;
|
|
return false;
|
|
}
|
|
|
|
/// <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.
|
|
/// Actually works with the LocalizedJobTitle DataField and not with JobTitle.
|
|
/// </remarks>
|
|
public bool TryChangeJobTitle(EntityUid uid, string? jobTitle, IdCardComponent? id = null, EntityUid? player = null)
|
|
{
|
|
if (!Resolve(uid, ref id))
|
|
return false;
|
|
|
|
if (!string.IsNullOrWhiteSpace(jobTitle))
|
|
{
|
|
jobTitle = jobTitle.Trim();
|
|
|
|
if (jobTitle.Length > IdCardConsoleComponent.MaxJobTitleLength)
|
|
jobTitle = jobTitle[..IdCardConsoleComponent.MaxJobTitleLength];
|
|
}
|
|
else
|
|
{
|
|
jobTitle = null;
|
|
}
|
|
|
|
if (id.LocalizedJobTitle == jobTitle)
|
|
return true;
|
|
id.LocalizedJobTitle = jobTitle;
|
|
Dirty(uid, id);
|
|
UpdateEntityName(uid, id);
|
|
|
|
if (player != null)
|
|
{
|
|
_adminLogger.Add(LogType.Identity, LogImpact.Low,
|
|
$"{ToPrettyString(player.Value):player} has changed the job title of {ToPrettyString(uid):entity} to {jobTitle} ");
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool TryChangeJobIcon(EntityUid uid, JobIconPrototype jobIcon, IdCardComponent? id = null, EntityUid? player = null)
|
|
{
|
|
if (!Resolve(uid, ref id))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (id.JobIcon == jobIcon.ID)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
id.JobIcon = jobIcon.ID;
|
|
Dirty(uid, id);
|
|
|
|
if (player != null)
|
|
{
|
|
_adminLogger.Add(LogType.Identity, LogImpact.Low,
|
|
$"{ToPrettyString(player.Value):player} has changed the job icon of {ToPrettyString(uid):entity} to {jobIcon} ");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool TryChangeJobDepartment(EntityUid uid, JobPrototype job, IdCardComponent? id = null)
|
|
{
|
|
if (!Resolve(uid, ref id))
|
|
return false;
|
|
|
|
id.JobDepartments.Clear();
|
|
foreach (var department in _prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
|
|
{
|
|
if (department.Roles.Contains(job.ID))
|
|
id.JobDepartments.Add(department.ID);
|
|
}
|
|
|
|
Dirty(uid, id);
|
|
|
|
return true;
|
|
}
|
|
|
|
// Sunrise-Start
|
|
public bool TryChangeJobColor(EntityUid uid, string? jobColor, bool boldRadio = false, IdCardComponent? id = null, EntityUid? player = null)
|
|
{
|
|
if (!Resolve(uid, ref id))
|
|
return false;
|
|
|
|
if (id.JobColor == jobColor && id.RadioBold == boldRadio)
|
|
return true;
|
|
|
|
id.JobColor = jobColor;
|
|
id.RadioBold = boldRadio;
|
|
UpdateEntityName(uid, id);
|
|
|
|
if (player != null)
|
|
{
|
|
_adminLogger.Add(LogType.Identity, LogImpact.Low,
|
|
$"{ToPrettyString(player.Value):player} has changed the job color of {ToPrettyString(uid):entity} to {jobColor} ");
|
|
}
|
|
|
|
Dirty(uid, id);
|
|
|
|
return true;
|
|
}
|
|
|
|
public string GetJobColor(IPrototypeManager prototypeManager, IPrototype job)
|
|
{
|
|
var jobCode = job.ID;
|
|
|
|
var departments = prototypeManager.EnumeratePrototypes<DepartmentPrototype>().ToList();
|
|
departments.Sort((a, b) => a.Sort.CompareTo(b.Sort));
|
|
|
|
foreach (var department in from department in departments
|
|
from jobId in department.Roles
|
|
where jobId == jobCode
|
|
select department)
|
|
{
|
|
return department.Color.ToHex();
|
|
}
|
|
|
|
return string.Empty;
|
|
}
|
|
// Sunrise-End
|
|
|
|
/// <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;
|
|
|
|
if (!string.IsNullOrWhiteSpace(fullName))
|
|
{
|
|
fullName = fullName.Trim();
|
|
if (fullName.Length > IdCardConsoleComponent.MaxFullNameLength)
|
|
fullName = fullName[..IdCardConsoleComponent.MaxFullNameLength];
|
|
}
|
|
else
|
|
{
|
|
fullName = null;
|
|
}
|
|
|
|
if (id.FullName == fullName)
|
|
return true;
|
|
id.FullName = fullName;
|
|
Dirty(uid, id);
|
|
UpdateEntityName(uid, id);
|
|
|
|
if (player != null)
|
|
{
|
|
_adminLogger.Add(LogType.Identity, LogImpact.Low,
|
|
$"{ToPrettyString(player.Value):player} has changed the name of {ToPrettyString(uid):entity} to {fullName} ");
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Changes the name of the id's owner.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// If either <see cref="FullName"/> or <see cref="JobTitle"/> is empty, it's replaced by placeholders.
|
|
/// If both are empty, the original entity's name is restored.
|
|
/// </remarks>
|
|
private void UpdateEntityName(EntityUid uid, IdCardComponent? id = null)
|
|
{
|
|
if (!Resolve(uid, ref id))
|
|
return;
|
|
|
|
var jobSuffix = string.IsNullOrWhiteSpace(id.LocalizedJobTitle) ? string.Empty : $" ({id.LocalizedJobTitle})";
|
|
|
|
var val = string.IsNullOrWhiteSpace(id.FullName)
|
|
? Loc.GetString(id.NameLocId,
|
|
("jobSuffix", jobSuffix))
|
|
: Loc.GetString(id.FullNameLocId,
|
|
("fullName", id.FullName),
|
|
("jobSuffix", jobSuffix));
|
|
_metaSystem.SetEntityName(uid, val);
|
|
}
|
|
|
|
private static string ExtractFullTitle(IdCardComponent idCardComponent)
|
|
{
|
|
return $"{idCardComponent.FullName} ({CultureInfo.CurrentCulture.TextInfo.ToTitleCase(idCardComponent.LocalizedJobTitle ?? string.Empty)})"
|
|
.Trim();
|
|
}
|
|
|
|
public void SetExpireTime(Entity<ExpireIdCardComponent?> ent, TimeSpan time)
|
|
{
|
|
if (!Resolve(ent, ref ent.Comp))
|
|
return;
|
|
ent.Comp.ExpireTime = time;
|
|
Dirty(ent);
|
|
}
|
|
|
|
public void SetPermanent(Entity<ExpireIdCardComponent?> ent, bool val)
|
|
{
|
|
if (!Resolve(ent, ref ent.Comp))
|
|
return;
|
|
ent.Comp.Permanent = val;
|
|
Dirty(ent);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Marks an <see cref="ExpireIdCardComponent"/> as expired, setting the accesses.
|
|
/// </summary>
|
|
public virtual void ExpireId(Entity<ExpireIdCardComponent> ent)
|
|
{
|
|
if (ent.Comp.Expired)
|
|
return;
|
|
|
|
_access.TrySetTags(ent, ent.Comp.ExpiredAccess);
|
|
ent.Comp.Expired = true;
|
|
Dirty(ent);
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
var query = EntityQueryEnumerator<ExpireIdCardComponent>();
|
|
while (query.MoveNext(out var uid, out var comp))
|
|
{
|
|
if (comp.Expired || comp.Permanent)
|
|
continue;
|
|
|
|
if (_timing.CurTime < comp.ExpireTime)
|
|
continue;
|
|
|
|
ExpireId((uid, comp));
|
|
}
|
|
}
|
|
}
|