Skip to content

Commit

Permalink
Merge pull request #24255 from bdach/multiplayer-disconnection-schedu…
Browse files Browse the repository at this point in the history
…le-bomb

Fix several issues in multiplayer exit-on-disconnection flow
  • Loading branch information
peppy authored Jul 16, 2023
2 parents acb51df + 7fbd47e commit a472fe6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion osu.Game/Overlays/Dialog/PopupDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public void PerformAction<T>() where T : PopupDialogButton
{
// Buttons are regularly added in BDL or LoadComplete, so let's schedule to ensure
// they are ready to be pressed.
Schedule(() => Buttons.OfType<T>().FirstOrDefault()?.TriggerClick());
Scheduler.AddOnce(() => Buttons.OfType<T>().FirstOrDefault()?.TriggerClick());
}

protected override bool OnKeyDown(KeyDownEvent e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using osu.Game.Configuration;
using osu.Game.Graphics.Cursor;
using osu.Game.Online;
using osu.Game.Online.API;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
using osu.Game.Overlays;
Expand Down Expand Up @@ -49,6 +50,9 @@ public partial class MultiplayerMatchSubScreen : RoomSubScreen, IHandlePresentBe
[Resolved]
private MultiplayerClient client { get; set; }

[Resolved]
private IAPIProvider api { get; set; }

[Resolved(canBeNull: true)]
private OsuGame game { get; set; }

Expand Down Expand Up @@ -251,10 +255,10 @@ protected override void UpdateMods()
public override bool OnExiting(ScreenExitEvent e)
{
// the room may not be left immediately after a disconnection due to async flow,
// so checking the IsConnected status is also required.
if (client.Room == null || !client.IsConnected.Value)
// so checking the MultiplayerClient / IAPIAccess statuses is also required.
if (client.Room == null || !client.IsConnected.Value || api.State.Value != APIState.Online)
{
// room has not been created yet; exit immediately.
// room has not been created yet or we're offline; exit immediately.
return base.OnExiting(e);
}

Expand Down

0 comments on commit a472fe6

Please sign in to comment.