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
87 lines
3.4 KiB
C#
87 lines
3.4 KiB
C#
using Content.Server.DeviceNetwork.Components;
|
|
using Content.Server.Station.Systems;
|
|
using Content.Shared.DeviceNetwork.Events;
|
|
using JetBrains.Annotations;
|
|
|
|
namespace Content.Server.DeviceNetwork.Systems
|
|
{
|
|
/// <summary>
|
|
/// This system requires the StationLimitedNetworkComponent to be on the the sending entity as well as the receiving entity
|
|
/// </summary>
|
|
[UsedImplicitly]
|
|
public sealed partial class StationLimitedNetworkSystem : EntitySystem
|
|
{
|
|
[Dependency] private StationSystem _stationSystem = default!;
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<StationLimitedNetworkComponent, MapInitEvent>(OnMapInit);
|
|
SubscribeLocalEvent<StationLimitedNetworkComponent, BeforePacketSentEvent>(OnBeforePacketSent);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the station id the device is limited to.
|
|
/// </summary>
|
|
public void SetStation(EntityUid uid, EntityUid? stationId, StationLimitedNetworkComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
component.StationId = stationId;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to set the station id to the current station if the device is currently on a station
|
|
/// </summary>
|
|
public bool TrySetStationId(EntityUid uid, StationLimitedNetworkComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component) || !Transform(uid).GridUid.HasValue)
|
|
return false;
|
|
|
|
component.StationId = _stationSystem.GetOwningStation(uid);
|
|
return component.StationId.HasValue;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set the station id to the one the entity is on when the station limited component is added
|
|
/// </summary>
|
|
private void OnMapInit(EntityUid uid, StationLimitedNetworkComponent networkComponent, MapInitEvent args)
|
|
{
|
|
networkComponent.StationId = _stationSystem.GetOwningStation(uid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if both devices are limited to the same station
|
|
/// </summary>
|
|
private void OnBeforePacketSent(Entity<StationLimitedNetworkComponent> ent, ref BeforePacketSentEvent args)
|
|
{
|
|
var (uid, component) = ent;
|
|
if (!component.StationId.HasValue)
|
|
TrySetStationId(uid, component);
|
|
|
|
if (!CheckStationId(args.Sender, component.AllowNonStationPackets, component.StationId))
|
|
{
|
|
args.Cancelled = true;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Compares the station IDs of the sending and receiving network components.
|
|
/// Returns false if either of them doesn't have a station ID or if their station ID isn't equal.
|
|
/// Returns true even when the sending entity isn't tied to a station if `allowNonStationPackets` is set to true.
|
|
/// </summary>
|
|
private bool CheckStationId(EntityUid senderUid, bool allowNonStationPackets, EntityUid? receiverStationId, StationLimitedNetworkComponent? sender = null)
|
|
{
|
|
if (!receiverStationId.HasValue)
|
|
return false;
|
|
|
|
if (!Resolve(senderUid, ref sender, false))
|
|
return allowNonStationPackets;
|
|
|
|
if (!sender.StationId.HasValue)
|
|
TrySetStationId(senderUid, sender);
|
|
|
|
return sender.StationId == receiverStationId;
|
|
}
|
|
}
|
|
}
|