Files
tbd-station-14/Content.Server/DeviceNetwork/Systems/WirelessNetworkSystem.cs
deltanedas e837f2fd85 air alarm signal ports and other stuff (#18642)
Co-authored-by: deltanedas <@deltanedas:kde.org>
2023-08-21 14:18:30 -07: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();
}
}
}
}