Files
tbd-station-14/Content.Server/DeviceNetwork/Systems/WirelessNetworkSystem.cs
metalgearsloth a9502be29e Revert "Fix chat bubbles (#25643)" (#25645)
* Revert "Fix chat bubbles (#25643)"

This reverts commit 23d2c4d924.

* Revert "Fixes obsolete Transform warnings in Content. (#25256)"

This reverts commit f284b43ff6.
2024-02-28 00:51:20 +11:00

35 lines
1.2 KiB
C#

using Content.Server.DeviceNetwork.Components;
using JetBrains.Annotations;
namespace Content.Server.DeviceNetwork.Systems
{
[UsedImplicitly]
public sealed class WirelessNetworkSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<WirelessNetworkComponent, BeforePacketSentEvent>(OnBeforePacketSent);
}
/// <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);
// not a wireless to wireless connection, just let it happen
if (!TryComp<WirelessNetworkComponent>(args.Sender, out var sendingComponent))
return;
if (xform.MapID != args.SenderTransform.MapID
|| (ownPosition - xform.WorldPosition).Length() > sendingComponent.Range)
{
args.Cancel();
}
}
}
}