Skip to content

Commit

Permalink
Fix null exceptions in SurveillanceCameraMonitorSystem (#29275)
Browse files Browse the repository at this point in the history
* Add IsNullOrEmpty checks before indexing KnownSubnets

* actor
  • Loading branch information
Tayrtahn committed Jun 21, 2024
1 parent 0b34592 commit afc8002
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private void OnComponentStartup(EntityUid uid, SurveillanceCameraMonitorComponen
private void OnSubnetRequest(EntityUid uid, SurveillanceCameraMonitorComponent component,
SurveillanceCameraMonitorSubnetRequestMessage args)
{
if (args.Actor != null)
if (args.Actor is { Valid: true } actor && !Deleted(actor))
{
SetActiveSubnet(uid, args.Subnet, component);
}
Expand Down Expand Up @@ -146,6 +146,7 @@ private void OnPacketReceived(EntityUid uid, SurveillanceCameraMonitorComponent
break;
case SurveillanceCameraSystem.CameraSubnetData:
if (args.Data.TryGetValue(SurveillanceCameraSystem.CameraSubnetData, out string? subnet)
&& !string.IsNullOrEmpty(subnet)
&& !component.KnownSubnets.ContainsKey(subnet))
{
component.KnownSubnets.Add(subnet, args.SenderAddress);
Expand Down Expand Up @@ -217,6 +218,7 @@ private void SendHeartbeat(EntityUid uid, SurveillanceCameraMonitorComponent? mo
{
if (!Resolve(uid, ref monitor)
|| monitor.LastHeartbeatSent < _heartbeatDelay
|| string.IsNullOrEmpty(monitor.ActiveSubnet)
|| !monitor.KnownSubnets.TryGetValue(monitor.ActiveSubnet, out var subnetAddress))
{
return;
Expand Down Expand Up @@ -278,6 +280,7 @@ private void SetActiveSubnet(EntityUid uid, string subnet,
SurveillanceCameraMonitorComponent? monitor = null)
{
if (!Resolve(uid, ref monitor)
|| string.IsNullOrEmpty(subnet)
|| !monitor.KnownSubnets.ContainsKey(subnet))
{
return;
Expand All @@ -295,6 +298,7 @@ private void SetActiveSubnet(EntityUid uid, string subnet,
private void RequestActiveSubnetInfo(EntityUid uid, SurveillanceCameraMonitorComponent? monitor = null)
{
if (!Resolve(uid, ref monitor)
|| string.IsNullOrEmpty(monitor.ActiveSubnet)
|| !monitor.KnownSubnets.TryGetValue(monitor.ActiveSubnet, out var address))
{
return;
Expand All @@ -310,6 +314,7 @@ private void RequestActiveSubnetInfo(EntityUid uid, SurveillanceCameraMonitorCom
private void ConnectToSubnet(EntityUid uid, string subnet, SurveillanceCameraMonitorComponent? monitor = null)
{
if (!Resolve(uid, ref monitor)
|| string.IsNullOrEmpty(subnet)
|| !monitor.KnownSubnets.TryGetValue(subnet, out var address))
{
return;
Expand All @@ -327,6 +332,7 @@ private void ConnectToSubnet(EntityUid uid, string subnet, SurveillanceCameraMon
private void DisconnectFromSubnet(EntityUid uid, string subnet, SurveillanceCameraMonitorComponent? monitor = null)
{
if (!Resolve(uid, ref monitor)
|| string.IsNullOrEmpty(subnet)
|| !monitor.KnownSubnets.TryGetValue(subnet, out var address))
{
return;
Expand Down Expand Up @@ -415,6 +421,7 @@ private void TrySwitchCameraByAddress(EntityUid uid, string address,
SurveillanceCameraMonitorComponent? monitor = null)
{
if (!Resolve(uid, ref monitor)
|| string.IsNullOrEmpty(monitor.ActiveSubnet)
|| !monitor.KnownSubnets.TryGetValue(monitor.ActiveSubnet, out var subnetAddress))
{
return;
Expand Down

0 comments on commit afc8002

Please sign in to comment.