1
0

WirelessNetworkSystem.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using Content.Server.DeviceNetwork.Components;
  2. using JetBrains.Annotations;
  3. namespace Content.Server.DeviceNetwork.Systems
  4. {
  5. [UsedImplicitly]
  6. public sealed class WirelessNetworkSystem : EntitySystem
  7. {
  8. [Dependency] private readonly SharedTransformSystem _transformSystem = default!;
  9. public override void Initialize()
  10. {
  11. base.Initialize();
  12. SubscribeLocalEvent<WirelessNetworkComponent, BeforePacketSentEvent>(OnBeforePacketSent);
  13. }
  14. /// <summary>
  15. /// Gets the position of both the sending and receiving entity and checks if the receiver is in range of the sender.
  16. /// </summary>
  17. private void OnBeforePacketSent(EntityUid uid, WirelessNetworkComponent component, BeforePacketSentEvent args)
  18. {
  19. var ownPosition = args.SenderPosition;
  20. var xform = Transform(uid);
  21. // not a wireless to wireless connection, just let it happen
  22. if (!TryComp<WirelessNetworkComponent>(args.Sender, out var sendingComponent))
  23. return;
  24. if (xform.MapID != args.SenderTransform.MapID
  25. || (ownPosition - _transformSystem.GetWorldPosition(xform)).Length() > sendingComponent.Range)
  26. {
  27. args.Cancel();
  28. }
  29. }
  30. }
  31. }