1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:07:52 +08:00

Fix "server-side" room playlist not updated

Remove unused using
This commit is contained in:
Dan Balasescu 2022-04-01 18:31:17 +09:00
parent 16d4544ff9
commit 6e6271d0c0
3 changed files with 39 additions and 8 deletions

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;

View File

@ -85,6 +85,19 @@ namespace osu.Game.Online.Rooms
Beatmap = beatmap;
}
public PlaylistItem(MultiplayerPlaylistItem item)
: this(new APIBeatmap { OnlineID = item.BeatmapID })
{
ID = item.ID;
OwnerID = item.OwnerID;
RulesetID = item.RulesetID;
Expired = item.Expired;
PlaylistOrder = item.PlaylistOrder;
PlayedAt = item.PlayedAt;
RequiredMods = item.RequiredMods.ToArray();
AllowedMods = item.AllowedMods.ToArray();
}
public void MarkInvalid() => valid.Value = false;
#region Newtonsoft.Json implicit ShouldSerialize() methods

View File

@ -31,7 +31,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
public override IBindable<bool> IsConnected => isConnected;
private readonly Bindable<bool> isConnected = new Bindable<bool>(true);
/// <summary>
/// The local client's <see cref="Room"/>. This is not always equivalent to the server-side room.
/// </summary>
public new Room? APIRoom => base.APIRoom;
public Action<MultiplayerRoom>? RoomSetupAction;
public bool RoomJoined { get; private set; }
@ -46,6 +50,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
/// </summary>
private readonly List<MultiplayerPlaylistItem> serverSidePlaylist = new List<MultiplayerPlaylistItem>();
/// <summary>
/// Guaranteed up-to-date API room.
/// </summary>
private Room? serverSideAPIRoom;
private MultiplayerPlaylistItem? currentItem => Room?.Playlist[currentIndex];
private int currentIndex;
private long lastPlaylistItemId;
@ -192,13 +201,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
protected override async Task<MultiplayerRoom> JoinRoom(long roomId, string? password = null)
{
var apiRoom = roomManager.ServerSideRooms.Single(r => r.RoomID.Value == roomId);
serverSideAPIRoom = roomManager.ServerSideRooms.Single(r => r.RoomID.Value == roomId);
if (password != apiRoom.Password.Value)
if (password != serverSideAPIRoom.Password.Value)
throw new InvalidOperationException("Invalid password.");
serverSidePlaylist.Clear();
serverSidePlaylist.AddRange(apiRoom.Playlist.Select(item => new MultiplayerPlaylistItem(item)));
serverSidePlaylist.AddRange(serverSideAPIRoom.Playlist.Select(item => new MultiplayerPlaylistItem(item)));
lastPlaylistItemId = serverSidePlaylist.Max(item => item.ID);
var localUser = new MultiplayerRoomUser(api.LocalUser.Value.Id)
@ -210,11 +219,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
Settings =
{
Name = apiRoom.Name.Value,
MatchType = apiRoom.Type.Value,
Name = serverSideAPIRoom.Name.Value,
MatchType = serverSideAPIRoom.Type.Value,
Password = password,
QueueMode = apiRoom.QueueMode.Value,
AutoStartDuration = apiRoom.AutoStartDuration.Value
QueueMode = serverSideAPIRoom.QueueMode.Value,
AutoStartDuration = serverSideAPIRoom.AutoStartDuration.Value
},
Playlist = serverSidePlaylist.ToList(),
Users = { localUser },
@ -479,6 +488,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
Debug.Assert(Room != null);
Debug.Assert(APIRoom != null);
Debug.Assert(serverSideAPIRoom != null);
var item = serverSidePlaylist.Find(i => i.ID == playlistItemId);
@ -495,6 +505,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
throw new InvalidOperationException("Attempted to remove an item which has already been played.");
serverSidePlaylist.Remove(item);
serverSideAPIRoom.Playlist.RemoveAll(i => i.ID == item.ID);
await ((IMultiplayerClient)this).PlaylistItemRemoved(playlistItemId).ConfigureAwait(false);
await updateCurrentItem(Room).ConfigureAwait(false);
@ -576,10 +587,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
private async Task addItem(MultiplayerPlaylistItem item)
{
Debug.Assert(Room != null);
Debug.Assert(serverSideAPIRoom != null);
item.ID = ++lastPlaylistItemId;
serverSidePlaylist.Add(item);
serverSideAPIRoom.Playlist.Add(new PlaylistItem(item));
await ((IMultiplayerClient)this).PlaylistItemAdded(item).ConfigureAwait(false);
await updatePlaylistOrder(Room).ConfigureAwait(false);
@ -603,6 +616,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
private async Task updatePlaylistOrder(MultiplayerRoom room)
{
Debug.Assert(serverSideAPIRoom != null);
List<MultiplayerPlaylistItem> orderedActiveItems;
switch (room.Settings.QueueMode)
@ -648,6 +663,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
await ((IMultiplayerClient)this).PlaylistItemChanged(item).ConfigureAwait(false);
}
// Also ensure that the API room's playlist is correct.
foreach (var item in serverSideAPIRoom.Playlist)
item.PlaylistOrder = serverSidePlaylist.Single(i => i.ID == item.ID).PlaylistOrder;
}
}
}