Files
tbd-station-14/Content.Server/DeviceNetwork/DeviceNetworkConnection.cs
Julian Giebel 45b610f933 Disposal mailing (#2194)
* 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>
2020-10-30 01:16:26 +01:00

73 lines
2.3 KiB
C#

using Content.Server.Interfaces;
using Robust.Shared.ViewVariables;
using System.Collections.Generic;
namespace Content.Server.GameObjects.EntitySystems.DeviceNetwork
{
public class DeviceNetworkConnection : IDeviceNetworkConnection
{
private readonly DeviceNetwork _network;
[ViewVariables]
private readonly int _netId;
[ViewVariables]
public bool Open { get; internal set; }
[ViewVariables]
public string Address { get; internal set; }
[ViewVariables]
public int Frequency { get; internal set; }
[ViewVariables]
public bool RecieveAll
{
get => _network.GetDeviceReceiveAll(_netId, Frequency, Address);
set => _network.SetDeviceReceiveAll(_netId, Frequency, Address, value);
}
public DeviceNetworkConnection(DeviceNetwork network, int netId, string address, int frequency)
{
_network = network;
_netId = netId;
Open = true;
Address = address;
Frequency = frequency;
}
public bool Send(int frequency, string address, IReadOnlyDictionary<string, string> payload, Metadata metadata)
{
return Open && _network.EnqueuePackage(_netId, frequency, address, payload, Address, metadata);
}
public bool Send(int frequency, string address, Dictionary<string, string> payload)
{
return Send(frequency, address, payload);
}
public bool Send(string address, Dictionary<string, string> payload)
{
return Send(0, address, payload);
}
public bool Broadcast(int frequency, IReadOnlyDictionary<string, string> payload, Metadata metadata)
{
return Open && _network.EnqueuePackage(_netId, frequency, "", payload, Address, metadata, true);
}
public bool Broadcast(int frequency, Dictionary<string, string> payload)
{
return Broadcast(frequency, payload);
}
public bool Broadcast(Dictionary<string, string> payload)
{
return Broadcast(0, payload);
}
public void Close()
{
_network.RemoveDevice(_netId, Frequency, Address);
Open = false;
}
}
}