mirror of
https://github.com/osukey/osukey.git
synced 2025-06-10 13:58:01 +09:00
Fix "server-side" room playlist not updated
Remove unused using
This commit is contained in:
parent
16d4544ff9
commit
6e6271d0c0
@ -2,7 +2,6 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
@ -85,6 +85,19 @@ namespace osu.Game.Online.Rooms
|
|||||||
Beatmap = beatmap;
|
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;
|
public void MarkInvalid() => valid.Value = false;
|
||||||
|
|
||||||
#region Newtonsoft.Json implicit ShouldSerialize() methods
|
#region Newtonsoft.Json implicit ShouldSerialize() methods
|
||||||
|
@ -31,7 +31,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
public override IBindable<bool> IsConnected => isConnected;
|
public override IBindable<bool> IsConnected => isConnected;
|
||||||
private readonly Bindable<bool> isConnected = new Bindable<bool>(true);
|
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 new Room? APIRoom => base.APIRoom;
|
||||||
|
|
||||||
public Action<MultiplayerRoom>? RoomSetupAction;
|
public Action<MultiplayerRoom>? RoomSetupAction;
|
||||||
|
|
||||||
public bool RoomJoined { get; private set; }
|
public bool RoomJoined { get; private set; }
|
||||||
@ -46,6 +50,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly List<MultiplayerPlaylistItem> serverSidePlaylist = new List<MultiplayerPlaylistItem>();
|
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 MultiplayerPlaylistItem? currentItem => Room?.Playlist[currentIndex];
|
||||||
private int currentIndex;
|
private int currentIndex;
|
||||||
private long lastPlaylistItemId;
|
private long lastPlaylistItemId;
|
||||||
@ -192,13 +201,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
protected override async Task<MultiplayerRoom> JoinRoom(long roomId, string? password = null)
|
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.");
|
throw new InvalidOperationException("Invalid password.");
|
||||||
|
|
||||||
serverSidePlaylist.Clear();
|
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);
|
lastPlaylistItemId = serverSidePlaylist.Max(item => item.ID);
|
||||||
|
|
||||||
var localUser = new MultiplayerRoomUser(api.LocalUser.Value.Id)
|
var localUser = new MultiplayerRoomUser(api.LocalUser.Value.Id)
|
||||||
@ -210,11 +219,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
Settings =
|
Settings =
|
||||||
{
|
{
|
||||||
Name = apiRoom.Name.Value,
|
Name = serverSideAPIRoom.Name.Value,
|
||||||
MatchType = apiRoom.Type.Value,
|
MatchType = serverSideAPIRoom.Type.Value,
|
||||||
Password = password,
|
Password = password,
|
||||||
QueueMode = apiRoom.QueueMode.Value,
|
QueueMode = serverSideAPIRoom.QueueMode.Value,
|
||||||
AutoStartDuration = apiRoom.AutoStartDuration.Value
|
AutoStartDuration = serverSideAPIRoom.AutoStartDuration.Value
|
||||||
},
|
},
|
||||||
Playlist = serverSidePlaylist.ToList(),
|
Playlist = serverSidePlaylist.ToList(),
|
||||||
Users = { localUser },
|
Users = { localUser },
|
||||||
@ -479,6 +488,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
Debug.Assert(Room != null);
|
Debug.Assert(Room != null);
|
||||||
Debug.Assert(APIRoom != null);
|
Debug.Assert(APIRoom != null);
|
||||||
|
Debug.Assert(serverSideAPIRoom != null);
|
||||||
|
|
||||||
var item = serverSidePlaylist.Find(i => i.ID == playlistItemId);
|
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.");
|
throw new InvalidOperationException("Attempted to remove an item which has already been played.");
|
||||||
|
|
||||||
serverSidePlaylist.Remove(item);
|
serverSidePlaylist.Remove(item);
|
||||||
|
serverSideAPIRoom.Playlist.RemoveAll(i => i.ID == item.ID);
|
||||||
await ((IMultiplayerClient)this).PlaylistItemRemoved(playlistItemId).ConfigureAwait(false);
|
await ((IMultiplayerClient)this).PlaylistItemRemoved(playlistItemId).ConfigureAwait(false);
|
||||||
|
|
||||||
await updateCurrentItem(Room).ConfigureAwait(false);
|
await updateCurrentItem(Room).ConfigureAwait(false);
|
||||||
@ -576,10 +587,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
private async Task addItem(MultiplayerPlaylistItem item)
|
private async Task addItem(MultiplayerPlaylistItem item)
|
||||||
{
|
{
|
||||||
Debug.Assert(Room != null);
|
Debug.Assert(Room != null);
|
||||||
|
Debug.Assert(serverSideAPIRoom != null);
|
||||||
|
|
||||||
item.ID = ++lastPlaylistItemId;
|
item.ID = ++lastPlaylistItemId;
|
||||||
|
|
||||||
serverSidePlaylist.Add(item);
|
serverSidePlaylist.Add(item);
|
||||||
|
serverSideAPIRoom.Playlist.Add(new PlaylistItem(item));
|
||||||
await ((IMultiplayerClient)this).PlaylistItemAdded(item).ConfigureAwait(false);
|
await ((IMultiplayerClient)this).PlaylistItemAdded(item).ConfigureAwait(false);
|
||||||
|
|
||||||
await updatePlaylistOrder(Room).ConfigureAwait(false);
|
await updatePlaylistOrder(Room).ConfigureAwait(false);
|
||||||
@ -603,6 +616,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
private async Task updatePlaylistOrder(MultiplayerRoom room)
|
private async Task updatePlaylistOrder(MultiplayerRoom room)
|
||||||
{
|
{
|
||||||
|
Debug.Assert(serverSideAPIRoom != null);
|
||||||
|
|
||||||
List<MultiplayerPlaylistItem> orderedActiveItems;
|
List<MultiplayerPlaylistItem> orderedActiveItems;
|
||||||
|
|
||||||
switch (room.Settings.QueueMode)
|
switch (room.Settings.QueueMode)
|
||||||
@ -648,6 +663,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
await ((IMultiplayerClient)this).PlaylistItemChanged(item).ConfigureAwait(false);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user