Files
tbd-station-14/Content.Server/DeviceNetwork/NetworkUtils.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

39 lines
1.2 KiB
C#

using Content.Server.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
namespace Content.Server.GameObjects.EntitySystems.DeviceNetwork
{
/// <summary>
/// A collection of utilities to help with using device networks
/// </summary>
public static class NetworkUtils
{
public const int PRIVATE = 0;
public const int WIRED = 1;
public const int WIRELESS = 2;
public const string COMMAND = "command";
public const string MESSAGE = "message";
public const string PING = "ping";
/// <summary>
/// Handles responding to pings.
/// </summary>
public static void PingResponse<T>(T connection, string sender, IReadOnlyDictionary<string, string> payload, string message = "") where T : IDeviceNetworkConnection
{
if (payload.TryGetValue(COMMAND, out var command) && command == PING)
{
var response = new Dictionary<string, string>
{
{COMMAND, "ping_response"},
{MESSAGE, message}
};
connection.Send(connection.Frequency, sender, response);
}
}
}
}