From 9076519710aa245baa50743789211aa5a34caf76 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 16 Nov 2021 13:49:06 +0900 Subject: [PATCH] Give MultiplayerRoom a playlist, remove RequestAllPlaylistItems() --- osu.Game/Online/Multiplayer/IMultiplayerRoomServer.cs | 5 ----- osu.Game/Online/Multiplayer/MultiplayerClient.cs | 10 ++++++---- osu.Game/Online/Multiplayer/MultiplayerRoom.cs | 4 ++++ osu.Game/Online/Multiplayer/OnlineMultiplayerClient.cs | 9 --------- .../Tests/Visual/Multiplayer/TestMultiplayerClient.cs | 6 ------ 5 files changed, 10 insertions(+), 24 deletions(-) diff --git a/osu.Game/Online/Multiplayer/IMultiplayerRoomServer.cs b/osu.Game/Online/Multiplayer/IMultiplayerRoomServer.cs index afaf1e89de..3e84e4b904 100644 --- a/osu.Game/Online/Multiplayer/IMultiplayerRoomServer.cs +++ b/osu.Game/Online/Multiplayer/IMultiplayerRoomServer.cs @@ -77,11 +77,6 @@ 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 77a1b51b7d..07f827e748 100644 --- a/osu.Game/Online/Multiplayer/MultiplayerClient.cs +++ b/osu.Game/Online/Multiplayer/MultiplayerClient.cs @@ -139,6 +139,9 @@ namespace osu.Game.Online.Multiplayer var joinedRoom = await JoinRoom(room.RoomID.Value.Value, password ?? room.Password.Value).ConfigureAwait(false); Debug.Assert(joinedRoom != null); + // Populate playlist items. + var playlistItems = await Task.WhenAll(joinedRoom.Playlist.Select(createPlaylistItem)).ConfigureAwait(false); + // Populate users. Debug.Assert(joinedRoom.Users != null); await Task.WhenAll(joinedRoom.Users.Select(PopulateUser)).ConfigureAwait(false); @@ -149,6 +152,9 @@ namespace osu.Game.Online.Multiplayer Room = joinedRoom; APIRoom = room; + APIRoom.Playlist.Clear(); + APIRoom.Playlist.AddRange(playlistItems); + Debug.Assert(LocalUser != null); addUserToAPIRoom(LocalUser); @@ -158,8 +164,6 @@ 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); @@ -307,8 +311,6 @@ namespace osu.Game.Online.Multiplayer public abstract Task StartMatch(); - public abstract Task RequestAllPlaylistItems(); - public abstract Task AddPlaylistItem(MultiplayerPlaylistItem item); Task IMultiplayerClient.RoomStateChanged(MultiplayerRoomState state) diff --git a/osu.Game/Online/Multiplayer/MultiplayerRoom.cs b/osu.Game/Online/Multiplayer/MultiplayerRoom.cs index 175c0e0e27..a60e70dab3 100644 --- a/osu.Game/Online/Multiplayer/MultiplayerRoom.cs +++ b/osu.Game/Online/Multiplayer/MultiplayerRoom.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using MessagePack; using Newtonsoft.Json; +using osu.Game.Online.Rooms; namespace osu.Game.Online.Multiplayer { @@ -50,6 +51,9 @@ namespace osu.Game.Online.Multiplayer [Key(5)] public MatchRoomState? MatchState { get; set; } + [Key(6)] + public IList Playlist { get; set; } = new List(); + [JsonConstructor] [SerializationConstructor] public MultiplayerRoom(long roomId) diff --git a/osu.Game/Online/Multiplayer/OnlineMultiplayerClient.cs b/osu.Game/Online/Multiplayer/OnlineMultiplayerClient.cs index 2609436890..7308c03ec3 100644 --- a/osu.Game/Online/Multiplayer/OnlineMultiplayerClient.cs +++ b/osu.Game/Online/Multiplayer/OnlineMultiplayerClient.cs @@ -3,7 +3,6 @@ #nullable enable -using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -152,14 +151,6 @@ 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(MultiplayerPlaylistItem item) { if (!IsConnected.Value) diff --git a/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs b/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs index e2dff61e7c..dc86c20b4c 100644 --- a/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs +++ b/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs @@ -294,12 +294,6 @@ 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(MultiplayerPlaylistItem item) { Debug.Assert(Room != null);