ID Console can no longer grant access the privileged ID doesn't have. (read: AA nerf) (#14699)
Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -116,7 +116,7 @@ namespace Content.Client.Access.UI
|
|||||||
// this is a sussy way to do this
|
// this is a sussy way to do this
|
||||||
foreach (var access in job.Access)
|
foreach (var access in job.Access)
|
||||||
{
|
{
|
||||||
if (_accessButtons.TryGetValue(access, out var button))
|
if (_accessButtons.TryGetValue(access, out var button) && !button.Disabled)
|
||||||
{
|
{
|
||||||
button.Pressed = true;
|
button.Pressed = true;
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ namespace Content.Client.Access.UI
|
|||||||
|
|
||||||
foreach (var access in groupPrototype.Tags)
|
foreach (var access in groupPrototype.Tags)
|
||||||
{
|
{
|
||||||
if (_accessButtons.TryGetValue(access, out var button))
|
if (_accessButtons.TryGetValue(access, out var button) && !button.Disabled)
|
||||||
{
|
{
|
||||||
button.Pressed = true;
|
button.Pressed = true;
|
||||||
}
|
}
|
||||||
@@ -187,6 +187,7 @@ namespace Content.Client.Access.UI
|
|||||||
if (interfaceEnabled)
|
if (interfaceEnabled)
|
||||||
{
|
{
|
||||||
button.Pressed = state.TargetIdAccessList?.Contains(accessName) ?? false;
|
button.Pressed = state.TargetIdAccessList?.Contains(accessName) ?? false;
|
||||||
|
button.Disabled = (!state.AllowedModifyAccessList?.Contains(accessName)) ?? true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,16 +54,18 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
|
|||||||
if (!component.Initialized)
|
if (!component.Initialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var privilegedIdName = string.Empty;
|
||||||
|
string[]? possibleAccess = null;
|
||||||
|
if (component.PrivilegedIdSlot.Item is { Valid: true } item)
|
||||||
|
{
|
||||||
|
privilegedIdName = EntityManager.GetComponent<MetaDataComponent>(item).EntityName;
|
||||||
|
possibleAccess = _accessReader.FindAccessTags(item).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
IdCardConsoleBoundUserInterfaceState newState;
|
IdCardConsoleBoundUserInterfaceState newState;
|
||||||
// this could be prettier
|
// this could be prettier
|
||||||
if (component.TargetIdSlot.Item is not { Valid: true } targetId)
|
if (component.TargetIdSlot.Item is not { Valid: true } targetId)
|
||||||
{
|
{
|
||||||
var privilegedIdName = string.Empty;
|
|
||||||
if (component.PrivilegedIdSlot.Item is { Valid: true } item)
|
|
||||||
{
|
|
||||||
privilegedIdName = EntityManager.GetComponent<MetaDataComponent>(item).EntityName;
|
|
||||||
}
|
|
||||||
|
|
||||||
newState = new IdCardConsoleBoundUserInterfaceState(
|
newState = new IdCardConsoleBoundUserInterfaceState(
|
||||||
component.PrivilegedIdSlot.HasItem,
|
component.PrivilegedIdSlot.HasItem,
|
||||||
PrivilegedIdIsAuthorized(uid, component),
|
PrivilegedIdIsAuthorized(uid, component),
|
||||||
@@ -71,6 +73,7 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
possibleAccess,
|
||||||
string.Empty,
|
string.Empty,
|
||||||
privilegedIdName,
|
privilegedIdName,
|
||||||
string.Empty);
|
string.Empty);
|
||||||
@@ -79,9 +82,6 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
|
|||||||
{
|
{
|
||||||
var targetIdComponent = EntityManager.GetComponent<IdCardComponent>(targetId);
|
var targetIdComponent = EntityManager.GetComponent<IdCardComponent>(targetId);
|
||||||
var targetAccessComponent = EntityManager.GetComponent<AccessComponent>(targetId);
|
var targetAccessComponent = EntityManager.GetComponent<AccessComponent>(targetId);
|
||||||
var name = string.Empty;
|
|
||||||
if (component.PrivilegedIdSlot.Item is { Valid: true } item)
|
|
||||||
name = EntityManager.GetComponent<MetaDataComponent>(item).EntityName;
|
|
||||||
|
|
||||||
var jobProto = string.Empty;
|
var jobProto = string.Empty;
|
||||||
if (_station.GetOwningStation(uid) is { } station
|
if (_station.GetOwningStation(uid) is { } station
|
||||||
@@ -99,8 +99,9 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
|
|||||||
targetIdComponent.FullName,
|
targetIdComponent.FullName,
|
||||||
targetIdComponent.JobTitle,
|
targetIdComponent.JobTitle,
|
||||||
targetAccessComponent.Tags.ToArray(),
|
targetAccessComponent.Tags.ToArray(),
|
||||||
|
possibleAccess,
|
||||||
jobProto,
|
jobProto,
|
||||||
name,
|
privilegedIdName,
|
||||||
EntityManager.GetComponent<MetaDataComponent>(targetId).EntityName);
|
EntityManager.GetComponent<MetaDataComponent>(targetId).EntityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,16 +131,29 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
|
|||||||
|
|
||||||
if (!newAccessList.TrueForAll(x => component.AccessLevels.Contains(x)))
|
if (!newAccessList.TrueForAll(x => component.AccessLevels.Contains(x)))
|
||||||
{
|
{
|
||||||
Logger.Warning("Tried to write unknown access tag.");
|
_sawmill.Warning($"User {ToPrettyString(uid)} tried to write unknown access tag.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var oldTags = _access.TryGetTags(targetId) ?? new List<string>();
|
var oldTags = _access.TryGetTags(targetId) ?? new List<string>();
|
||||||
oldTags = oldTags.ToList();
|
oldTags = oldTags.ToList();
|
||||||
|
|
||||||
|
var privilegedId = component.PrivilegedIdSlot.Item;
|
||||||
|
|
||||||
if (oldTags.SequenceEqual(newAccessList))
|
if (oldTags.SequenceEqual(newAccessList))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// I hate that C# doesn't have an option for this and don't desire to write this out the hard way.
|
||||||
|
// var difference = newAccessList.Difference(oldTags);
|
||||||
|
var difference = (newAccessList.Union(oldTags)).Except(newAccessList.Intersect(oldTags)).ToHashSet();
|
||||||
|
// NULL SAFETY: PrivilegedIdIsAuthorized checked this earlier.
|
||||||
|
var privilegedPerms = _accessReader.FindAccessTags(privilegedId!.Value).ToHashSet();
|
||||||
|
if (!difference.IsSubsetOf(privilegedPerms))
|
||||||
|
{
|
||||||
|
_sawmill.Warning($"User {ToPrettyString(uid)} tried to modify permissions they could not give/take!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var addedTags = newAccessList.Except(oldTags).Select(tag => "+" + tag).ToList();
|
var addedTags = newAccessList.Except(oldTags).Select(tag => "+" + tag).ToList();
|
||||||
var removedTags = oldTags.Except(newAccessList).Select(tag => "-" + tag).ToList();
|
var removedTags = oldTags.Except(newAccessList).Select(tag => "-" + tag).ToList();
|
||||||
_access.TrySetTags(targetId, newAccessList);
|
_access.TrySetTags(targetId, newAccessList);
|
||||||
@@ -155,6 +169,9 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns true if there is an ID in <see cref="IdCardConsoleComponent.PrivilegedIdSlot"/> and said ID satisfies the requirements of <see cref="AccessReaderComponent"/>.
|
/// Returns true if there is an ID in <see cref="IdCardConsoleComponent.PrivilegedIdSlot"/> and said ID satisfies the requirements of <see cref="AccessReaderComponent"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Other code relies on the fact this returns false if privileged Id is null. Don't break that invariant.
|
||||||
|
/// </remarks>
|
||||||
private bool PrivilegedIdIsAuthorized(EntityUid uid, IdCardConsoleComponent? component = null)
|
private bool PrivilegedIdIsAuthorized(EntityUid uid, IdCardConsoleComponent? component = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref component))
|
if (!Resolve(uid, ref component))
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ public sealed class IdCardConsoleComponent : Component
|
|||||||
public readonly string? TargetIdFullName;
|
public readonly string? TargetIdFullName;
|
||||||
public readonly string? TargetIdJobTitle;
|
public readonly string? TargetIdJobTitle;
|
||||||
public readonly string[]? TargetIdAccessList;
|
public readonly string[]? TargetIdAccessList;
|
||||||
|
public readonly string[]? AllowedModifyAccessList;
|
||||||
public readonly string TargetIdJobPrototype;
|
public readonly string TargetIdJobPrototype;
|
||||||
|
|
||||||
public IdCardConsoleBoundUserInterfaceState(bool isPrivilegedIdPresent,
|
public IdCardConsoleBoundUserInterfaceState(bool isPrivilegedIdPresent,
|
||||||
@@ -93,6 +94,7 @@ public sealed class IdCardConsoleComponent : Component
|
|||||||
string? targetIdFullName,
|
string? targetIdFullName,
|
||||||
string? targetIdJobTitle,
|
string? targetIdJobTitle,
|
||||||
string[]? targetIdAccessList,
|
string[]? targetIdAccessList,
|
||||||
|
string[]? allowedModifyAccessList,
|
||||||
string targetIdJobPrototype,
|
string targetIdJobPrototype,
|
||||||
string privilegedIdName,
|
string privilegedIdName,
|
||||||
string targetIdName)
|
string targetIdName)
|
||||||
@@ -103,6 +105,7 @@ public sealed class IdCardConsoleComponent : Component
|
|||||||
TargetIdFullName = targetIdFullName;
|
TargetIdFullName = targetIdFullName;
|
||||||
TargetIdJobTitle = targetIdJobTitle;
|
TargetIdJobTitle = targetIdJobTitle;
|
||||||
TargetIdAccessList = targetIdAccessList;
|
TargetIdAccessList = targetIdAccessList;
|
||||||
|
AllowedModifyAccessList = allowedModifyAccessList;
|
||||||
TargetIdJobPrototype = targetIdJobPrototype;
|
TargetIdJobPrototype = targetIdJobPrototype;
|
||||||
PrivilegedIdName = privilegedIdName;
|
PrivilegedIdName = privilegedIdName;
|
||||||
TargetIdName = targetIdName;
|
TargetIdName = targetIdName;
|
||||||
|
|||||||
@@ -10,12 +10,15 @@ namespace Content.Shared.Access.Systems
|
|||||||
public abstract class SharedIdCardConsoleSystem : EntitySystem
|
public abstract class SharedIdCardConsoleSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
|
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
|
||||||
|
[Dependency] private readonly ILogManager _log = default!;
|
||||||
|
|
||||||
public const string Sawmill = "idconsole";
|
public const string Sawmill = "idconsole";
|
||||||
|
protected ISawmill _sawmill = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
_sawmill = _log.GetSawmill(Sawmill);
|
||||||
|
|
||||||
SubscribeLocalEvent<IdCardConsoleComponent, ComponentInit>(OnComponentInit);
|
SubscribeLocalEvent<IdCardConsoleComponent, ComponentInit>(OnComponentInit);
|
||||||
SubscribeLocalEvent<IdCardConsoleComponent, ComponentRemove>(OnComponentRemove);
|
SubscribeLocalEvent<IdCardConsoleComponent, ComponentRemove>(OnComponentRemove);
|
||||||
|
|||||||
@@ -409,8 +409,6 @@
|
|||||||
name: ID card computer
|
name: ID card computer
|
||||||
description: Terminal for programming Nanotrasen employee ID cards to access parts of the station.
|
description: Terminal for programming Nanotrasen employee ID cards to access parts of the station.
|
||||||
components:
|
components:
|
||||||
- type: AccessReader
|
|
||||||
access: [["HeadOfPersonnel"]]
|
|
||||||
- type: IdCardConsole
|
- type: IdCardConsole
|
||||||
privilegedIdSlot:
|
privilegedIdSlot:
|
||||||
name: id-card-console-privileged-id
|
name: id-card-console-privileged-id
|
||||||
|
|||||||
@@ -34,6 +34,19 @@
|
|||||||
- Hydroponics
|
- Hydroponics
|
||||||
- External
|
- External
|
||||||
# I mean they'll give themselves the rest of the access levels *anyways*.
|
# I mean they'll give themselves the rest of the access levels *anyways*.
|
||||||
|
# As of 15/03/23 they can't do that so here's MOST of the rest of the access levels.
|
||||||
|
# Head level access that isn't their own was deliberately left out, get AA from the captain instead.
|
||||||
|
- Chemistry
|
||||||
|
- Engineering
|
||||||
|
- Quartermaster
|
||||||
|
- Research
|
||||||
|
- Salvage
|
||||||
|
- Security
|
||||||
|
- Brig
|
||||||
|
- Cargo
|
||||||
|
- Atmospherics
|
||||||
|
- Cargo
|
||||||
|
- Medical
|
||||||
|
|
||||||
- type: startingGear
|
- type: startingGear
|
||||||
id: HoPGear
|
id: HoPGear
|
||||||
|
|||||||
Reference in New Issue
Block a user