diff --git a/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs b/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs index bb07a00edb..4c18165e43 100644 --- a/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs @@ -168,6 +168,24 @@ public sealed class AirAlarmSystem : EntitySystem private void OnDeviceListUpdate(EntityUid uid, AirAlarmComponent component, DeviceListUpdateEvent args) { + var query = GetEntityQuery(); + 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); } @@ -294,8 +312,8 @@ public sealed class AirAlarmSystem : EntitySystem } 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) { diff --git a/Content.Server/Atmos/Monitor/Systems/AtmosDeviceNetwork.cs b/Content.Server/Atmos/Monitor/Systems/AtmosDeviceNetwork.cs index 3190cbd37f..0b73ea5f35 100644 --- a/Content.Server/Atmos/Monitor/Systems/AtmosDeviceNetwork.cs +++ b/Content.Server/Atmos/Monitor/Systems/AtmosDeviceNetwork.cs @@ -15,6 +15,11 @@ public sealed class AtmosDeviceNetworkSystem : EntitySystem /// public const string RegisterDevice = "atmos_register_device"; + /// + /// Deregister a device's address on this device. + /// + public const string DeregisterDevice = "atmos_deregister_device"; + /// /// Synchronize the data this device has with the sender. /// @@ -32,6 +37,16 @@ public sealed class AtmosDeviceNetworkSystem : EntitySystem _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) { var syncPayload = new NetworkPayload diff --git a/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs b/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs index 18e2862bcc..24dafa8481 100644 --- a/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs @@ -98,6 +98,9 @@ public sealed class AtmosMonitorSystem : EntitySystem case AtmosDeviceNetworkSystem.RegisterDevice: component.RegisteredDevices.Add(args.SenderAddress); break; + case AtmosDeviceNetworkSystem.DeregisterDevice: + component.RegisteredDevices.Remove(args.SenderAddress); + break; case AtmosAlarmableSystem.ResetAll: Reset(uid); // Don't clear alarm states here. diff --git a/Content.Server/Atmos/Monitor/Systems/FireAlarmSystem.cs b/Content.Server/Atmos/Monitor/Systems/FireAlarmSystem.cs index fc0934aaa7..f6076821b9 100644 --- a/Content.Server/Atmos/Monitor/Systems/FireAlarmSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/FireAlarmSystem.cs @@ -1,5 +1,6 @@ using Content.Server.AlertLevel; using Content.Server.Atmos.Monitor.Components; +using Content.Server.DeviceNetwork.Components; using Content.Server.DeviceNetwork.Systems; using Content.Server.Power.Components; using Content.Server.Power.EntitySystems; @@ -32,6 +33,17 @@ public sealed class FireAlarmSystem : EntitySystem private void OnDeviceListSync(EntityUid uid, FireAlarmComponent component, DeviceListUpdateEvent args) { + var query = GetEntityQuery(); + foreach (var device in args.OldDevices) + { + if (!query.TryGetComponent(device, out var deviceNet)) + { + continue; + } + + _atmosDevNet.Deregister(uid, deviceNet.Address); + } + _atmosDevNet.Register(uid, null); _atmosDevNet.Sync(uid, null); } diff --git a/Content.Shared/DeviceNetwork/Systems/SharedDeviceListSystem.cs b/Content.Shared/DeviceNetwork/Systems/SharedDeviceListSystem.cs index 66f5cbc25a..4b4a38dcd3 100644 --- a/Content.Shared/DeviceNetwork/Systems/SharedDeviceListSystem.cs +++ b/Content.Shared/DeviceNetwork/Systems/SharedDeviceListSystem.cs @@ -24,6 +24,7 @@ public abstract class SharedDeviceListSystem : EntitySystem if (!Resolve(uid, ref deviceList)) return DeviceListUpdateResult.NoComponent; + var oldDevices = deviceList.Devices.ToList(); var newDevices = merge ? new HashSet(deviceList.Devices) : new(); var devicesList = devices.ToList(); @@ -35,7 +36,7 @@ public abstract class SharedDeviceListSystem : EntitySystem deviceList.Devices = newDevices; - RaiseLocalEvent(uid, new DeviceListUpdateEvent(devicesList)); + RaiseLocalEvent(uid, new DeviceListUpdateEvent(oldDevices, devicesList)); Dirty(deviceList); @@ -71,11 +72,13 @@ public abstract class SharedDeviceListSystem : EntitySystem public sealed class DeviceListUpdateEvent : EntityEventArgs { - public DeviceListUpdateEvent(List devices) + public DeviceListUpdateEvent(List oldDevices, List devices) { + OldDevices = oldDevices; Devices = devices; } + public List OldDevices { get; } public List Devices { get; } }