From c646b4e5ec55bae66abf1bd8fd44a430082d0fa1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 15 Jan 2026 17:11:29 +0900 Subject: [PATCH] Alert when spectator server disconnects during gameplay This can cause issues liek loss of replays, so it's worth notifying the user and keeping things visible. --- osu.Game/Online/OnlineStatusNotifier.cs | 57 ++++++++++++++----------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/osu.Game/Online/OnlineStatusNotifier.cs b/osu.Game/Online/OnlineStatusNotifier.cs index 70020f4b84..66282e48fd 100644 --- a/osu.Game/Online/OnlineStatusNotifier.cs +++ b/osu.Game/Online/OnlineStatusNotifier.cs @@ -17,6 +17,7 @@ using osu.Game.Online.Spectator; using osu.Game.Overlays; using osu.Game.Overlays.Notifications; using osu.Game.Screens.OnlinePlay; +using osu.Game.Screens.Play; namespace osu.Game.Online { @@ -75,22 +76,16 @@ namespace osu.Game.Online apiState.BindValueChanged(state => { - if (state.NewValue == APIState.Online) + switch (state.NewValue) { - userNotified = false; - return; - } + case APIState.Online: + userNotified = false; + return; - if (userNotified) return; - - if (state.NewValue == APIState.Offline && getCurrentScreen() is OnlinePlayScreen) - { - userNotified = true; - notificationOverlay?.Post(new SimpleErrorNotification - { - Icon = FontAwesome.Solid.ExclamationCircle, - Text = NotificationsStrings.APIConnectionInterrupted, - }); + case APIState.Offline: + if (getCurrentScreen() is OnlinePlayScreen) + notifyApiDisconnection(); + break; } }); @@ -102,22 +97,32 @@ namespace osu.Game.Online return; } - if (userNotified) return; - if (multiplayerClient.Room != null) - { - userNotified = true; - notificationOverlay?.Post(new SimpleErrorNotification - { - Icon = FontAwesome.Solid.ExclamationCircle, - Text = NotificationsStrings.APIConnectionInterrupted, - }); - } + notifyApiDisconnection(); })); - spectatorState.BindValueChanged(_ => + spectatorState.BindValueChanged(connected => Schedule(() => { - // TODO: handle spectator server failure somehow? + if (connected.NewValue) + { + userNotified = false; + return; + } + + if (getCurrentScreen() is Player) + notifyApiDisconnection(); + })); + } + + private void notifyApiDisconnection() + { + if (userNotified) return; + + userNotified = true; + notificationOverlay?.Post(new SimpleErrorNotification + { + Icon = FontAwesome.Solid.ExclamationCircle, + Text = NotificationsStrings.APIConnectionInterrupted, }); }