-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create DeviceNetworkJammerComponent & System as a general way for ent…
…ities to act as jammers (#26342) * Add DeviceNetworkJammerComponent & System Allows for entities to "jam" DeviceNetwork packets. Whenever a device attempts to send a packet, the DeviceNetworkJammerSystem listens for the BeforePacketSentEvent. From there if any entity with the jammer component is within range of either the sender or receiver of the packet the event will be cancelled. Additionally jammers can only block packets in certain networks. If a packet is not being transmitted in one of the networks it can block then even if the jammer is in range the event will not be cancelled. The range is stored in the jammer component along with the networks it can jam. Jammable network ids are stored as strings which seems to be how custom networks are stored (E.g. network ids for suit sensors). To allow for all of this, the BeforePacketSentEvent was modified to provide the NetworkId. * Make JammerSystem for the radio jammer use the DeviceNetworkJammer. Remove redundant event. * Replace calls to TryDistance with InRange
- Loading branch information
1 parent
49dbead
commit 266cc85
Showing
7 changed files
with
91 additions
and
25 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
Content.Server/DeviceNetwork/Systems/DeviceNetworkJammerSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Content.Server.DeviceNetwork.Components; | ||
using Content.Shared.DeviceNetwork.Components; | ||
using Robust.Server.GameObjects; | ||
|
||
namespace Content.Server.DeviceNetwork.Systems; | ||
|
||
public sealed class DeviceNetworkJammerSystem : EntitySystem | ||
{ | ||
[Dependency] private TransformSystem _transform = default!; | ||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<TransformComponent, BeforePacketSentEvent>(BeforePacketSent); | ||
} | ||
|
||
private void BeforePacketSent(EntityUid uid, TransformComponent xform, BeforePacketSentEvent ev) | ||
{ | ||
if (ev.Cancelled) | ||
return; | ||
|
||
var query = EntityQueryEnumerator<DeviceNetworkJammerComponent, TransformComponent>(); | ||
|
||
while (query.MoveNext(out _, out var jammerComp, out var jammerXform)) | ||
{ | ||
if (!jammerComp.JammableNetworks.Contains(ev.NetworkId)) | ||
continue; | ||
|
||
if (jammerXform.Coordinates.InRange(EntityManager, _transform, ev.SenderTransform.Coordinates, jammerComp.Range) | ||
|| jammerXform.Coordinates.InRange(EntityManager, _transform, xform.Coordinates, jammerComp.Range)) | ||
{ | ||
ev.Cancel(); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Content.Shared/DeviceNetwork/Components/DeviceNetworkJammerComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared.DeviceNetwork.Components; | ||
|
||
/// <summary> | ||
/// Allow entities to jam DeviceNetwork packets. | ||
/// </summary> | ||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
public sealed partial class DeviceNetworkJammerComponent : Component | ||
{ | ||
/// <summary> | ||
/// Range where packets will be jammed. This is checked both against the sender and receiver. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public float Range = 5.0f; | ||
|
||
/// <summary> | ||
/// Device networks that can be jammed. For a list of default NetworkIds see DeviceNetIdDefaults on Content.Server. | ||
/// Network ids are not guaranteed to be limited to DeviceNetIdDefaults. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public HashSet<string> JammableNetworks = []; | ||
|
||
} |