Fix server NRE on clicking alerts with no OnClick (#2748)
* #2744 fix NRE on clicking alerts with no OnClick, and don't send the click message unless the alert has an onclick * #2744 fix NRE on clicking alerts with no OnClick, and don't send the click message unless the alert has an onclick
This commit is contained in:
@@ -222,6 +222,7 @@ namespace Content.Client.GameObjects.Components.Mobs
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!alert.Alert.HasOnClick) return;
|
||||||
SendNetworkMessage(new ClickAlertMessage(alert.Alert.AlertType));
|
SendNetworkMessage(new ClickAlertMessage(alert.Alert.AlertType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AlertManager.TryGet(msg.AlertType, out var alert))
|
if (AlertManager.TryGet(msg.AlertType, out var alert) && alert.OnClick != null)
|
||||||
{
|
{
|
||||||
alert.OnClick.AlertClicked(new ClickAlertEventArgs(player, alert));
|
alert.OnClick.AlertClicked(new ClickAlertEventArgs(player, alert));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,8 +72,14 @@ namespace Content.Shared.Alert
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool SupportsSeverity => MaxSeverity != -1;
|
public bool SupportsSeverity => MaxSeverity != -1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether this alert is clickable. This is valid clientside.
|
||||||
|
/// </summary>
|
||||||
|
public bool HasOnClick { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines what to do when the alert is clicked.
|
/// Defines what to do when the alert is clicked.
|
||||||
|
/// This will always be null on clientside.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IAlertClick OnClick { get; private set; }
|
public IAlertClick OnClick { get; private set; }
|
||||||
|
|
||||||
@@ -102,6 +108,8 @@ namespace Content.Shared.Alert
|
|||||||
}
|
}
|
||||||
AlertKey = new AlertKey(AlertType, Category);
|
AlertKey = new AlertKey(AlertType, Category);
|
||||||
|
|
||||||
|
HasOnClick = serializer.TryReadDataField("onClick", out string _);
|
||||||
|
|
||||||
if (IoCManager.Resolve<IModuleManager>().IsClientModule) return;
|
if (IoCManager.Resolve<IModuleManager>().IsClientModule) return;
|
||||||
serializer.DataField(this, x => x.OnClick, "onClick", null);
|
serializer.DataField(this, x => x.OnClick, "onClick", null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user