From 12876d7fb642500d7c5db31827a718a0af7b1798 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 22 Dec 2020 16:50:30 +0900 Subject: [PATCH] Add very basic error handling on ChangeSettings calls --- .../StatefulMultiplayerClient.cs | 6 +++--- .../Match/RealtimeMatchSettingsOverlay.cs | 9 +++++++-- .../RealtimeMultiplayer/RealtimeMatchSongSelect.cs | 13 +++++++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/osu.Game/Online/RealtimeMultiplayer/StatefulMultiplayerClient.cs b/osu.Game/Online/RealtimeMultiplayer/StatefulMultiplayerClient.cs index f56499f040..4ebd648689 100644 --- a/osu.Game/Online/RealtimeMultiplayer/StatefulMultiplayerClient.cs +++ b/osu.Game/Online/RealtimeMultiplayer/StatefulMultiplayerClient.cs @@ -127,10 +127,10 @@ public virtual Task LeaveRoom() /// /// The new room name, if any. /// The new room playlist item, if any. - public void ChangeSettings(Optional name = default, Optional item = default) + public Task ChangeSettings(Optional name = default, Optional item = default) { if (Room == null) - return; + throw new InvalidOperationException("Must be joined to a match to change settings."); // A dummy playlist item filled with the current room settings (except mods). var existingPlaylistItem = new PlaylistItem @@ -146,7 +146,7 @@ public void ChangeSettings(Optional name = default, Optional Schedule(() => + { + if (t.IsCompletedSuccessfully) + onSuccess(currentRoom.Value); + else + onError(t.Exception?.Message ?? "Error changing settings."); + })); } else { diff --git a/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimeMatchSongSelect.cs b/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimeMatchSongSelect.cs index b2ae5402a1..0feeed6fe5 100644 --- a/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimeMatchSongSelect.cs +++ b/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimeMatchSongSelect.cs @@ -6,6 +6,7 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Logging; using osu.Framework.Screens; using osu.Game.Online.Multiplayer; using osu.Game.Online.RealtimeMultiplayer; @@ -43,14 +44,22 @@ protected override bool OnStart() // If the client is already in a room, update via the client. // Otherwise, update the playlist directly in preparation for it to be submitted to the API on match creation. if (client.Room != null) - client.ChangeSettings(item: item); + { + client.ChangeSettings(item: item).ContinueWith(t => Schedule(() => + { + if (t.IsCompletedSuccessfully) + this.Exit(); + else + Logger.Log($"Could not use current beatmap ({t.Exception?.Message})", level: LogLevel.Important); + })); + } else { playlist.Clear(); playlist.Add(item); + this.Exit(); } - this.Exit(); return true; }