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

@@ -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;
}
}