From ce47f456ec4a8f61b5c9842c6334e344fe172164 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Sat, 13 Nov 2021 04:42:14 +0900 Subject: [PATCH] Change API for retrieving playlist items on join --- osu.Game/Online/Multiplayer/IMultiplayerRoomServer.cs | 5 +++++ osu.Game/Online/Multiplayer/MultiplayerClient.cs | 4 ++++ osu.Game/Online/Multiplayer/OnlineMultiplayerClient.cs | 9 +++++++++ .../Tests/Visual/Multiplayer/TestMultiplayerClient.cs | 10 ++++++---- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/osu.Game/Online/Multiplayer/IMultiplayerRoomServer.cs b/osu.Game/Online/Multiplayer/IMultiplayerRoomServer.cs index d6ff4f4993..d00022d6f5 100644 --- a/osu.Game/Online/Multiplayer/IMultiplayerRoomServer.cs +++ b/osu.Game/Online/Multiplayer/IMultiplayerRoomServer.cs @@ -77,6 +77,11 @@ namespace osu.Game.Online.Multiplayer /// If an attempt to start the game occurs when the game's (or users') state disallows it. Task StartMatch(); + /// + /// Requests for all playlist items of the room to be sent to the client. + /// + Task RequestAllPlaylistItems(); + /// /// Adds an item to the playlist. /// diff --git a/osu.Game/Online/Multiplayer/MultiplayerClient.cs b/osu.Game/Online/Multiplayer/MultiplayerClient.cs index 43c1148ba9..638eb30ee9 100644 --- a/osu.Game/Online/Multiplayer/MultiplayerClient.cs +++ b/osu.Game/Online/Multiplayer/MultiplayerClient.cs @@ -158,6 +158,8 @@ namespace osu.Game.Online.Multiplayer OnRoomJoined(); }, cancellationSource.Token).ConfigureAwait(false); + await RequestAllPlaylistItems().ConfigureAwait(false); + // Update room settings. await updateLocalRoomSettings(joinedRoom.Settings, cancellationSource.Token).ConfigureAwait(false); }, cancellationSource.Token).ConfigureAwait(false); @@ -305,6 +307,8 @@ namespace osu.Game.Online.Multiplayer public abstract Task StartMatch(); + public abstract Task RequestAllPlaylistItems(); + public abstract Task AddPlaylistItem(APIPlaylistItem item); public abstract Task RemovePlaylistItem(long playlistItemId); diff --git a/osu.Game/Online/Multiplayer/OnlineMultiplayerClient.cs b/osu.Game/Online/Multiplayer/OnlineMultiplayerClient.cs index 2f0e1623e7..c7a751500e 100644 --- a/osu.Game/Online/Multiplayer/OnlineMultiplayerClient.cs +++ b/osu.Game/Online/Multiplayer/OnlineMultiplayerClient.cs @@ -3,6 +3,7 @@ #nullable enable +using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -151,6 +152,14 @@ namespace osu.Game.Online.Multiplayer return connection.InvokeAsync(nameof(IMultiplayerServer.StartMatch)); } + public override Task RequestAllPlaylistItems() + { + if (!IsConnected.Value) + return Task.FromResult(Array.Empty()); + + return connection.InvokeAsync(nameof(IMultiplayerServer.RequestAllPlaylistItems)); + } + public override Task AddPlaylistItem(APIPlaylistItem item) { if (!IsConnected.Value) diff --git a/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs b/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs index a4175defa2..dc871de3f5 100644 --- a/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs +++ b/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs @@ -199,10 +199,6 @@ namespace osu.Game.Tests.Visual.Multiplayer // emulate the server sending this after the join room. scheduler required to make sure the join room event is fired first (in Join). changeMatchType(Room.Settings.MatchType).Wait(); - - // emulate the server sending all playlist items after room join. - var serverSideRoom = roomManager.ServerSideRooms.Single(r => r.RoomID.Value == APIRoom.RoomID.Value); - Task.WhenAll(serverSideRoom.Playlist.Select(i => ((IMultiplayerClient)this).PlaylistItemAdded(new APIPlaylistItem(i)))).Wait(); } protected override Task LeaveRoomInternal() => Task.CompletedTask; @@ -298,6 +294,12 @@ namespace osu.Game.Tests.Visual.Multiplayer return ((IMultiplayerClient)this).LoadRequested(); } + public override async Task RequestAllPlaylistItems() + { + foreach (var item in playlistItems) + await ((IMultiplayerClient)this).PlaylistItemAdded(item).ConfigureAwait(false); + } + public override async Task AddPlaylistItem(APIPlaylistItem item) { Debug.Assert(Room != null);