Rejig Device networks (#7380)

This commit is contained in:
Leon Friedrich
2022-04-09 00:27:10 +12:00
committed by GitHub
parent 44649e7fed
commit a4d55235cc
33 changed files with 671 additions and 247 deletions

View File

@@ -1,4 +1,4 @@
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Components.Devices;
using Content.Shared.Interaction;
using Robust.Shared.GameObjects;
@@ -15,7 +15,7 @@ namespace Content.Server.DeviceNetwork.Systems.Devices
base.Initialize();
SubscribeLocalEvent<ApcNetSwitchComponent, InteractHandEvent>(OnInteracted);
SubscribeLocalEvent<ApcNetSwitchComponent, PacketSentEvent>(OnPackedReceived);
SubscribeLocalEvent<ApcNetSwitchComponent, DeviceNetworkPacketEvent>(OnPackedReceived);
}
/// <summary>
@@ -28,13 +28,16 @@ namespace Content.Server.DeviceNetwork.Systems.Devices
component.State = !component.State;
if (networkComponent.TransmitFrequency == null)
return;
var payload = new NetworkPayload
{
[DeviceNetworkConstants.Command] = DeviceNetworkConstants.CmdSetState,
[DeviceNetworkConstants.StateEnabled] = component.State,
};
_deviceNetworkSystem.QueuePacket(uid, DeviceNetworkConstants.NullAddress, networkComponent.Frequency, payload, true);
_deviceNetworkSystem.QueuePacket(uid, null, payload, device: networkComponent);
args.Handled = true;
}
@@ -42,7 +45,7 @@ namespace Content.Server.DeviceNetwork.Systems.Devices
/// <summary>
/// Listens to the <see cref="DeviceNetworkConstants.CmdSetState"/> command of other switches to sync state
/// </summary>
private void OnPackedReceived(EntityUid uid, ApcNetSwitchComponent component, PacketSentEvent args)
private void OnPackedReceived(EntityUid uid, ApcNetSwitchComponent component, DeviceNetworkPacketEvent args)
{
if (!EntityManager.TryGetComponent(uid, out DeviceNetworkComponent? networkComponent) || args.SenderAddress == networkComponent.Address) return;
if (!args.Data.TryGetValue(DeviceNetworkConstants.Command, out string? command) || command != DeviceNetworkConstants.CmdSetState) return;