Create DeviceNetworkJammerComponent & System as a general way for entities 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
This commit is contained in:
@@ -351,13 +351,14 @@ namespace Content.Server.DeviceNetwork.Systems
|
||||
|
||||
var xform = Transform(packet.Sender);
|
||||
|
||||
BeforePacketSentEvent beforeEv = new(packet.Sender, xform, _transformSystem.GetWorldPosition(xform));
|
||||
var senderPos = _transformSystem.GetWorldPosition(xform);
|
||||
|
||||
foreach (var connection in connections)
|
||||
{
|
||||
if (connection.Owner == packet.Sender)
|
||||
continue;
|
||||
|
||||
BeforePacketSentEvent beforeEv = new(packet.Sender, xform, senderPos, connection.NetIdEnum.ToString());
|
||||
RaiseLocalEvent(connection.Owner, beforeEv, false);
|
||||
|
||||
if (!beforeEv.Cancelled)
|
||||
@@ -386,11 +387,17 @@ namespace Content.Server.DeviceNetwork.Systems
|
||||
/// </summary>
|
||||
public readonly Vector2 SenderPosition;
|
||||
|
||||
public BeforePacketSentEvent(EntityUid sender, TransformComponent xform, Vector2 senderPosition)
|
||||
/// <summary>
|
||||
/// The network the packet will be sent to.
|
||||
/// </summary>
|
||||
public readonly string NetworkId;
|
||||
|
||||
public BeforePacketSentEvent(EntityUid sender, TransformComponent xform, Vector2 senderPosition, string networkId)
|
||||
{
|
||||
Sender = sender;
|
||||
SenderTransform = xform;
|
||||
SenderPosition = senderPosition;
|
||||
NetworkId = networkId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user