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

Merge pull request #15410 from peppy/fix-multiplayer-room-participants

Fix multiplayer room participants display not updating as new users join/leave
This commit is contained in:
Dan Balasescu 2021-11-02 17:55:16 +09:00 committed by GitHub
commit e61f2970b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 5 deletions

View File

@ -231,6 +231,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
} }
} }
}); });
AddAssert("Check participant count correct", () => client.APIRoom?.ParticipantCount.Value == 1);
AddAssert("Check participant list contains user", () => client.APIRoom?.RecentParticipants.Count(u => u.Id == API.LocalUser.Value.Id) == 1);
} }
[Test] [Test]
@ -290,6 +293,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddUntilStep("wait for room open", () => this.ChildrenOfType<MultiplayerMatchSubScreen>().FirstOrDefault()?.IsLoaded == true); AddUntilStep("wait for room open", () => this.ChildrenOfType<MultiplayerMatchSubScreen>().FirstOrDefault()?.IsLoaded == true);
AddUntilStep("wait for join", () => client.Room != null); AddUntilStep("wait for join", () => client.Room != null);
AddAssert("Check participant count correct", () => client.APIRoom?.ParticipantCount.Value == 1);
AddAssert("Check participant list contains user", () => client.APIRoom?.RecentParticipants.Count(u => u.Id == API.LocalUser.Value.Id) == 1);
} }
[Test] [Test]

View File

@ -45,11 +45,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
} }
[Test] [Test]
public void TestAddNullUser() public void TestAddUnresolvedUser()
{ {
AddAssert("one unique panel", () => this.ChildrenOfType<ParticipantPanel>().Select(p => p.User).Distinct().Count() == 1); AddAssert("one unique panel", () => this.ChildrenOfType<ParticipantPanel>().Select(p => p.User).Distinct().Count() == 1);
AddStep("add non-resolvable user", () => Client.AddNullUser()); AddStep("add non-resolvable user", () => Client.TestAddUnresolvedUser());
AddAssert("null user added", () => Client.Room.AsNonNull().Users.Count(u => u.User == null) == 1); AddAssert("null user added", () => Client.Room.AsNonNull().Users.Count(u => u.User == null) == 1);
AddUntilStep("two unique panels", () => this.ChildrenOfType<ParticipantPanel>().Select(p => p.User).Distinct().Count() == 2); AddUntilStep("two unique panels", () => this.ChildrenOfType<ParticipantPanel>().Select(p => p.User).Distinct().Count() == 2);

View File

@ -148,6 +148,10 @@ namespace osu.Game.Online.Multiplayer
{ {
Room = joinedRoom; Room = joinedRoom;
APIRoom = room; APIRoom = room;
Debug.Assert(LocalUser != null);
addUserToAPIRoom(LocalUser);
foreach (var user in joinedRoom.Users) foreach (var user in joinedRoom.Users)
updateUserPlayingState(user.UserID, user.State); updateUserPlayingState(user.UserID, user.State);
@ -372,6 +376,8 @@ namespace osu.Game.Online.Multiplayer
Room.Users.Add(user); Room.Users.Add(user);
addUserToAPIRoom(user);
UserJoined?.Invoke(user); UserJoined?.Invoke(user);
RoomUpdated?.Invoke(); RoomUpdated?.Invoke();
}); });
@ -391,6 +397,18 @@ namespace osu.Game.Online.Multiplayer
return handleUserLeft(user, UserKicked); return handleUserLeft(user, UserKicked);
} }
private void addUserToAPIRoom(MultiplayerRoomUser user)
{
Debug.Assert(APIRoom != null);
APIRoom.RecentParticipants.Add(user.User ?? new User
{
Id = user.UserID,
Username = "[Unresolved]"
});
APIRoom.ParticipantCount.Value++;
}
private Task handleUserLeft(MultiplayerRoomUser user, Action<MultiplayerRoomUser>? callback) private Task handleUserLeft(MultiplayerRoomUser user, Action<MultiplayerRoomUser>? callback)
{ {
if (Room == null) if (Room == null)
@ -404,6 +422,10 @@ namespace osu.Game.Online.Multiplayer
Room.Users.Remove(user); Room.Users.Remove(user);
PlayingUserIds.Remove(user.UserID); PlayingUserIds.Remove(user.UserID);
Debug.Assert(APIRoom != null);
APIRoom.RecentParticipants.RemoveAll(u => u.Id == user.UserID);
APIRoom.ParticipantCount.Value--;
callback?.Invoke(user); callback?.Invoke(user);
RoomUpdated?.Invoke(); RoomUpdated?.Invoke();
}, false); }, false);

View File

@ -62,7 +62,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
return roomUser; return roomUser;
} }
public void AddNullUser() => addUser(new MultiplayerRoomUser(TestUserLookupCache.NULL_USER_ID)); public void TestAddUnresolvedUser() => addUser(new MultiplayerRoomUser(TestUserLookupCache.UNRESOLVED_USER_ID));
private void addUser(MultiplayerRoomUser user) private void addUser(MultiplayerRoomUser user)
{ {

View File

@ -14,11 +14,11 @@ namespace osu.Game.Tests.Visual
/// A special user ID which <see cref="ComputeValueAsync"/> would return a <see langword="null"/> <see cref="User"/> for. /// A special user ID which <see cref="ComputeValueAsync"/> would return a <see langword="null"/> <see cref="User"/> for.
/// As a simulation to what a regular <see cref="UserLookupCache"/> would return in the case of failing to fetch the user. /// As a simulation to what a regular <see cref="UserLookupCache"/> would return in the case of failing to fetch the user.
/// </summary> /// </summary>
public const int NULL_USER_ID = -1; public const int UNRESOLVED_USER_ID = -1;
protected override Task<User> ComputeValueAsync(int lookup, CancellationToken token = default) protected override Task<User> ComputeValueAsync(int lookup, CancellationToken token = default)
{ {
if (lookup == NULL_USER_ID) if (lookup == UNRESOLVED_USER_ID)
return Task.FromResult((User)null); return Task.FromResult((User)null);
return Task.FromResult(new User return Task.FromResult(new User