Fix station limited devices station assignment (#16893)

Fix error in crew monitor window
This commit is contained in:
Julian Giebel
2023-05-28 22:07:31 +02:00
committed by GitHub
parent 02f015d97c
commit 8d040e57d7
3 changed files with 38 additions and 3 deletions

View File

@@ -112,7 +112,7 @@ namespace Content.Client.Medical.CrewMonitoring
if (sensor.Coordinates != null && NavMap.Visible)
{
NavMap.TrackedCoordinates.Add(sensor.Coordinates.Value, (true, Color.FromHex("#B02E26")));
NavMap.TrackedCoordinates.TryAdd(sensor.Coordinates.Value, (true, Color.FromHex("#B02E26")));
nameLabel.MouseFilter = MouseFilterMode.Stop;
// Hide all others upon mouseover.

View File

@@ -30,6 +30,18 @@ namespace Content.Server.DeviceNetwork.Systems
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>
@@ -43,6 +55,9 @@ namespace Content.Server.DeviceNetwork.Systems
/// </summary>
private void OnBeforePacketSent(EntityUid uid, StationLimitedNetworkComponent component, BeforePacketSentEvent args)
{
if (!component.StationId.HasValue)
TrySetStationId(uid, component);
if (!CheckStationId(args.Sender, component.AllowNonStationPackets, component.StationId))
{
args.Cancel();
@@ -62,6 +77,9 @@ namespace Content.Server.DeviceNetwork.Systems
if (!Resolve(senderUid, ref sender, false))
return allowNonStationPackets;
if (!sender.StationId.HasValue)
TrySetStationId(senderUid, sender);
return sender.StationId == receiverStationId;
}
}

View File

@@ -60,13 +60,16 @@ namespace Content.Server.Medical.SuitSensors
while (sensors.MoveNext(out var uid, out var sensor, out var device))
{
if (device.TransmitFrequency is null || !sensor.StationId.HasValue)
if (device.TransmitFrequency is null)
continue;
// check if sensor is ready to update
if (curTime < sensor.NextUpdate)
continue;
if (!CheckSensorAssignedStation(uid, sensor))
continue;
// TODO: This would cause imprecision at different tick rates.
sensor.NextUpdate = curTime + sensor.UpdateRate;
@@ -78,7 +81,7 @@ namespace Content.Server.Medical.SuitSensors
//Retrieve active server address if the sensor isn't connected to a server
if (sensor.ConnectedServer == null)
{
if (!_monitoringServerSystem.TryGetActiveServerAddress(sensor.StationId.Value, out var address))
if (!_monitoringServerSystem.TryGetActiveServerAddress(sensor.StationId!.Value, out var address))
continue;
sensor.ConnectedServer = address;
@@ -98,6 +101,20 @@ namespace Content.Server.Medical.SuitSensors
}
}
/// <summary>
/// Checks whether the sensor is assigned to a station or not
/// and tries to assign an unassigned sensor to a station if it's currently on a grid
/// </summary>
/// <returns>True if the sensor is assigned to a station or assigning it was successful. False otherwise.</returns>
private bool CheckSensorAssignedStation(EntityUid uid, SuitSensorComponent sensor)
{
if (!sensor.StationId.HasValue && Transform(uid).GridUid == null)
return false;
sensor.StationId = _stationSystem.GetOwningStation(uid);
return sensor.StationId.HasValue;
}
private void OnPlayerSpawn(PlayerSpawnCompleteEvent ev)
{
// If the player spawns in arrivals then the grid underneath them may not be appropriate.