Clear and reregister devices for atmos alarms (#11391)
* deregister sensors upon device list update and re-register after clearing devices * fire alarms, too * adds the last set of known devices to the device list update event * update UI upon clearing everything out * addresses reviews
This commit is contained in:
@@ -168,6 +168,24 @@ public sealed class AirAlarmSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnDeviceListUpdate(EntityUid uid, AirAlarmComponent component, DeviceListUpdateEvent args)
|
private void OnDeviceListUpdate(EntityUid uid, AirAlarmComponent component, DeviceListUpdateEvent args)
|
||||||
{
|
{
|
||||||
|
var query = GetEntityQuery<DeviceNetworkComponent>();
|
||||||
|
foreach (var device in args.OldDevices)
|
||||||
|
{
|
||||||
|
if (!query.TryGetComponent(device, out var deviceNet))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
_atmosDevNetSystem.Deregister(uid, deviceNet.Address);
|
||||||
|
}
|
||||||
|
|
||||||
|
component.ScrubberData.Clear();
|
||||||
|
component.SensorData.Clear();
|
||||||
|
component.VentData.Clear();
|
||||||
|
component.KnownDevices.Clear();
|
||||||
|
|
||||||
|
UpdateUI(uid, component);
|
||||||
|
|
||||||
SyncRegisterAllDevices(uid);
|
SyncRegisterAllDevices(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,8 +312,8 @@ public sealed class AirAlarmSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
var addr = string.Empty;
|
var addr = string.Empty;
|
||||||
if (EntityManager.TryGetComponent(uid, out DeviceNetworkComponent? netConn)) addr = netConn.Address;
|
if (EntityManager.TryGetComponent(uid, out DeviceNetworkComponent? netConn))
|
||||||
|
addr = netConn.Address;
|
||||||
|
|
||||||
if (args.AlarmType == AtmosAlarmType.Danger)
|
if (args.AlarmType == AtmosAlarmType.Danger)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ public sealed class AtmosDeviceNetworkSystem : EntitySystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const string RegisterDevice = "atmos_register_device";
|
public const string RegisterDevice = "atmos_register_device";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deregister a device's address on this device.
|
||||||
|
/// </summary>
|
||||||
|
public const string DeregisterDevice = "atmos_deregister_device";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Synchronize the data this device has with the sender.
|
/// Synchronize the data this device has with the sender.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -32,6 +37,16 @@ public sealed class AtmosDeviceNetworkSystem : EntitySystem
|
|||||||
_deviceNet.QueuePacket(uid, address, registerPayload);
|
_deviceNet.QueuePacket(uid, address, registerPayload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Deregister(EntityUid uid, string? address)
|
||||||
|
{
|
||||||
|
var deregisterPayload = new NetworkPayload
|
||||||
|
{
|
||||||
|
[DeviceNetworkConstants.Command] = DeregisterDevice
|
||||||
|
};
|
||||||
|
|
||||||
|
_deviceNet.QueuePacket(uid, address, deregisterPayload);
|
||||||
|
}
|
||||||
|
|
||||||
public void Sync(EntityUid uid, string? address)
|
public void Sync(EntityUid uid, string? address)
|
||||||
{
|
{
|
||||||
var syncPayload = new NetworkPayload
|
var syncPayload = new NetworkPayload
|
||||||
|
|||||||
@@ -98,6 +98,9 @@ public sealed class AtmosMonitorSystem : EntitySystem
|
|||||||
case AtmosDeviceNetworkSystem.RegisterDevice:
|
case AtmosDeviceNetworkSystem.RegisterDevice:
|
||||||
component.RegisteredDevices.Add(args.SenderAddress);
|
component.RegisteredDevices.Add(args.SenderAddress);
|
||||||
break;
|
break;
|
||||||
|
case AtmosDeviceNetworkSystem.DeregisterDevice:
|
||||||
|
component.RegisteredDevices.Remove(args.SenderAddress);
|
||||||
|
break;
|
||||||
case AtmosAlarmableSystem.ResetAll:
|
case AtmosAlarmableSystem.ResetAll:
|
||||||
Reset(uid);
|
Reset(uid);
|
||||||
// Don't clear alarm states here.
|
// Don't clear alarm states here.
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Content.Server.AlertLevel;
|
using Content.Server.AlertLevel;
|
||||||
using Content.Server.Atmos.Monitor.Components;
|
using Content.Server.Atmos.Monitor.Components;
|
||||||
|
using Content.Server.DeviceNetwork.Components;
|
||||||
using Content.Server.DeviceNetwork.Systems;
|
using Content.Server.DeviceNetwork.Systems;
|
||||||
using Content.Server.Power.Components;
|
using Content.Server.Power.Components;
|
||||||
using Content.Server.Power.EntitySystems;
|
using Content.Server.Power.EntitySystems;
|
||||||
@@ -32,6 +33,17 @@ public sealed class FireAlarmSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnDeviceListSync(EntityUid uid, FireAlarmComponent component, DeviceListUpdateEvent args)
|
private void OnDeviceListSync(EntityUid uid, FireAlarmComponent component, DeviceListUpdateEvent args)
|
||||||
{
|
{
|
||||||
|
var query = GetEntityQuery<DeviceNetworkComponent>();
|
||||||
|
foreach (var device in args.OldDevices)
|
||||||
|
{
|
||||||
|
if (!query.TryGetComponent(device, out var deviceNet))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
_atmosDevNet.Deregister(uid, deviceNet.Address);
|
||||||
|
}
|
||||||
|
|
||||||
_atmosDevNet.Register(uid, null);
|
_atmosDevNet.Register(uid, null);
|
||||||
_atmosDevNet.Sync(uid, null);
|
_atmosDevNet.Sync(uid, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public abstract class SharedDeviceListSystem : EntitySystem
|
|||||||
if (!Resolve(uid, ref deviceList))
|
if (!Resolve(uid, ref deviceList))
|
||||||
return DeviceListUpdateResult.NoComponent;
|
return DeviceListUpdateResult.NoComponent;
|
||||||
|
|
||||||
|
var oldDevices = deviceList.Devices.ToList();
|
||||||
var newDevices = merge ? new HashSet<EntityUid>(deviceList.Devices) : new();
|
var newDevices = merge ? new HashSet<EntityUid>(deviceList.Devices) : new();
|
||||||
var devicesList = devices.ToList();
|
var devicesList = devices.ToList();
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ public abstract class SharedDeviceListSystem : EntitySystem
|
|||||||
|
|
||||||
deviceList.Devices = newDevices;
|
deviceList.Devices = newDevices;
|
||||||
|
|
||||||
RaiseLocalEvent(uid, new DeviceListUpdateEvent(devicesList));
|
RaiseLocalEvent(uid, new DeviceListUpdateEvent(oldDevices, devicesList));
|
||||||
|
|
||||||
Dirty(deviceList);
|
Dirty(deviceList);
|
||||||
|
|
||||||
@@ -71,11 +72,13 @@ public abstract class SharedDeviceListSystem : EntitySystem
|
|||||||
|
|
||||||
public sealed class DeviceListUpdateEvent : EntityEventArgs
|
public sealed class DeviceListUpdateEvent : EntityEventArgs
|
||||||
{
|
{
|
||||||
public DeviceListUpdateEvent(List<EntityUid> devices)
|
public DeviceListUpdateEvent(List<EntityUid> oldDevices, List<EntityUid> devices)
|
||||||
{
|
{
|
||||||
|
OldDevices = oldDevices;
|
||||||
Devices = devices;
|
Devices = devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<EntityUid> OldDevices { get; }
|
||||||
public List<EntityUid> Devices { get; }
|
public List<EntityUid> Devices { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user