Files
OldThink/Content.Server/Medical/CrewMonitoring/CrewMonitoringServerSystem.cs
ThereDrD 3f97bdce2f Черри пики 7 (#592)
* Remake gasp popup to emote (#27736)

* fix

* Silence ringtones on admin PDAs (#29801)

* Silence ringtones on invisible PDAs

* Revert "Silence ringtones on invisible PDAs"

This reverts commit afc1041f31eebe82e83630a856a8856b877a9826.

* Literally just this

* Add an admin announcement for news article publishing

* Fix invalid UI hover/click sounds breaking client (#30067)

fixes #29561

* Display the administrator's title in ahelp and ahelp relay (#30075)

* Adding the admin prefix to the ahelp

* Updating the admin prefix

* The second update of the admin prefix

* Configuration correction

* fix

* Fix servers ambience sound (#30091)

* Fix servers ambience

* I'm silly

* Clean up

* Add pen clicking sound (#30531)

* Add pen clicking sound

* switch to OnUse and reduce distance a little

* Fix exploding pen clicking (#30533)

* fix pens

* added a bunch more fox noises (#27578)

* fuck it we ball

* added recommended copyright information

* revised copyright license

* revised copyright license x2

* finalized the fops

# reduced the number of audio clips
# adjusted the volume of all fox sounds to be consistent with each other

* added new sounds to the overall fox parent mob because we forgot oopsie

---------

Co-authored-by: lzk <124214523+lzk228@users.noreply.github.com>
Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
Co-authored-by: to4no_fix <156101927+chavonadelal@users.noreply.github.com>
Co-authored-by: Winkarst <74284083+Winkarst-cpu@users.noreply.github.com>
Co-authored-by: themias <89101928+themias@users.noreply.github.com>
Co-authored-by: nao fujiwara <awkwarddryad@gmail.com>
2024-08-09 02:37:34 +03:00

113 lines
3.9 KiB
C#

using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.Medical.SuitSensors;
using Content.Shared.DeviceNetwork;
using Content.Shared.Medical.SuitSensor;
using Robust.Shared.Timing;
namespace Content.Server.Medical.CrewMonitoring;
public sealed class CrewMonitoringServerSystem : EntitySystem
{
[Dependency] private readonly SuitSensorSystem _sensors = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly DeviceNetworkSystem _deviceNetworkSystem = default!;
[Dependency] private readonly SingletonDeviceNetServerSystem _singletonServerSystem = default!;
private const float UpdateRate = 3f;
private float _updateDiff;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CrewMonitoringServerComponent, ComponentRemove>(OnRemove);
SubscribeLocalEvent<CrewMonitoringServerComponent, DeviceNetworkPacketEvent>(OnPacketReceived);
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>
private void OnPacketReceived(EntityUid uid, CrewMonitoringServerComponent component, DeviceNetworkPacketEvent args)
{
var sensorStatus = _sensors.PacketToSuitSensor(args.Data);
if (sensorStatus == null)
return;
sensorStatus.Timestamp = _gameTiming.CurTime;
component.SensorStatus[args.SenderAddress] = sensorStatus;
}
/// <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 NetworkPayload()
{
[DeviceNetworkConstants.Command] = DeviceNetworkConstants.CmdUpdatedState,
[SuitSensorConstants.NET_STATUS_COLLECTION] = serverComponent.SensorStatus
};
_deviceNetworkSystem.QueuePacket(uid, null, payload, device: device);
}
/// <summary>
/// Clears sensor data on disconnect
/// </summary>
private void OnDisconnected(EntityUid uid, CrewMonitoringServerComponent component, ref DeviceNetServerDisconnectedEvent _)
{
component.SensorStatus.Clear();
}
}