mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* Refactor DeviceNetwork * Singleton * NetworkPayloads refactor * Reorganize DeviceNetworkSystem * Surveillance cameras * Fix code * Fix build * Fix test fail by rewriting entire singleton logic * Properly predict examine * Update DeviceNetworkSystem.API.cs * Update EntityTest.cs * Update DeviceNetworkSystem.cs * Alright I'll do this expensive check fine * Fix disposals debug assert * Implement device network static events support * Use frozen dictionaries for performance * Update SharedDeviceNetworkSystem.Payloads.cs * Parallel payload handling support * Fix some spagetti-code * Optimize NetworkPayload cancellation * Parallel payloads are now cancellable * Fix screens * Fix robotics console * Allow new methods for shared * Mail fix * Turret fix * Fix network system method usage + signal and borg fix * finally fix atmos devices OH MY GOOOD * Remove stupid parallelism from fax * Fix surveiollance cameras * Working on a single thing for 2 days straight award * Fix the test? * Update units.yml * Add IDevice interface because why not * Add more device network suffixes * Fix camera router failing test * yaml linter peak * Improve docs for DeviceNetworkHandlers * fix build * Update CartridgeLoaderSystem.Relay.cs * Remove parallel system and EntitySystem post init * Add more docs and also events * Remove unnecessary caching * Update DevicePayloadComponentSystem.cs * Back to entity events * Implement DeviceData * Remove serializable from payloads * Update DeviceData.cs * Add a prototype for a singleton * Fix tests * Fix air alarms * Update DeviceNetworkSystem.cs * Fix cameras * Make camera router event-less * Fix atmos sync payloads, add more docs * Remove singleton + instant packets * oops remove public access * Fix tests? * Why the hell overload effect makes puddle sparks * Apparently it was redundant * Update gates.yml * Finish documentation * Review * Mark relay properties as obsolete * Struct payloads support (#blazinglyfastmemorysafe) * Update DeviceNetworkTest.cs * Make device structs stuff better * Move address prefix to DeviceNetworkComponent * Locale fixes * Fix tests * Doesn't know boolean logic award * Update AtmosAlarmableSystem.cs * Fix address predicted examine * Partial fix to air alarmables * Fix deployable turrets UI * Fix firelocks, maybe * Apparently Activatable UI was enough lol * Fix surveillance cameras * Rename `QueuePacket` into `SendPacket` * Simplify DeviceData as much as possible * Update DeviceData.cs * Update FaxMachineComponent.cs * Remove DeviceData because its stupid * Update ScreenSystem.cs * Fix build (camera map broken still) * Fix map * fix usings * Review changes * Build fix
232 lines
9.1 KiB
C#
232 lines
9.1 KiB
C#
using System.Numerics;
|
|
using Content.IntegrationTests.Fixtures;
|
|
using Content.Server.DeviceNetwork.Components;
|
|
using Content.Server.DeviceNetwork.Systems;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Map;
|
|
using Content.Shared.DeviceNetwork.Components;
|
|
|
|
namespace Content.IntegrationTests.Tests.DeviceNetwork
|
|
{
|
|
[TestFixture]
|
|
[TestOf(typeof(DeviceNetworkComponent))]
|
|
[TestOf(typeof(WiredNetworkComponent))]
|
|
[TestOf(typeof(WirelessNetworkComponent))]
|
|
public sealed class DeviceNetworkTest : GameTest
|
|
{
|
|
[TestPrototypes]
|
|
private const string Prototypes = @"
|
|
- type: entity
|
|
name: DummyNetworkDevice
|
|
id: DummyNetworkDevice
|
|
components:
|
|
- type: DeviceNetwork
|
|
transmitFrequency: 100
|
|
receiveFrequency: 100
|
|
|
|
- type: entity
|
|
name: DummyWiredNetworkDevice
|
|
id: DummyWiredNetworkDevice
|
|
components:
|
|
- type: DeviceNetwork
|
|
deviceNetId: Wired
|
|
transmitFrequency: 0
|
|
receiveFrequency: 0
|
|
- type: WiredNetworkConnection
|
|
- type: ApcPowerReceiver
|
|
|
|
- type: entity
|
|
name: WirelessNetworkDeviceDummy
|
|
id: WirelessNetworkDeviceDummy
|
|
components:
|
|
- type: DeviceNetwork
|
|
transmitFrequency: 100
|
|
receiveFrequency: 100
|
|
deviceNetId: Wireless
|
|
- type: WirelessNetworkConnection
|
|
range: 100
|
|
";
|
|
|
|
[Test]
|
|
public async Task NetworkDeviceSendAndReceive()
|
|
{
|
|
var pair = Pair;
|
|
var server = pair.Server;
|
|
|
|
var entityManager = server.ResolveDependency<IEntityManager>();
|
|
var deviceNetSystem = entityManager.EntitySysManager.GetEntitySystem<DeviceNetworkSystem>();
|
|
var deviceNetTestSystem = entityManager.EntitySysManager.GetEntitySystem<DeviceNetworkTestSystem>();
|
|
|
|
EntityUid device1 = default;
|
|
EntityUid device2 = default;
|
|
DeviceNetworkComponent networkComponent1 = null;
|
|
DeviceNetworkComponent networkComponent2 = null;
|
|
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
var payload = new TestPayload
|
|
{
|
|
TestString = "test",
|
|
TestNumber = 1,
|
|
TestBool = true
|
|
};
|
|
|
|
device1 = entityManager.SpawnEntity("DummyNetworkDevice", MapCoordinates.Nullspace);
|
|
|
|
Assert.That(entityManager.TryGetComponent(device1, out networkComponent1), Is.True);
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(networkComponent1.ReceiveFrequency, Is.Not.Null);
|
|
Assert.That(networkComponent1.Address, Is.Not.EqualTo(string.Empty));
|
|
});
|
|
|
|
device2 = entityManager.SpawnEntity("DummyNetworkDevice", MapCoordinates.Nullspace);
|
|
|
|
Assert.That(entityManager.TryGetComponent(device2, out networkComponent2), Is.True);
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(networkComponent1.ReceiveFrequency, Is.Not.Null);
|
|
Assert.That(networkComponent2.Address, Is.Not.EqualTo(string.Empty));
|
|
|
|
Assert.That(networkComponent1.Address, Is.Not.EqualTo(networkComponent2.Address));
|
|
});
|
|
|
|
deviceNetSystem.SendPacket(device1, networkComponent2.Address, ref payload, networkComponent2.ReceiveFrequency.Value);
|
|
Assert.That(payload, Is.EqualTo(deviceNetTestSystem.LastPayload));
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task WirelessNetworkDeviceSendAndReceive()
|
|
{
|
|
var pair = Pair;
|
|
var server = pair.Server;
|
|
var testMap = await pair.CreateTestMap();
|
|
var coordinates = testMap.GridCoords;
|
|
|
|
var entityManager = server.ResolveDependency<IEntityManager>();
|
|
var deviceNetSystem = entityManager.EntitySysManager.GetEntitySystem<DeviceNetworkSystem>();
|
|
var deviceNetTestSystem = entityManager.EntitySysManager.GetEntitySystem<DeviceNetworkTestSystem>();
|
|
|
|
EntityUid device1 = default;
|
|
EntityUid device2 = default;
|
|
DeviceNetworkComponent networkComponent1 = null;
|
|
DeviceNetworkComponent networkComponent2 = null;
|
|
WirelessNetworkComponent wirelessNetworkComponent = null;
|
|
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
device1 = entityManager.SpawnEntity("WirelessNetworkDeviceDummy", coordinates);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(entityManager.TryGetComponent(device1, out networkComponent1), Is.True);
|
|
Assert.That(entityManager.TryGetComponent(device1, out wirelessNetworkComponent), Is.True);
|
|
});
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(networkComponent1.ReceiveFrequency, Is.Not.Null);
|
|
Assert.That(networkComponent1.Address, Is.Not.EqualTo(string.Empty));
|
|
});
|
|
|
|
device2 = entityManager.SpawnEntity("WirelessNetworkDeviceDummy", new MapCoordinates(new Vector2(0, 50), testMap.MapId));
|
|
|
|
Assert.That(entityManager.TryGetComponent(device2, out networkComponent2), Is.True);
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(networkComponent2.ReceiveFrequency, Is.Not.Null);
|
|
Assert.That(networkComponent2.Address, Is.Not.EqualTo(string.Empty));
|
|
|
|
Assert.That(networkComponent1.Address, Is.Not.EqualTo(networkComponent2.Address));
|
|
});
|
|
|
|
var payload = new TestPayload
|
|
{
|
|
TestString = "test",
|
|
TestNumber = 1,
|
|
TestBool = true
|
|
};
|
|
|
|
deviceNetSystem.SendPacket(device1, networkComponent2.Address, ref payload, networkComponent2.ReceiveFrequency.Value);
|
|
|
|
Assert.That(payload, Is.EqualTo(deviceNetTestSystem.LastPayload));
|
|
|
|
wirelessNetworkComponent.Range = 0;
|
|
|
|
var secondPayload = new SecondTestPayload
|
|
{
|
|
TestString = "test",
|
|
TestNumber = 1,
|
|
TestBool = true
|
|
};
|
|
|
|
deviceNetSystem.SendPacket(device1, networkComponent2.Address, ref secondPayload, networkComponent2.ReceiveFrequency.Value);
|
|
Assert.That(secondPayload, Is.Not.EqualTo(deviceNetTestSystem.LastPayloadSecond));
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task WiredNetworkDeviceSendAndReceive()
|
|
{
|
|
var pair = Pair;
|
|
var server = pair.Server;
|
|
var testMap = await pair.CreateTestMap();
|
|
var coordinates = testMap.GridCoords;
|
|
|
|
var entityManager = server.ResolveDependency<IEntityManager>();
|
|
var deviceNetSystem = entityManager.EntitySysManager.GetEntitySystem<DeviceNetworkSystem>();
|
|
var deviceNetTestSystem = entityManager.EntitySysManager.GetEntitySystem<DeviceNetworkTestSystem>();
|
|
|
|
EntityUid device1 = default;
|
|
EntityUid device2 = default;
|
|
DeviceNetworkComponent networkComponent1 = null;
|
|
DeviceNetworkComponent networkComponent2 = null;
|
|
WiredNetworkComponent wiredNetworkComponent = null;
|
|
|
|
await server.WaitRunTicks(2);
|
|
await server.WaitIdleAsync();
|
|
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
device1 = entityManager.SpawnEntity("DummyWiredNetworkDevice", coordinates);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(entityManager.TryGetComponent(device1, out networkComponent1), Is.True);
|
|
Assert.That(entityManager.TryGetComponent(device1, out wiredNetworkComponent), Is.True);
|
|
});
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(networkComponent1.ReceiveFrequency, Is.Not.Null);
|
|
Assert.That(networkComponent1.Address, Is.Not.EqualTo(string.Empty));
|
|
});
|
|
|
|
device2 = entityManager.SpawnEntity("DummyWiredNetworkDevice", coordinates);
|
|
|
|
Assert.That(entityManager.TryGetComponent(device2, out networkComponent2), Is.True);
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(networkComponent2.ReceiveFrequency, Is.Not.Null);
|
|
Assert.That(networkComponent2.Address, Is.Not.EqualTo(string.Empty));
|
|
|
|
Assert.That(networkComponent1.Address, Is.Not.EqualTo(networkComponent2.Address));
|
|
});
|
|
|
|
var payload = new TestPayload
|
|
{
|
|
TestString = "test",
|
|
TestNumber = 1,
|
|
TestBool = true
|
|
};
|
|
|
|
deviceNetSystem.SendPacket(device1, networkComponent2.Address, ref payload, networkComponent2.ReceiveFrequency.Value);
|
|
|
|
entityManager.SpawnEntity("CableApcExtension", coordinates);
|
|
|
|
deviceNetSystem.SendPacket(device1, networkComponent2.Address, ref payload, networkComponent2.ReceiveFrequency.Value);
|
|
|
|
Assert.That(payload, Is.EqualTo(deviceNetTestSystem.LastPayload));
|
|
});
|
|
}
|
|
}
|
|
}
|