diff --git a/Content.Client/GameObjects/Components/Configuration/ConfigurationBoundUserInterface.cs b/Content.Client/GameObjects/Components/Configuration/ConfigurationBoundUserInterface.cs index d173f061ed..97bcdf20b6 100644 --- a/Content.Client/GameObjects/Components/Configuration/ConfigurationBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Configuration/ConfigurationBoundUserInterface.cs @@ -49,6 +49,7 @@ namespace Content.Client.GameObjects.Components.Wires { base.Dispose(disposing); + _menu.OnClose -= Close; _menu.Close(); } } diff --git a/Content.Server/DeviceNetwork/DeviceNetwork.cs b/Content.Server/DeviceNetwork/DeviceNetwork.cs index 414cbe9cb8..06a9f4e054 100644 --- a/Content.Server/DeviceNetwork/DeviceNetwork.cs +++ b/Content.Server/DeviceNetwork/DeviceNetwork.cs @@ -1,4 +1,5 @@ -using Content.Server.Interfaces; +using System; +using Content.Server.Interfaces; using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; using System.Collections.Generic; @@ -11,7 +12,8 @@ namespace Content.Server.GameObjects.EntitySystems.DeviceNetwork { private const int PACKAGES_PER_TICK = 30; - private readonly IRobustRandom _random = IoCManager.Resolve(); + [Dependency] private readonly IRobustRandom _random = default!; + private readonly Dictionary> _devices = new Dictionary>(); private readonly Queue _packages = new Queue(); @@ -40,11 +42,9 @@ namespace Content.Server.GameObjects.EntitySystems.DeviceNetwork public void Update() { - var i = PACKAGES_PER_TICK; - while (_packages.Count > 0 && i > 0) + var count = Math.Min(PACKAGES_PER_TICK, _packages.Count); + for (var i = 0; i < count; i++) { - i--; - var package = _packages.Dequeue(); if (package.Broadcast) @@ -72,7 +72,7 @@ namespace Content.Server.GameObjects.EntitySystems.DeviceNetwork Sender = sender, Metadata = metadata }; - + _packages.Enqueue(package); return true; } @@ -132,7 +132,7 @@ namespace Content.Server.GameObjects.EntitySystems.DeviceNetwork { var devices = DevicesForFrequency(netId, frequency); - var device = devices.Find(device => device.Address == address); + var device = devices.Find(dvc => dvc.Address == address); return device; } @@ -192,7 +192,6 @@ namespace Content.Server.GameObjects.EntitySystems.DeviceNetwork public IReadOnlyDictionary Data { get; set; } public Metadata Metadata; public string Sender; - } } } diff --git a/Content.Server/DeviceNetwork/DeviceNetworkConnection.cs b/Content.Server/DeviceNetwork/DeviceNetworkConnection.cs index 204f00edf6..9cc17e8cb1 100644 --- a/Content.Server/DeviceNetwork/DeviceNetworkConnection.cs +++ b/Content.Server/DeviceNetwork/DeviceNetworkConnection.cs @@ -11,14 +11,14 @@ namespace Content.Server.GameObjects.EntitySystems.DeviceNetwork private readonly int _netId; [ViewVariables] - public bool Open { get; internal set; } + public bool Open { get; private set; } [ViewVariables] - public string Address { get; internal set; } + public string Address { get; private set; } [ViewVariables] - public int Frequency { get; internal set; } + public int Frequency { get; private set; } [ViewVariables] - public bool RecieveAll + public bool ReceiveAll { get => _network.GetDeviceReceiveAll(_netId, Frequency, Address); set => _network.SetDeviceReceiveAll(_netId, Frequency, Address, value); diff --git a/Content.Server/GameObjects/Components/ConfigurationComponent.cs b/Content.Server/GameObjects/Components/ConfigurationComponent.cs index 77049e6260..6e468e2435 100644 --- a/Content.Server/GameObjects/Components/ConfigurationComponent.cs +++ b/Content.Server/GameObjects/Components/ConfigurationComponent.cs @@ -8,9 +8,7 @@ using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; -using System; using System.Collections.Generic; -using System.Collections.Immutable; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -28,18 +26,24 @@ namespace Content.Server.GameObjects.Components private Regex _validation; - public event Action> OnConfigUpdate; - - public override void Initialize() + public override void OnAdd() { - base.Initialize(); - + base.OnAdd(); if (UserInterface != null) { UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage; } } + public override void OnRemove() + { + base.OnRemove(); + if (UserInterface != null) + { + UserInterface.OnReceiveMessage -= UserInterfaceOnReceiveMessage; + } + } + public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); @@ -48,7 +52,7 @@ namespace Content.Server.GameObjects.Components (list) => FillConfiguration(list, _config, ""), () => _config.Keys.ToList()); - serializer.DataReadFunction("vailidation", "^[a-zA-Z0-9 ]*$", value => _validation = new Regex("^[a-zA-Z0-9 ]*$", RegexOptions.Compiled)); + serializer.DataReadFunction("validation", "^[a-zA-Z0-9 ]*$", value => _validation = new Regex("^[a-zA-Z0-9 ]*$", RegexOptions.Compiled)); } public string GetConfig(string name) @@ -90,22 +94,19 @@ namespace Content.Server.GameObjects.Components { var value = msg.Config.GetValueOrDefault(key); - if (_validation != null && !_validation.IsMatch(value) && value != "") + if (value == null || _validation != null && !_validation.IsMatch(value) && value != "") continue; _config[key] = value; } - OnConfigUpdate(_config); + SendMessage(new ConfigUpdatedComponentMessage(config)); } } private void UpdateUserInterface() { - if (UserInterface == null) - return; - - UserInterface.SetState(new ConfigurationBoundUserInterfaceState(_config)); + UserInterface?.SetState(new ConfigurationBoundUserInterfaceState(_config)); } private static void FillConfiguration(List list, Dictionary configuration, T value){ diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalMailingUnitComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalMailingUnitComponent.cs index 67cac05d66..e757fb5ace 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalMailingUnitComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalMailingUnitComponent.cs @@ -13,6 +13,7 @@ using Content.Server.GameObjects.EntitySystems.DoAfter; using Content.Server.Interfaces; using Content.Server.Interfaces.GameObjects.Components.Items; using Content.Server.Utility; +using Content.Shared.GameObjects.Components; using Content.Shared.GameObjects.Components.Body; using Content.Shared.GameObjects.Components.Disposal; using Content.Shared.GameObjects.EntitySystems; @@ -603,12 +604,7 @@ namespace Content.Server.GameObjects.Components.Disposal UserInterface.OnReceiveMessage += OnUiReceiveMessage; } - var network = IoCManager.Resolve(); _connection = new WiredNetworkConnection(OnReceiveNetMessage, false, Owner); - - if (Owner.TryGetComponent(out var configuration)) - configuration.OnConfigUpdate += OnConfigUpdate; - UpdateInterface(); } @@ -673,6 +669,9 @@ namespace Content.Server.GameObjects.Components.Disposal switch (message) { + case SharedConfigurationComponent.ConfigUpdatedComponentMessage msg: + OnConfigUpdate(msg.Config); + break; case RelayMovementEntityMessage msg: if (!msg.Entity.TryGetComponent(out HandsComponent? hands) || hands.Count == 0 || @@ -745,7 +744,7 @@ namespace Content.Server.GameObjects.Components.Disposal return false; } - // Duplicated code here, not sure how else to get actor inside to make UserInterface happy. + // Duplicated code here, not sure how else to get actor inside to make UserInterface happy. if (IsValidInteraction(eventArgs)) { diff --git a/Content.Server/GameObjects/EntitySystems/DeviceNetworkSystem.cs b/Content.Server/GameObjects/EntitySystems/DeviceNetworkSystem.cs index f5b99a5988..0708dbada4 100644 --- a/Content.Server/GameObjects/EntitySystems/DeviceNetworkSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/DeviceNetworkSystem.cs @@ -1,27 +1,16 @@ -using Content.Server.Interfaces; +using Content.Server.Interfaces; using Robust.Shared.GameObjects.Systems; using Robust.Shared.IoC; namespace Content.Server.GameObjects.EntitySystems.DeviceNetwork { - public class DeviceNetworkSystem : EntitySystem + internal sealed class DeviceNetworkSystem : EntitySystem { - private IDeviceNetwork _network; - - public override void Initialize() - { - base.Initialize(); - - _network = IoCManager.Resolve(); - } + [Dependency] private readonly IDeviceNetwork _network = default!; public override void Update(float frameTime) { base.Update(frameTime); - - if (_network == null) - return; - //(ノ°Д°)ノ︵ ┻━┻ _network.Update(); } } diff --git a/Content.Shared/GameObjects/Components/SharedConfigurationComponent.cs b/Content.Shared/GameObjects/Components/SharedConfigurationComponent.cs index 413507d3b3..590f770b62 100644 --- a/Content.Shared/GameObjects/Components/SharedConfigurationComponent.cs +++ b/Content.Shared/GameObjects/Components/SharedConfigurationComponent.cs @@ -13,21 +13,34 @@ namespace Content.Shared.GameObjects.Components [Serializable, NetSerializable] public class ConfigurationBoundUserInterfaceState : BoundUserInterfaceState { - public readonly Dictionary Config; - + public Dictionary Config { get; } + public ConfigurationBoundUserInterfaceState(Dictionary config) { Config = config; } } + /// + /// Message sent to other components on this entity when DeviceNetwork configuration updated. + /// + public class ConfigUpdatedComponentMessage : ComponentMessage + { + public Dictionary Config { get; } + + public ConfigUpdatedComponentMessage(Dictionary config) + { + Config = config; + } + } + /// /// Message data sent from client to server when the device configuration is updated. /// [Serializable, NetSerializable] public class ConfigurationUpdatedMessage : BoundUserInterfaceMessage { - public readonly Dictionary Config; + public Dictionary Config { get; } public ConfigurationUpdatedMessage(Dictionary config) { @@ -38,7 +51,7 @@ namespace Content.Shared.GameObjects.Components [Serializable, NetSerializable] public class ValidationUpdateMessage : BoundUserInterfaceMessage { - public readonly string ValidationString; + public string ValidationString { get; } public ValidationUpdateMessage(string validationString) {