From aa29712a651f813b97cb3720a3080ef825499656 Mon Sep 17 00:00:00 2001 From: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com> Date: Tue, 29 Apr 2025 15:32:18 +0200 Subject: [PATCH] Fix clientsided alerts being overwritten by server (#37033) Initial commit --- Content.Client/Alerts/ClientAlertsSystem.cs | 16 ++++++++++++++++ Content.Shared/Alert/AlertPrototype.cs | 6 ++++++ Resources/Prototypes/Alerts/alerts.yml | 1 + 3 files changed, 23 insertions(+) diff --git a/Content.Client/Alerts/ClientAlertsSystem.cs b/Content.Client/Alerts/ClientAlertsSystem.cs index b77bc9e4bc..5b658fb07c 100644 --- a/Content.Client/Alerts/ClientAlertsSystem.cs +++ b/Content.Client/Alerts/ClientAlertsSystem.cs @@ -52,8 +52,24 @@ public sealed class ClientAlertsSystem : AlertsSystem if (args.Current is not AlertComponentState cast) return; + // Save all client-sided alerts to later put back in + var clientAlerts = new Dictionary(); + foreach (var alert in alerts.Comp.Alerts) + { + if (alert.Key.AlertType != null && TryGet(alert.Key.AlertType.Value, out var alertProto)) + { + if (alertProto.ClientHandled) + clientAlerts[alert.Key] = alert.Value; + } + } + alerts.Comp.Alerts = new(cast.Alerts); + foreach (var alert in clientAlerts) + { + alerts.Comp.Alerts[alert.Key] = alert.Value; + } + UpdateHud(alerts); } diff --git a/Content.Shared/Alert/AlertPrototype.cs b/Content.Shared/Alert/AlertPrototype.cs index a82cbd3daf..998eb4bd4d 100644 --- a/Content.Shared/Alert/AlertPrototype.cs +++ b/Content.Shared/Alert/AlertPrototype.cs @@ -75,6 +75,12 @@ public sealed partial class AlertPrototype : IPrototype /// public bool SupportsSeverity => MaxSeverity != -1; + /// + /// If true, this alert is being handled by the client and will not be overwritten when handling server -> client states. + /// + [DataField] + public bool ClientHandled = false; + /// /// Event raised on the user when they click on this alert. /// Can be null. diff --git a/Resources/Prototypes/Alerts/alerts.yml b/Resources/Prototypes/Alerts/alerts.yml index 859f223730..471ece63ee 100644 --- a/Resources/Prototypes/Alerts/alerts.yml +++ b/Resources/Prototypes/Alerts/alerts.yml @@ -134,6 +134,7 @@ state: walking name: alerts-walking-name description: alerts-walking-desc + clientHandled: true - type: alert id: Stun