mirror of
https://github.com/ppy/osu.git
synced 2024-11-15 14:27:51 +08:00
Switch multiplayer away from using UserLookupCache
After switching `UserLookupCache` to `GET /users/lookup` from `GET /users`, multiplayer sort of breaks, since the former endpoint does not return `ruleset_statistics`, which are used in multiplayer to show users' ranks. Therefore, switch multiplayer to use the appropriate request type directly.
This commit is contained in:
parent
17bc5ce5a9
commit
5104f3e7ac
@ -165,11 +165,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
AddUntilStep("wait for room join", () => RoomJoined);
|
AddUntilStep("wait for room join", () => RoomJoined);
|
||||||
|
|
||||||
AddStep("join other user (ready)", () =>
|
AddStep("join other user", void () => MultiplayerClient.AddUser(new APIUser { Id = PLAYER_1_ID }));
|
||||||
{
|
AddUntilStep("wait for user populated", () => MultiplayerClient.ClientRoom!.Users.Single(u => u.UserID == PLAYER_1_ID).User, () => Is.Not.Null);
|
||||||
MultiplayerClient.AddUser(new APIUser { Id = PLAYER_1_ID });
|
AddStep("other user ready", () => MultiplayerClient.ChangeUserState(PLAYER_1_ID, MultiplayerUserState.Ready));
|
||||||
MultiplayerClient.ChangeUserState(PLAYER_1_ID, MultiplayerUserState.Ready);
|
|
||||||
});
|
|
||||||
|
|
||||||
ClickButtonWhenEnabled<MultiplayerSpectateButton>();
|
ClickButtonWhenEnabled<MultiplayerSpectateButton>();
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Localisation;
|
using osu.Game.Localisation;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Online.Multiplayer.Countdown;
|
using osu.Game.Online.Multiplayer.Countdown;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
@ -188,7 +189,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
|
|
||||||
// Populate users.
|
// Populate users.
|
||||||
Debug.Assert(joinedRoom.Users != null);
|
Debug.Assert(joinedRoom.Users != null);
|
||||||
await Task.WhenAll(joinedRoom.Users.Select(PopulateUser)).ConfigureAwait(false);
|
await PopulateUsers(joinedRoom.Users).ConfigureAwait(false);
|
||||||
|
|
||||||
// Update the stored room (must be done on update thread for thread-safety).
|
// Update the stored room (must be done on update thread for thread-safety).
|
||||||
await runOnUpdateThreadAsync(() =>
|
await runOnUpdateThreadAsync(() =>
|
||||||
@ -416,7 +417,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
|
|
||||||
async Task IMultiplayerClient.UserJoined(MultiplayerRoomUser user)
|
async Task IMultiplayerClient.UserJoined(MultiplayerRoomUser user)
|
||||||
{
|
{
|
||||||
await PopulateUser(user).ConfigureAwait(false);
|
await PopulateUsers([user]).ConfigureAwait(false);
|
||||||
|
|
||||||
Scheduler.Add(() =>
|
Scheduler.Add(() =>
|
||||||
{
|
{
|
||||||
@ -803,10 +804,26 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Populates the <see cref="APIUser"/> for a given <see cref="MultiplayerRoomUser"/>.
|
/// Populates the <see cref="APIUser"/> for a given collection of <see cref="MultiplayerRoomUser"/>s.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="multiplayerUser">The <see cref="MultiplayerRoomUser"/> to populate.</param>
|
/// <param name="multiplayerUsers">The <see cref="MultiplayerRoomUser"/>s to populate.</param>
|
||||||
protected async Task PopulateUser(MultiplayerRoomUser multiplayerUser) => multiplayerUser.User ??= await userLookupCache.GetUserAsync(multiplayerUser.UserID).ConfigureAwait(false);
|
protected async Task PopulateUsers(IEnumerable<MultiplayerRoomUser> multiplayerUsers)
|
||||||
|
{
|
||||||
|
var request = new GetUsersRequest(multiplayerUsers.Select(u => u.UserID).Distinct().ToArray());
|
||||||
|
await API.PerformAsync(request).ContinueWith(t =>
|
||||||
|
{
|
||||||
|
if (request.Response == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var users = request.Response.Users.ToDictionary(user => user.Id);
|
||||||
|
|
||||||
|
foreach (var multiplayerUser in multiplayerUsers)
|
||||||
|
{
|
||||||
|
if (users.TryGetValue(multiplayerUser.UserID, out var user))
|
||||||
|
multiplayerUser.User = user;
|
||||||
|
}
|
||||||
|
}).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the local room settings with the given <see cref="MultiplayerRoomSettings"/>.
|
/// Updates the local room settings with the given <see cref="MultiplayerRoomSettings"/>.
|
||||||
|
@ -214,6 +214,22 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
|||||||
getBeatmapSetRequest.TriggerSuccess(OsuTestScene.CreateAPIBeatmapSet(baseBeatmap));
|
getBeatmapSetRequest.TriggerSuccess(OsuTestScene.CreateAPIBeatmapSet(baseBeatmap));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case GetUsersRequest getUsersRequest:
|
||||||
|
{
|
||||||
|
getUsersRequest.TriggerSuccess(new GetUsersResponse
|
||||||
|
{
|
||||||
|
Users = getUsersRequest.UserIds.Select(id => id == TestUserLookupCache.UNRESOLVED_USER_ID
|
||||||
|
? null
|
||||||
|
: new APIUser
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
Username = $"User {id}"
|
||||||
|
})
|
||||||
|
.Where(u => u != null).ToList(),
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<APIBeatmap> createResponseBeatmaps(params int[] beatmapIds)
|
List<APIBeatmap> createResponseBeatmaps(params int[] beatmapIds)
|
||||||
|
Loading…
Reference in New Issue
Block a user