Remove outdated access reader method. (#19765)
This commit is contained in:
@@ -53,7 +53,7 @@ public sealed class AccessReaderSystem : EntitySystem
|
||||
{
|
||||
if (args.User == null) // AutoLink (and presumably future external linkers) have no user.
|
||||
return;
|
||||
if (!HasComp<EmaggedComponent>(uid) && !IsAllowed(args.User.Value, component))
|
||||
if (!HasComp<EmaggedComponent>(uid) && !IsAllowed(args.User.Value, uid, component))
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
@@ -64,80 +64,65 @@ public sealed class AccessReaderSystem : EntitySystem
|
||||
Dirty(reader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds all AccessReaderComponents in the container of the
|
||||
/// required entity.
|
||||
/// </summary>
|
||||
/// <param name="target">The entity to search for a container</param>
|
||||
/// <param name="accessReader"></param>
|
||||
/// <param name="result"></param>
|
||||
private bool FindAccessReadersInContainer(EntityUid target, AccessReaderComponent accessReader, out List<AccessReaderComponent> result)
|
||||
{
|
||||
result = new();
|
||||
if (accessReader.ContainerAccessProvider == null)
|
||||
return false;
|
||||
|
||||
if (!_containerSystem.TryGetContainer(target, accessReader.ContainerAccessProvider, out var container))
|
||||
return false;
|
||||
|
||||
foreach (var entity in container.ContainedEntities)
|
||||
{
|
||||
if (TryComp<AccessReaderComponent>(entity, out var entityAccessReader))
|
||||
result.Add(entityAccessReader);
|
||||
}
|
||||
|
||||
return result.Any();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches the source for access tags
|
||||
/// then compares it with the all targets accesses to see if it is allowed.
|
||||
/// </summary>
|
||||
/// <param name="source">The entity that wants access.</param>
|
||||
/// <param name="user">The entity that wants access.</param>
|
||||
/// <param name="target">The entity to search for an access reader</param>
|
||||
/// <param name="reader">Optional reader from the target entity</param>
|
||||
public bool IsAllowed(EntityUid source, EntityUid target, AccessReaderComponent? reader = null)
|
||||
public bool IsAllowed(EntityUid user, EntityUid target, AccessReaderComponent? reader = null)
|
||||
{
|
||||
if (!Resolve(target, ref reader, false))
|
||||
return true;
|
||||
|
||||
if (FindAccessReadersInContainer(target, reader, out var accessReaderList))
|
||||
{
|
||||
foreach (var access in accessReaderList)
|
||||
{
|
||||
if (IsAllowed(source, access))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return IsAllowed(source, reader);
|
||||
}
|
||||
/// <summary>
|
||||
/// Searches the given entity for access tags
|
||||
/// then compares it with the readers access list to see if it is allowed.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity that wants access.</param>
|
||||
/// <param name="reader">A reader from a different entity</param>
|
||||
public bool IsAllowed(EntityUid entity, AccessReaderComponent reader)
|
||||
{
|
||||
// Access reader is totally disabled, so access is always allowed.
|
||||
if (!reader.Enabled)
|
||||
return true;
|
||||
|
||||
var allEnts = FindPotentialAccessItems(entity);
|
||||
var accessSources = FindPotentialAccessItems(user);
|
||||
var access = FindAccessTags(user, accessSources);
|
||||
FindStationRecordKeys(user, out var stationKeys, accessSources);
|
||||
|
||||
if (AreAccessTagsAllowed(FindAccessTags(entity, allEnts), reader))
|
||||
return IsAllowed(access, stationKeys, target, reader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the given access permissions satisfy an access reader's requirements.
|
||||
/// </summary>
|
||||
public bool IsAllowed(
|
||||
ICollection<string> access,
|
||||
ICollection<StationRecordKey> stationKeys,
|
||||
EntityUid target,
|
||||
AccessReaderComponent reader)
|
||||
{
|
||||
if (!reader.Enabled)
|
||||
return true;
|
||||
|
||||
if (FindStationRecordKeys(entity, out var recordKeys, allEnts)
|
||||
&& AreStationRecordKeysAllowed(recordKeys, reader))
|
||||
return true;
|
||||
if (reader.ContainerAccessProvider == null)
|
||||
return IsAllowedInternal(access, stationKeys, reader);
|
||||
|
||||
if (!_containerSystem.TryGetContainer(target, reader.ContainerAccessProvider, out var container))
|
||||
return false;
|
||||
|
||||
foreach (var entity in container.ContainedEntities)
|
||||
{
|
||||
if (!TryComp(entity, out AccessReaderComponent? containedReader))
|
||||
continue;
|
||||
|
||||
if (IsAllowed(access, stationKeys, entity, containedReader))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsAllowedInternal(ICollection<string> access, ICollection<StationRecordKey> stationKeys, AccessReaderComponent reader)
|
||||
{
|
||||
return !reader.Enabled
|
||||
|| AreAccessTagsAllowed(access, reader)
|
||||
|| AreStationRecordKeysAllowed(stationKeys, reader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares the given tags with the readers access list to see if it is allowed.
|
||||
/// </summary>
|
||||
@@ -155,7 +140,16 @@ public sealed class AccessReaderSystem : EntitySystem
|
||||
return false;
|
||||
}
|
||||
|
||||
return reader.AccessLists.Count == 0 || reader.AccessLists.Any(a => a.IsSubsetOf(accessTags));
|
||||
if (reader.AccessLists.Count == 0)
|
||||
return true;
|
||||
|
||||
foreach (var set in reader.AccessLists)
|
||||
{
|
||||
if (set.IsSubsetOf(accessTags))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -163,7 +157,13 @@ public sealed class AccessReaderSystem : EntitySystem
|
||||
/// </summary>
|
||||
public bool AreStationRecordKeysAllowed(ICollection<StationRecordKey> keys, AccessReaderComponent reader)
|
||||
{
|
||||
return keys.Any() && reader.AccessKeys.Any(keys.Contains);
|
||||
foreach (var key in reader.AccessKeys)
|
||||
{
|
||||
if (keys.Contains(key))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user