From 27d5019df05da1be021e435070cff91861190b77 Mon Sep 17 00:00:00 2001 From: chairbender Date: Wed, 16 Dec 2020 03:13:57 -0800 Subject: [PATCH] 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 --- .../GameObjects/Components/Mobs/ClientAlertsComponent.cs | 1 + .../GameObjects/Components/Mobs/ServerAlertsComponent.cs | 2 +- Content.Shared/Alert/AlertPrototype.cs | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Content.Client/GameObjects/Components/Mobs/ClientAlertsComponent.cs b/Content.Client/GameObjects/Components/Mobs/ClientAlertsComponent.cs index ae92f09ee3..7e847038be 100644 --- a/Content.Client/GameObjects/Components/Mobs/ClientAlertsComponent.cs +++ b/Content.Client/GameObjects/Components/Mobs/ClientAlertsComponent.cs @@ -222,6 +222,7 @@ namespace Content.Client.GameObjects.Components.Mobs return; } + if (!alert.Alert.HasOnClick) return; SendNetworkMessage(new ClickAlertMessage(alert.Alert.AlertType)); } diff --git a/Content.Server/GameObjects/Components/Mobs/ServerAlertsComponent.cs b/Content.Server/GameObjects/Components/Mobs/ServerAlertsComponent.cs index 2ec4c6f398..e80232120c 100644 --- a/Content.Server/GameObjects/Components/Mobs/ServerAlertsComponent.cs +++ b/Content.Server/GameObjects/Components/Mobs/ServerAlertsComponent.cs @@ -71,7 +71,7 @@ namespace Content.Server.GameObjects.Components.Mobs 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)); } diff --git a/Content.Shared/Alert/AlertPrototype.cs b/Content.Shared/Alert/AlertPrototype.cs index 9a6e0bd674..d7cf72bb88 100644 --- a/Content.Shared/Alert/AlertPrototype.cs +++ b/Content.Shared/Alert/AlertPrototype.cs @@ -72,8 +72,14 @@ namespace Content.Shared.Alert /// public bool SupportsSeverity => MaxSeverity != -1; + /// + /// Whether this alert is clickable. This is valid clientside. + /// + public bool HasOnClick { get; private set; } + /// /// Defines what to do when the alert is clicked. + /// This will always be null on clientside. /// public IAlertClick OnClick { get; private set; } @@ -102,6 +108,8 @@ namespace Content.Shared.Alert } AlertKey = new AlertKey(AlertType, Category); + HasOnClick = serializer.TryReadDataField("onClick", out string _); + if (IoCManager.Resolve().IsClientModule) return; serializer.DataField(this, x => x.OnClick, "onClick", null); }