* Implement device networking * Implement device configuration menu * Fix device network * Implement disposal mailing unit * Implement base network connection Implement wired and wireless network connection Implement device network metadata * Fix dereference null error * Fix wired network null checks * Change BaseNetworks enum to NetworkUtils class Add PingResponse function to NetworkUtils Change device network file structure * Add doc comments * Apply suggestions from code review Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Add tag validation to disposal mailing unit * Add tag validation to the mailing unit component * Address reviews Change WiredNetwork can connect check Change device networking string literals to constants * Address reviews Revert changes to PowerProvider and PowerReceiver Add new NodeGroup WELP * Fix recursive access to Owner property * Integrate suggested changes * Fix TryGetWireNet acting on NullPowerProvider Fix network connections not checking if their owner has been deleted * Close device network connection when the owning entity got deleted Fix mailing unit not closing the device network connection on remove * Remove GetWireNet from NullPowerProvider Co-authored-by: Julian Giebel <j.giebel@netrocks.info> Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
119 lines
3.9 KiB
C#
119 lines
3.9 KiB
C#
using Content.Server.GameObjects.Components.Interactable;
|
|
using Content.Server.Utility;
|
|
using Content.Shared.GameObjects.Components;
|
|
using Content.Shared.GameObjects.Components.Interactable;
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
|
using Robust.Server.GameObjects.Components.UserInterface;
|
|
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;
|
|
|
|
namespace Content.Server.GameObjects.Components
|
|
{
|
|
[RegisterComponent]
|
|
[ComponentReference(typeof(SharedConfigurationComponent))]
|
|
public class ConfigurationComponent : SharedConfigurationComponent, IInteractUsing
|
|
{
|
|
[ViewVariables] private BoundUserInterface UserInterface => Owner.GetUIOrNull(ConfigurationUiKey.Key);
|
|
|
|
[ViewVariables]
|
|
private readonly Dictionary<string, string> _config = new Dictionary<string, string>();
|
|
|
|
private Regex _validation;
|
|
|
|
public event Action<Dictionary<string, string>> OnConfigUpdate;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
if (UserInterface != null)
|
|
{
|
|
UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
|
|
}
|
|
}
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
{
|
|
base.ExposeData(serializer);
|
|
|
|
serializer.DataReadWriteFunction("keys", new List<string>(),
|
|
(list) => FillConfiguration(list, _config, ""),
|
|
() => _config.Keys.ToList());
|
|
|
|
serializer.DataReadFunction("vailidation", "^[a-zA-Z0-9 ]*$", value => _validation = new Regex("^[a-zA-Z0-9 ]*$", RegexOptions.Compiled));
|
|
}
|
|
|
|
public string GetConfig(string name)
|
|
{
|
|
return _config.GetValueOrDefault(name);
|
|
}
|
|
|
|
protected override void Startup()
|
|
{
|
|
base.Startup();
|
|
UpdateUserInterface();
|
|
}
|
|
|
|
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
|
{
|
|
if (UserInterface == null || !eventArgs.User.TryGetComponent(out IActorComponent actor))
|
|
return false;
|
|
|
|
if (!eventArgs.Using.TryGetComponent<ToolComponent>(out var tool))
|
|
return false;
|
|
|
|
if (!await tool.UseTool(eventArgs.User, Owner, 0.2f, ToolQuality.Multitool))
|
|
return false;
|
|
|
|
UpdateUserInterface();
|
|
UserInterface.Open(actor.playerSession);
|
|
UserInterface.SendMessage(new ValidationUpdateMessage(_validation.ToString()), actor.playerSession);
|
|
return true;
|
|
}
|
|
|
|
private void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage serverMsg)
|
|
{
|
|
var message = serverMsg.Message;
|
|
var config = new Dictionary<string, string>(_config);
|
|
|
|
if (message is ConfigurationUpdatedMessage msg)
|
|
{
|
|
foreach (var key in config.Keys)
|
|
{
|
|
var value = msg.Config.GetValueOrDefault(key);
|
|
|
|
if (_validation != null && !_validation.IsMatch(value) && value != "")
|
|
continue;
|
|
|
|
_config[key] = value;
|
|
}
|
|
|
|
OnConfigUpdate(_config);
|
|
}
|
|
}
|
|
|
|
private void UpdateUserInterface()
|
|
{
|
|
if (UserInterface == null)
|
|
return;
|
|
|
|
UserInterface.SetState(new ConfigurationBoundUserInterfaceState(_config));
|
|
}
|
|
|
|
private static void FillConfiguration<T>(List<string> list, Dictionary<string, T> configuration, T value){
|
|
for (var index = 0; index < list.Count; index++)
|
|
{
|
|
configuration.Add(list[index], value);
|
|
}
|
|
}
|
|
}
|
|
}
|