1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 11:03:22 +08:00

Merge pull request #23551 from timiimit/update-multiplayer-room-diff-range

Fix multiplayer room difficulty range not being updated
This commit is contained in:
Bartłomiej Dach 2023-06-03 19:41:50 +02:00 committed by GitHub
commit 51149343fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 26 deletions

View File

@ -129,7 +129,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
Playlist = Playlist =
{ {
new MultiplayerPlaylistItem(playlistItem), TestMultiplayerClient.CreateMultiplayerPlaylistItem(playlistItem),
}, },
Users = { localUser }, Users = { localUser },
Host = localUser, Host = localUser,

View File

@ -906,7 +906,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
enterGameplay(); enterGameplay();
AddStep("join other user", () => multiplayerClient.AddUser(new APIUser { Id = 1234 })); AddStep("join other user", () => multiplayerClient.AddUser(new APIUser { Id = 1234 }));
AddStep("add item as other user", () => multiplayerClient.AddUserPlaylistItem(1234, new MultiplayerPlaylistItem( AddStep("add item as other user", () => multiplayerClient.AddUserPlaylistItem(1234, TestMultiplayerClient.CreateMultiplayerPlaylistItem(
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo) new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
{ {
RulesetID = new OsuRuleset().RulesetInfo.OnlineID, RulesetID = new OsuRuleset().RulesetInfo.OnlineID,
@ -938,7 +938,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
enterGameplay(); enterGameplay();
AddStep("join other user", () => multiplayerClient.AddUser(new APIUser { Id = 1234 })); AddStep("join other user", () => multiplayerClient.AddUser(new APIUser { Id = 1234 }));
AddStep("add item as other user", () => multiplayerClient.AddUserPlaylistItem(1234, new MultiplayerPlaylistItem( AddStep("add item as other user", () => multiplayerClient.AddUserPlaylistItem(1234, TestMultiplayerClient.CreateMultiplayerPlaylistItem(
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo) new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
{ {
RulesetID = new OsuRuleset().RulesetInfo.OnlineID, RulesetID = new OsuRuleset().RulesetInfo.OnlineID,

View File

@ -215,7 +215,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
/// </summary> /// </summary>
private void addItemStep(bool expired = false, int? userId = null) => AddStep("add item", () => private void addItemStep(bool expired = false, int? userId = null) => AddStep("add item", () =>
{ {
MultiplayerClient.AddUserPlaylistItem(userId ?? API.LocalUser.Value.OnlineID, new MultiplayerPlaylistItem(new PlaylistItem(importedBeatmap) MultiplayerClient.AddUserPlaylistItem(userId ?? API.LocalUser.Value.OnlineID, TestMultiplayerClient.CreateMultiplayerPlaylistItem(new PlaylistItem(importedBeatmap)
{ {
Expired = expired, Expired = expired,
PlayedAt = DateTimeOffset.Now PlayedAt = DateTimeOffset.Now

View File

@ -130,7 +130,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("add playlist item", () => AddStep("add playlist item", () =>
{ {
MultiplayerPlaylistItem item = new MultiplayerPlaylistItem(new PlaylistItem(importedBeatmap)); MultiplayerPlaylistItem item = TestMultiplayerClient.CreateMultiplayerPlaylistItem(new PlaylistItem(importedBeatmap));
MultiplayerClient.AddUserPlaylistItem(userId(), item).WaitSafely(); MultiplayerClient.AddUserPlaylistItem(userId(), item).WaitSafely();

View File

@ -783,7 +783,7 @@ namespace osu.Game.Online.Multiplayer
RoomUpdated?.Invoke(); RoomUpdated?.Invoke();
} }
private PlaylistItem createPlaylistItem(MultiplayerPlaylistItem item) => new PlaylistItem(new APIBeatmap { OnlineID = item.BeatmapID }) private PlaylistItem createPlaylistItem(MultiplayerPlaylistItem item) => new PlaylistItem(new APIBeatmap { OnlineID = item.BeatmapID, StarRating = item.StarRating })
{ {
ID = item.ID, ID = item.ID,
OwnerID = item.OwnerID, OwnerID = item.OwnerID,

View File

@ -53,22 +53,12 @@ namespace osu.Game.Online.Rooms
[Key(9)] [Key(9)]
public DateTimeOffset? PlayedAt { get; set; } public DateTimeOffset? PlayedAt { get; set; }
[Key(10)]
public double StarRating { get; set; }
[SerializationConstructor]
public MultiplayerPlaylistItem() public MultiplayerPlaylistItem()
{ {
} }
public MultiplayerPlaylistItem(PlaylistItem item)
{
ID = item.ID;
OwnerID = item.OwnerID;
BeatmapID = item.Beatmap.OnlineID;
BeatmapChecksum = item.Beatmap.MD5Hash;
RulesetID = item.RulesetID;
RequiredMods = item.RequiredMods.ToArray();
AllowedMods = item.AllowedMods.ToArray();
Expired = item.Expired;
PlaylistOrder = item.PlaylistOrder ?? 0;
PlayedAt = item.PlayedAt;
}
} }
} }

View File

@ -91,7 +91,7 @@ namespace osu.Game.Online.Rooms
} }
public PlaylistItem(MultiplayerPlaylistItem item) public PlaylistItem(MultiplayerPlaylistItem item)
: this(new APIBeatmap { OnlineID = item.BeatmapID }) : this(new APIBeatmap { OnlineID = item.BeatmapID, StarRating = item.StarRating })
{ {
ID = item.ID; ID = item.ID;
OwnerID = item.OwnerID; OwnerID = item.OwnerID;

View File

@ -85,15 +85,15 @@ namespace osu.Game.Screens.OnlinePlay.Components
StarDifficulty minDifficulty; StarDifficulty minDifficulty;
StarDifficulty maxDifficulty; StarDifficulty maxDifficulty;
if (DifficultyRange.Value != null) if (DifficultyRange.Value != null && Playlist.Count == 0)
{ {
// When Playlist is empty (in lounge) we take retrieved range
minDifficulty = new StarDifficulty(DifficultyRange.Value.Min, 0); minDifficulty = new StarDifficulty(DifficultyRange.Value.Min, 0);
maxDifficulty = new StarDifficulty(DifficultyRange.Value.Max, 0); maxDifficulty = new StarDifficulty(DifficultyRange.Value.Max, 0);
} }
else else
{ {
// In multiplayer rooms, the beatmaps of playlist items will not be populated to a point this can be correct. // When Playlist is not empty (in room) we compute actual range
// Either populating them via BeatmapLookupCache or polling the API for the room's DifficultyRange will be required.
var orderedDifficulties = Playlist.Select(p => p.Beatmap).OrderBy(b => b.StarRating).ToArray(); var orderedDifficulties = Playlist.Select(p => p.Beatmap).OrderBy(b => b.StarRating).ToArray();
minDifficulty = new StarDifficulty(orderedDifficulties.Length > 0 ? orderedDifficulties[0].StarRating : 0, 0); minDifficulty = new StarDifficulty(orderedDifficulties.Length > 0 ? orderedDifficulties[0].StarRating : 0, 0);

View File

@ -108,7 +108,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
// simulate the server's automatic assignment of users to teams on join. // simulate the server's automatic assignment of users to teams on join.
// the "best" team is the one with the least users on it. // the "best" team is the one with the least users on it.
int bestTeam = teamVersus.Teams int bestTeam = teamVersus.Teams
.Select(team => (teamID: team.ID, userCount: ServerRoom.Users.Count(u => (u.MatchState as TeamVersusUserState)?.TeamID == team.ID))).MinBy(pair => pair.userCount).teamID; .Select(team => (teamID: team.ID, userCount: ServerRoom.Users.Count(u => (u.MatchState as TeamVersusUserState)?.TeamID == team.ID)))
.MinBy(pair => pair.userCount).teamID;
user.MatchState = new TeamVersusUserState { TeamID = bestTeam }; user.MatchState = new TeamVersusUserState { TeamID = bestTeam };
((IMultiplayerClient)this).MatchUserStateChanged(clone(user.UserID), clone(user.MatchState)).WaitSafely(); ((IMultiplayerClient)this).MatchUserStateChanged(clone(user.UserID), clone(user.MatchState)).WaitSafely();
@ -232,7 +233,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
QueueMode = ServerAPIRoom.QueueMode.Value, QueueMode = ServerAPIRoom.QueueMode.Value,
AutoStartDuration = ServerAPIRoom.AutoStartDuration.Value AutoStartDuration = ServerAPIRoom.AutoStartDuration.Value
}, },
Playlist = ServerAPIRoom.Playlist.Select(item => new MultiplayerPlaylistItem(item)).ToList(), Playlist = ServerAPIRoom.Playlist.Select(CreateMultiplayerPlaylistItem).ToList(),
Users = { localUser }, Users = { localUser },
Host = localUser Host = localUser
}; };
@ -637,5 +638,20 @@ namespace osu.Game.Tests.Visual.Multiplayer
byte[]? serialized = MessagePackSerializer.Serialize(typeof(T), incoming, SignalRUnionWorkaroundResolver.OPTIONS); byte[]? serialized = MessagePackSerializer.Serialize(typeof(T), incoming, SignalRUnionWorkaroundResolver.OPTIONS);
return MessagePackSerializer.Deserialize<T>(serialized, SignalRUnionWorkaroundResolver.OPTIONS); return MessagePackSerializer.Deserialize<T>(serialized, SignalRUnionWorkaroundResolver.OPTIONS);
} }
public static MultiplayerPlaylistItem CreateMultiplayerPlaylistItem(PlaylistItem item) => new MultiplayerPlaylistItem
{
ID = item.ID,
OwnerID = item.OwnerID,
BeatmapID = item.Beatmap.OnlineID,
BeatmapChecksum = item.Beatmap.MD5Hash,
RulesetID = item.RulesetID,
RequiredMods = item.RequiredMods.ToArray(),
AllowedMods = item.AllowedMods.ToArray(),
Expired = item.Expired,
PlaylistOrder = item.PlaylistOrder ?? 0,
PlayedAt = item.PlayedAt,
StarRating = item.Beatmap.StarRating,
};
} }
} }