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
106 lines
3.5 KiB
C#
106 lines
3.5 KiB
C#
using Content.Server.DeviceNetwork.Systems;
|
|
using Content.Shared.DeviceNetwork.Events;
|
|
using Robust.Shared.Timing;
|
|
using Content.Shared.DeviceNetwork.Components;
|
|
using Content.Shared.Medical.CrewMonitoring;
|
|
using Content.Shared.Medical.SuitSensors;
|
|
|
|
namespace Content.Server.Medical.CrewMonitoring;
|
|
|
|
public sealed partial class CrewMonitoringServerSystem : EntitySystem
|
|
{
|
|
[Dependency] private IGameTiming _gameTiming = default!;
|
|
[Dependency] private DeviceNetworkSystem _deviceNetworkSystem = default!;
|
|
[Dependency] private SingletonDeviceNetServerSystem _singletonServerSystem = default!;
|
|
|
|
private const float UpdateRate = 3f;
|
|
private float _updateDiff;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<CrewMonitoringServerComponent, ComponentRemove>(OnRemove);
|
|
SubscribeLocalEvent<CrewMonitoringServerComponent, DeviceNetServerDisconnectedEvent>(OnDisconnected);
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
// check update rate
|
|
_updateDiff += frameTime;
|
|
if (_updateDiff < UpdateRate)
|
|
return;
|
|
_updateDiff -= UpdateRate;
|
|
|
|
var servers = EntityQueryEnumerator<CrewMonitoringServerComponent>();
|
|
|
|
while (servers.MoveNext(out var id, out var server))
|
|
{
|
|
if (!_singletonServerSystem.IsActiveServer(id))
|
|
continue;
|
|
|
|
UpdateTimeout(id);
|
|
BroadcastSensorStatus(id, server);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds or updates a sensor status entry if the received package is a sensor status update
|
|
/// </summary>
|
|
[SubscribeLocalEvent]
|
|
private void OnSensorStatus(Entity<CrewMonitoringServerComponent> ent, ref DeviceNetworkPacketEvent<SuitSensorStatusPayload> args)
|
|
{
|
|
var sensorData = args.Data.Data;
|
|
sensorData.Timestamp = _gameTiming.CurTime;
|
|
ent.Comp.SensorStatus[args.SenderAddress] = sensorData;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clears the servers sensor status list
|
|
/// </summary>
|
|
private void OnRemove(EntityUid uid, CrewMonitoringServerComponent component, ComponentRemove args)
|
|
{
|
|
component.SensorStatus.Clear();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Drop the sensor status if it hasn't been updated for to long
|
|
/// </summary>
|
|
private void UpdateTimeout(EntityUid uid, CrewMonitoringServerComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
foreach (var (address, sensor) in component.SensorStatus)
|
|
{
|
|
var dif = _gameTiming.CurTime - sensor.Timestamp;
|
|
if (dif.Seconds > component.SensorTimeout)
|
|
component.SensorStatus.Remove(address);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Broadcasts the status of all connected sensors
|
|
/// </summary>
|
|
private void BroadcastSensorStatus(EntityUid uid, CrewMonitoringServerComponent? serverComponent = null, DeviceNetworkComponent? device = null)
|
|
{
|
|
if (!Resolve(uid, ref serverComponent, ref device))
|
|
return;
|
|
|
|
var payload = new BroadcastSuitSensorStatePayload
|
|
{
|
|
SensorStatus = serverComponent.SensorStatus,
|
|
};
|
|
|
|
_deviceNetworkSystem.SendPacket((uid, device), null, ref payload);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clears sensor data on disconnect
|
|
/// </summary>
|
|
private void OnDisconnected(EntityUid uid, CrewMonitoringServerComponent component, ref DeviceNetServerDisconnectedEvent _)
|
|
{
|
|
component.SensorStatus.Clear();
|
|
}
|
|
}
|