Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent borgs unlocking eachother and robotics console #27888

Merged
merged 21 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Content.Shared/Lock/LockSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public bool CanToggleLock(EntityUid uid, EntityUid user, bool quiet = true)

var ev = new LockToggleAttemptEvent(user, quiet);
RaiseLocalEvent(uid, ref ev, true);
RaiseLocalEvent(user, ref ev, true);
return !ev.Cancelled;
}

Expand Down
17 changes: 17 additions & 0 deletions Content.Shared/Lock/LockingWhitelistComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Content.Shared.Whitelist;
using Robust.Shared.GameStates;

namespace Content.Shared.Lock;

/// <summary>
/// Adds whitelist and blacklist for this mob to lock things.
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(LockingWhitelistSystem))]
public sealed partial class LockingWhitelistComponent : Component
{
[DataField]
public EntityWhitelist? Whitelist;

[DataField]
public EntityWhitelist? Blacklist;
}
21 changes: 21 additions & 0 deletions Content.Shared/Lock/LockingWhitelistSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Content.Shared.Whitelist;

namespace Content.Shared.Lock;

public sealed class LockingWhitelistSystem : EntitySystem
{
[Dependency] private readonly EntityWhitelistSystem _whitelist = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<LockingWhitelistComponent, LockToggleAttemptEvent>(OnLockToggleAttempt);
}

private void OnLockToggleAttempt(Entity<LockingWhitelistComponent> ent, ref LockToggleAttemptEvent args)
{
if (args.User == ent.Owner && !_whitelist.IsAllowed(ent, ent.Comp.Blacklist, ent.Comp.Whitelist))
args.Cancelled = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public sealed partial class BorgChassisComponent : Component
[DataField("activated"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public bool Activated;

/// <summary>
/// Things the borg is not allowed to lock or unlock.
/// </summary>
[DataField]
public EntityWhitelist? LockBlacklist;

#region Brain
/// <summary>
/// A whitelist for which entities count as valid brains
Expand Down
1 change: 1 addition & 0 deletions Content.Shared/Silicons/Borgs/SharedBorgSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Shared.Access.Components;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Lock;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Systems;
using Content.Shared.Popups;
Expand Down
36 changes: 36 additions & 0 deletions Content.Shared/Whitelist/EntityWhitelistSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,42 @@ public bool IsValid(EntityWhitelist list, [NotNullWhen(true)] EntityUid? uid)
return uid != null && IsValid(list, uid.Value);
}

/// <summary>
/// Checks whether a given entity satisfies a whitelist.
/// If the whitelist is null it returns null.
/// </summary>
public bool? Match(EntityWhitelist? list, [NotNullWhen(true)] EntityUid? uid)
{
if (list == null)
return null;

return IsValid(list, uid);
}

/// <summary>
/// Checks whether a given entity is allowed by a whitelist and not blocked by a blacklist.
/// If a blacklist is provided and it matches then this returns false.
/// If a whitelist is provided and it does not match then this returns false.
/// If either list is null it does not get checked.
/// </summary>
public bool IsAllowed([NotNullWhen(true)] EntityUid? uid, EntityWhitelist? blacklist = null, EntityWhitelist? whitelist = null)
{
if (uid == null)
return false;

return Match(blacklist, uid) != true
&& Match(whitelist, uid) != false;
}

/// <summary>
/// Checks whether a given entity is on a blacklist.
/// If the blacklist is null it cannot be on it, so it returns false.
/// </summary>
public bool IsBlacklisted(EntityWhitelist? list, EntityUid? uid)
{
return Match(list, uid) != true;
}

/// <summary>
/// Checks whether a given entity satisfies a whitelist.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
doAfterDelay: 10
allowSelfRepair: false
- type: BorgChassis
- type: LockingWhitelist
blacklist:
components:
- BorgChassis
- RoboticsConsole
- type: WiresPanel
- type: ActivatableUIRequiresPanel
- type: NameIdentifier
Expand Down
Loading