using Content.Server.DeviceNetwork.Components; using JetBrains.Annotations; namespace Content.Server.DeviceNetwork.Systems { [UsedImplicitly] public sealed class WirelessNetworkSystem : EntitySystem { [Dependency] private readonly SharedTransformSystem _xformSystem = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnBeforePacketSent); } /// /// Gets the position of both the sending and receiving entity and checks if the receiver is in range of the sender. /// private void OnBeforePacketSent(EntityUid uid, WirelessNetworkComponent component, BeforePacketSentEvent args) { var ownPosition = args.SenderPosition; var xform = Transform(uid); // not a wireless to wireless connection, just let it happen if (!TryComp(args.Sender, out var sendingComponent)) return; if (xform.MapID != args.SenderTransform.MapID || (ownPosition - _xformSystem.GetWorldPosition(xform)).Length() > sendingComponent.Range) { args.Cancel(); } } } }