Add very basic error handling on ChangeSettings calls

This commit is contained in:
Dean Herbert 2020-12-22 16:50:30 +09:00
parent 2d7174d99c
commit 12876d7fb6
3 changed files with 21 additions and 7 deletions

View File

@ -127,10 +127,10 @@ public virtual Task LeaveRoom()
/// </remarks>
/// <param name="name">The new room name, if any.</param>
/// <param name="item">The new room playlist item, if any.</param>
public void ChangeSettings(Optional<string> name = default, Optional<PlaylistItem> item = default)
public Task ChangeSettings(Optional<string> name = default, Optional<PlaylistItem> 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<string> name = default, Optional<PlaylistIte
RulesetID = Room.Settings.RulesetID
};
ChangeSettings(new MultiplayerRoomSettings
return ChangeSettings(new MultiplayerRoomSettings
{
Name = name.GetOr(Room.Settings.Name),
BeatmapID = item.GetOr(existingPlaylistItem).BeatmapID,

View File

@ -294,8 +294,13 @@ private void apply()
// Otherwise, update the room directly in preparation for it to be submitted to the API on match creation.
if (client.Room != null)
{
client.ChangeSettings(name: NameField.Text);
onSuccess(currentRoom.Value);
client.ChangeSettings(name: NameField.Text).ContinueWith(t => Schedule(() =>
{
if (t.IsCompletedSuccessfully)
onSuccess(currentRoom.Value);
else
onError(t.Exception?.Message ?? "Error changing settings.");
}));
}
else
{

View File

@ -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;
}