Device network DeviceLists and the NetworkConfigurator (Makes air alarms usable) (#7697)

* Implement DeviceList
Implement NetworkConfigurator
I sould really get into the habit of making smaller commits

* Remove ApcNetworkComponent from vents, scrubbers anf firelocks

* Change BeforeBroadcastAttemptEvent#Recepients to readonly IReadonlySet and add a ModifiedRecepients field

* Address revievs in NetworkConfigurationSystem

* Fix red and green button styles

* Change NetworkConfiguratorSystem#UpdateState to remove saved entites that don't exist anymore

* Add AtmosDevices device net id

* Add const strings for style classes
Fix wrong margin for NetworkConfiguratorConfigurationMenu

* Hello? Github?

* Add access check before opening the configuration ui

* Address reviews

* Fix call to access reader

* You shall not live again IgnoreComponent

* Fix interaction verb check

* Fix configuration window not closing when target gets deleted / out of range

* Change device is already saved message to say 'network device: ... is already saves'

* Apply suggestions from code review

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>

* Fix applied suggestion

Co-authored-by: wrexbe <81056464+wrexbe@users.noreply.github.com>
Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
This commit is contained in:
Julian Giebel
2022-06-10 03:28:24 +02:00
committed by GitHub
parent 0fc8c0ef5e
commit f4be8b5793
20 changed files with 836 additions and 14 deletions

View File

@@ -51,7 +51,7 @@ namespace Content.Server.DeviceNetwork.Systems
if (!Resolve(uid, ref device, false))
return;
if (device.Address == null)
if (device.Address == string.Empty)
return;
frequency ??= device.TransmitFrequency;
@@ -194,7 +194,8 @@ namespace Content.Server.DeviceNetwork.Systems
var network = GetNetwork(packet.NetId);
if (packet.Address == null)
{
if (network.ListeningDevices.TryGetValue(packet.Frequency, out var devices))
// Broadcast to all listening devices
if (network.ListeningDevices.TryGetValue(packet.Frequency, out var devices) && CheckRecipientsList(packet, ref devices))
{
var deviceCopy = ArrayPool<DeviceNetworkComponent>.Shared.Rent(devices.Count);
devices.CopyTo(deviceCopy);
@@ -231,6 +232,30 @@ namespace Content.Server.DeviceNetwork.Systems
}
}
/// <summary>
/// Sends the <see cref="BeforeBroadcastAttemptEvent"/> to the sending entity if the packets SendBeforeBroadcastAttemptEvent field is set to true.
/// The recipients is set to the modified recipient list.
/// </summary>
/// <returns>false if the broadcast was canceled</returns>
private bool CheckRecipientsList(DeviceNetworkPacketEvent packet, ref HashSet<DeviceNetworkComponent> recipients)
{
if (!_networks.ContainsKey(packet.NetId) || !_networks[packet.NetId].Devices.ContainsKey(packet.SenderAddress))
return false;
var sender = _networks[packet.NetId].Devices[packet.SenderAddress];
if (!sender.SendBroadcastAttemptEvent)
return true;
var beforeBroadcastAttemptEvent = new BeforeBroadcastAttemptEvent(recipients);
RaiseLocalEvent(packet.Sender, beforeBroadcastAttemptEvent);
if (beforeBroadcastAttemptEvent.Cancelled || beforeBroadcastAttemptEvent.ModifiedRecipients == null)
return false;
recipients = beforeBroadcastAttemptEvent.ModifiedRecipients;
return true;
}
private void SendToConnections(ReadOnlySpan<DeviceNetworkComponent> connections, DeviceNetworkPacketEvent packet)
{
var xform = Transform(packet.Sender);
@@ -278,6 +303,20 @@ namespace Content.Server.DeviceNetwork.Systems
}
}
/// <summary>
/// Sent to the sending entity before broadcasting network packets to recipients
/// </summary>
public sealed class BeforeBroadcastAttemptEvent : CancellableEntityEventArgs
{
public readonly IReadOnlySet<DeviceNetworkComponent> Recipients;
public HashSet<DeviceNetworkComponent>? ModifiedRecipients;
public BeforeBroadcastAttemptEvent(IReadOnlySet<DeviceNetworkComponent> recipients)
{
Recipients = recipients;
}
}
/// <summary>
/// Event raised when a device network packet gets sent.
/// </summary>