mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +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
176 lines
6.3 KiB
C#
176 lines
6.3 KiB
C#
using Content.Server.DeviceNetwork.Systems;
|
|
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.DeviceNetwork.Events;
|
|
using Content.Shared.Power;
|
|
using Content.Shared.SurveillanceCamera;
|
|
using Content.Shared.Verbs;
|
|
using Robust.Server.GameObjects;
|
|
using Content.Shared.DeviceNetwork.Components;
|
|
|
|
namespace Content.Server.SurveillanceCamera;
|
|
|
|
public sealed partial class SurveillanceCameraRouterSystem : EntitySystem
|
|
{
|
|
[Dependency] private DeviceNetworkSystem _deviceNetworkSystem = default!;
|
|
[Dependency] private ActionBlockerSystem _actionBlocker = default!;
|
|
[Dependency] private UserInterfaceSystem _userInterface = default!;
|
|
|
|
[Dependency] private EntityQuery<SurveillanceCameraRouterComponent> _query = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<SurveillanceCameraRouterComponent, MapInitEvent>(OnMapInit);
|
|
SubscribeLocalEvent<SurveillanceCameraRouterComponent, SurveillanceCameraSetupSetNetwork>(OnSetNetwork);
|
|
SubscribeLocalEvent<SurveillanceCameraRouterComponent, GetVerbsEvent<AlternativeVerb>>(AddVerbs);
|
|
SubscribeLocalEvent<SurveillanceCameraRouterComponent, PowerChangedEvent>(OnPowerChanged);
|
|
}
|
|
|
|
private void OnMapInit(Entity<SurveillanceCameraRouterComponent> ent, ref MapInitEvent args)
|
|
{
|
|
if (ent.Comp.SubnetFrequencyId == null
|
|
|| !ProtoMan.TryIndex(ent.Comp.SubnetFrequencyId, out var subnetFrequency))
|
|
return;
|
|
|
|
ent.Comp.SubnetFrequency = subnetFrequency.Frequency;
|
|
ent.Comp.Active = true;
|
|
|
|
if (string.IsNullOrEmpty(ent.Comp.SubnetName) && subnetFrequency.Name != null)
|
|
ent.Comp.SubnetName = Loc.GetString(subnetFrequency.Name);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnSubnetConnect(Entity<SurveillanceCameraRouterComponent> ent, ref DeviceNetworkPacketEvent<SurveillanceCameraSubnetConnectPayload> args)
|
|
{
|
|
AddMonitorToRoute(ent.AsNullable(), args.SenderAddress);
|
|
PingSubnet(ent.AsNullable());
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnSubnetDisconnect(Entity<SurveillanceCameraRouterComponent> ent, ref DeviceNetworkPacketEvent<SurveillanceCameraSubnetDisconnectPayload> args)
|
|
{
|
|
RemoveMonitorFromRoute(ent.AsNullable(), args.SenderAddress);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnSubnetPing(Entity<SurveillanceCameraRouterComponent> ent, ref DeviceNetworkPacketEvent<SurveillanceCameraPingSubnetPayload> args)
|
|
{
|
|
if (ent.Comp.SubnetFrequencyId == null)
|
|
return;
|
|
|
|
var response = new SurveillanceCameraSubnetDataPayload
|
|
{
|
|
Subnet = ent.Comp.SubnetName,
|
|
TransmitFrequency = ent.Comp.SubnetFrequencyId.Value,
|
|
};
|
|
_deviceNetworkSystem.SendPacket(ent.Owner, args.SenderAddress, ref response);
|
|
}
|
|
|
|
private void OnPowerChanged(Entity<SurveillanceCameraRouterComponent> ent, ref PowerChangedEvent args)
|
|
{
|
|
ent.Comp.MonitorRoutes.Clear();
|
|
ent.Comp.Active = args.Powered;
|
|
}
|
|
|
|
private void AddVerbs(Entity<SurveillanceCameraRouterComponent> ent, ref GetVerbsEvent<AlternativeVerb> verbs)
|
|
{
|
|
if (!_actionBlocker.CanInteract(verbs.User, ent.Owner) || !_actionBlocker.CanComplexInteract(verbs.User))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (ent.Comp.SubnetFrequencyId != null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
AlternativeVerb verb = new();
|
|
var user = verbs.User;
|
|
verb.Text = Loc.GetString("surveillance-camera-setup");
|
|
verb.Act = () => OpenSetupInterface(ent.AsNullable(), user);
|
|
verbs.Verbs.Add(verb);
|
|
}
|
|
|
|
private void OnSetNetwork(Entity<SurveillanceCameraRouterComponent> ent, ref SurveillanceCameraSetupSetNetwork args)
|
|
{
|
|
if (args.UiKey is not SurveillanceCameraSetupUiKey key
|
|
|| key != SurveillanceCameraSetupUiKey.Router)
|
|
{
|
|
return;
|
|
}
|
|
if (args.Network < 0 || args.Network >= ent.Comp.AvailableNetworks.Count)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!ProtoMan.Resolve(ent.Comp.AvailableNetworks[args.Network], out var frequency))
|
|
{
|
|
return;
|
|
}
|
|
|
|
ent.Comp.SubnetFrequencyId = ent.Comp.AvailableNetworks[args.Network];
|
|
ent.Comp.SubnetFrequency = frequency.Frequency;
|
|
ent.Comp.Active = true;
|
|
UpdateSetupInterface(ent.AsNullable());
|
|
}
|
|
|
|
private void OpenSetupInterface(Entity<SurveillanceCameraRouterComponent?> ent, EntityUid player)
|
|
{
|
|
if (!_query.Resolve(ref ent))
|
|
return;
|
|
|
|
if (!_userInterface.TryOpenUi(ent.Owner, SurveillanceCameraSetupUiKey.Router, player))
|
|
return;
|
|
|
|
UpdateSetupInterface(ent.AsNullable());
|
|
}
|
|
|
|
private void UpdateSetupInterface(Entity<SurveillanceCameraRouterComponent?, DeviceNetworkComponent?> ent)
|
|
{
|
|
if (!_query.Resolve(ent.Owner, ref ent.Comp1) || !Resolve(ent.Owner, ref ent.Comp2))
|
|
return;
|
|
|
|
if (ent.Comp1.AvailableNetworks.Count == 0 || ent.Comp1.SubnetFrequencyId != null)
|
|
{
|
|
_userInterface.CloseUi(ent.Owner, SurveillanceCameraSetupUiKey.Router);
|
|
return;
|
|
}
|
|
|
|
var state = new SurveillanceCameraSetupBoundUiState(ent.Comp1.SubnetName,
|
|
ent.Comp2.ReceiveFrequency ?? 0,
|
|
ent.Comp1.AvailableNetworks,
|
|
true,
|
|
ent.Comp1.SubnetFrequencyId != null);
|
|
_userInterface.SetUiState(ent.Owner, SurveillanceCameraSetupUiKey.Router, state);
|
|
}
|
|
|
|
// Adds a monitor to the set of routes.
|
|
private void AddMonitorToRoute(Entity<SurveillanceCameraRouterComponent?> ent, string address)
|
|
{
|
|
if (!_query.Resolve(ref ent) || ent.Comp == null)
|
|
return;
|
|
|
|
ent.Comp.MonitorRoutes.Add(address);
|
|
}
|
|
|
|
private void RemoveMonitorFromRoute(Entity<SurveillanceCameraRouterComponent?> ent, string address)
|
|
{
|
|
if (!_query.Resolve(ref ent) || ent.Comp == null)
|
|
return;
|
|
|
|
ent.Comp.MonitorRoutes.Remove(address);
|
|
}
|
|
|
|
// Pings a subnet to get all camera information.
|
|
private void PingSubnet(Entity<SurveillanceCameraRouterComponent?> ent)
|
|
{
|
|
if (!_query.Resolve(ref ent) || ent.Comp == null)
|
|
return;
|
|
|
|
var payload = new SurveillanceCameraPingPayload
|
|
{
|
|
Subnet = ent.Comp.SubnetName,
|
|
};
|
|
_deviceNetworkSystem.SendPacket(ent.Owner, null, ref payload, ent.Comp.SubnetFrequency);
|
|
}
|
|
}
|