/// <summary> /// Filters incoming packets if that is enabled <see cref="OnBeforeBroadcast"/> /// </summary> private void OnBeforePacketSent(EntityUid uid, DeviceListComponent component, BeforePacketSentEvent args) { if (component.HandleIncomingPackets && component.Devices.Contains(args.Sender) != component.IsAllowList) { args.Cancel(); } }
/// <summary> /// Checks if both devices are connected to the same apc /// </summary> private void OnBeforePacketSent(EntityUid uid, ApcNetworkComponent receiver, BeforePacketSentEvent args) { if (!EntityManager.TryGetComponent(args.Sender, out ApcNetworkComponent? sender)) { return; } if (sender.ConnectedNode?.NodeGroup == null || !sender.ConnectedNode.NodeGroup.Equals(receiver.ConnectedNode?.NodeGroup)) { args.Cancel(); } }
/// <summary> /// Gets the position of both the sending and receiving entity and checks if the receiver is in range of the sender. /// </summary> private void OnBeforePacketSent(EntityUid uid, WirelessNetworkComponent component, BeforePacketSentEvent args) { var ownPosition = EntityManager.GetComponent <TransformComponent>(component.Owner).WorldPosition; var position = EntityManager.GetComponent <TransformComponent>(args.Sender).WorldPosition; var distance = (ownPosition - position).Length; if (EntityManager.TryGetComponent <WirelessNetworkComponent?>(args.Sender, out var sendingComponent) && distance > sendingComponent.Range) { args.Cancel(); } }
/// <summary> /// Checks if both devices are on the same grid /// </summary> private void OnBeforePacketSent(EntityUid uid, WiredNetworkComponent component, BeforePacketSentEvent args) { if (EntityManager.GetComponent <TransformComponent>(uid).GridUid != args.SenderTransform.GridUid) { args.Cancel(); } }
/// <summary> /// Gets the position of both the sending and receiving entity and checks if the receiver is in range of the sender. /// </summary> private void OnBeforePacketSent(EntityUid uid, WirelessNetworkComponent component, BeforePacketSentEvent args) { var ownPosition = args.SenderPosition; var xform = Transform(uid); if (xform.MapID != args.SenderTransform.MapID || !TryComp <WirelessNetworkComponent?>(args.Sender, out var sendingComponent) || (ownPosition - xform.WorldPosition).Length > sendingComponent.Range) { args.Cancel(); } }
/// <summary> /// Checks if both devices are on the same grid /// </summary> private void OnBeforePacketSent(EntityUid uid, WiredNetworkComponent component, BeforePacketSentEvent args) { IEntity sender = EntityManager.GetEntity(args.Sender); IEntity receiver = EntityManager.GetEntity(uid); if (receiver.Transform.GridID != sender.Transform.GridID) { args.Cancel(); } }