mirror of
https://github.com/ppy/osu.git
synced 2025-01-06 08:22:56 +08:00
Add very basic error handling on ChangeSettings calls
This commit is contained in:
parent
2d7174d99c
commit
12876d7fb6
@ -127,10 +127,10 @@ namespace osu.Game.Online.RealtimeMultiplayer
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="name">The new room name, if any.</param>
|
/// <param name="name">The new room name, if any.</param>
|
||||||
/// <param name="item">The new room playlist item, 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)
|
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).
|
// A dummy playlist item filled with the current room settings (except mods).
|
||||||
var existingPlaylistItem = new PlaylistItem
|
var existingPlaylistItem = new PlaylistItem
|
||||||
@ -146,7 +146,7 @@ namespace osu.Game.Online.RealtimeMultiplayer
|
|||||||
RulesetID = Room.Settings.RulesetID
|
RulesetID = Room.Settings.RulesetID
|
||||||
};
|
};
|
||||||
|
|
||||||
ChangeSettings(new MultiplayerRoomSettings
|
return ChangeSettings(new MultiplayerRoomSettings
|
||||||
{
|
{
|
||||||
Name = name.GetOr(Room.Settings.Name),
|
Name = name.GetOr(Room.Settings.Name),
|
||||||
BeatmapID = item.GetOr(existingPlaylistItem).BeatmapID,
|
BeatmapID = item.GetOr(existingPlaylistItem).BeatmapID,
|
||||||
|
@ -294,8 +294,13 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer.Match
|
|||||||
// Otherwise, update the room directly in preparation for it to be submitted to the API on match creation.
|
// Otherwise, update the room directly in preparation for it to be submitted to the API on match creation.
|
||||||
if (client.Room != null)
|
if (client.Room != null)
|
||||||
{
|
{
|
||||||
client.ChangeSettings(name: NameField.Text);
|
client.ChangeSettings(name: NameField.Text).ContinueWith(t => Schedule(() =>
|
||||||
onSuccess(currentRoom.Value);
|
{
|
||||||
|
if (t.IsCompletedSuccessfully)
|
||||||
|
onSuccess(currentRoom.Value);
|
||||||
|
else
|
||||||
|
onError(t.Exception?.Message ?? "Error changing settings.");
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,7 @@ using Humanizer;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Online.RealtimeMultiplayer;
|
using osu.Game.Online.RealtimeMultiplayer;
|
||||||
@ -43,14 +44,22 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
|||||||
// If the client is already in a room, update via the client.
|
// 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.
|
// Otherwise, update the playlist directly in preparation for it to be submitted to the API on match creation.
|
||||||
if (client.Room != null)
|
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
|
else
|
||||||
{
|
{
|
||||||
playlist.Clear();
|
playlist.Clear();
|
||||||
playlist.Add(item);
|
playlist.Add(item);
|
||||||
|
this.Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Exit();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user