From 5c8c121446e44f92840ff74a783fc5c9861db4dc Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 11 Nov 2021 23:39:15 +0900 Subject: [PATCH] Update behaviour to match server (removing playlist items) + tests --- .../TestSceneFreeForAllQueueMode.cs | 6 +-- .../Multiplayer/TestMultiplayerClient.cs | 49 ++++++++++--------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/osu.Game.Tests/Visual/Multiplayer/QueueingModes/TestSceneFreeForAllQueueMode.cs b/osu.Game.Tests/Visual/Multiplayer/QueueingModes/TestSceneFreeForAllQueueMode.cs index 906e528ac5..0cf330bbbb 100644 --- a/osu.Game.Tests/Visual/Multiplayer/QueueingModes/TestSceneFreeForAllQueueMode.cs +++ b/osu.Game.Tests/Visual/Multiplayer/QueueingModes/TestSceneFreeForAllQueueMode.cs @@ -73,9 +73,9 @@ namespace osu.Game.Tests.Visual.Multiplayer.QueueingModes RunGameplay(); AddStep("change queue mode", () => Client.ChangeSettings(queueMode: QueueModes.HostOnly)); - AddAssert("playlist has 1 item", () => Client.APIRoom?.Playlist.Count == 1); - AddAssert("playlist item is the same as last selected", () => Client.APIRoom?.Playlist[0].Beatmap.Value.OnlineID == OtherBeatmap.OnlineID); - AddAssert("playlist item is not expired", () => Client.APIRoom?.Playlist[0].Expired == false); + AddAssert("playlist has 2 items", () => Client.APIRoom?.Playlist.Count == 2); + AddAssert("playlist item is the other beatmap", () => Client.CurrentMatchPlayingItem.Value?.BeatmapID == OtherBeatmap.OnlineID); + AddAssert("playlist item is not expired", () => Client.APIRoom?.Playlist[1].Expired == false); } private void addItem(Func beatmap) diff --git a/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs b/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs index 0e0c9480dd..036afb26b4 100644 --- a/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs +++ b/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs @@ -209,29 +209,10 @@ namespace osu.Game.Tests.Visual.Multiplayer Debug.Assert(Room != null); Debug.Assert(APIRoom != null); - switch (Room.Settings.QueueMode, settings.QueueMode) - { - case (QueueModes.HostOnly, QueueModes.HostOnly): - break; + // Server is authoritative for the time being. + settings.PlaylistItemId = Room.Settings.PlaylistItemId; - // Host-only is incompatible with other queueing modes, so expire all non-expired items. - case (QueueModes.HostOnly, _): - case (_, QueueModes.HostOnly): - foreach (var playlistItem in APIRoom.Playlist.Where(i => !i.Expired).ToArray()) - { - playlistItem.Expired = true; - await ((IMultiplayerClient)this).PlaylistItemChanged(new APIPlaylistItem(playlistItem)).ConfigureAwait(false); - } - - break; - } - - await ((IMultiplayerClient)this).SettingsChanged(settings).ConfigureAwait(false); - - foreach (var user in Room.Users.Where(u => u.State == MultiplayerUserState.Ready)) - ChangeUserState(user.UserID, MultiplayerUserState.Idle); - - await changeMatchType(settings.MatchType).ConfigureAwait(false); + await changeSettings(settings).ConfigureAwait(false); } public override Task ChangeState(MultiplayerUserState newState) @@ -344,6 +325,28 @@ namespace osu.Game.Tests.Visual.Multiplayer return Task.FromResult(apiSet); } + private async Task changeSettings(MultiplayerRoomSettings settings) + { + Debug.Assert(Room != null); + Debug.Assert(APIRoom != null); + + if (settings.QueueMode == QueueModes.HostOnly) + { + foreach (var playlistItem in APIRoom.Playlist.Where(i => !i.Expired && i.ID != Room.Settings.PlaylistItemId).ToArray()) + { + APIRoom.Playlist.Remove(playlistItem); + await ((IMultiplayerClient)this).PlaylistItemRemoved(playlistItem.ID).ConfigureAwait(false); + } + } + + await ((IMultiplayerClient)this).SettingsChanged(settings).ConfigureAwait(false); + + foreach (var user in Room.Users.Where(u => u.State == MultiplayerUserState.Ready)) + ChangeUserState(user.UserID, MultiplayerUserState.Idle); + + await changeMatchType(settings.MatchType).ConfigureAwait(false); + } + private async Task changeMatchType(MatchType type) { Debug.Assert(Room != null); @@ -417,7 +420,7 @@ namespace osu.Game.Tests.Visual.Multiplayer if (nextId != Room.Settings.PlaylistItemId) { Room.Settings.PlaylistItemId = nextId; - await ChangeSettings(Room.Settings).ConfigureAwait(false); + await changeSettings(Room.Settings).ConfigureAwait(false); } } }