Skip to content

Commit e9b8154

Browse files
authored
Merge pull request #32005 from smoogipoo/fix-multi-leave-host-sound
Fix host change sounds playing when exiting multiplayer rooms
2 parents 8c20ef1 + f868f03 commit e9b8154

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

osu.Game/Online/Multiplayer/MultiplayerClient.cs

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public abstract partial class MultiplayerClient : Component, IMultiplayerClient,
5151
/// </summary>
5252
public event Action<MultiplayerRoomUser>? UserKicked;
5353

54+
/// <summary>
55+
/// Invoked when the room's host is changed.
56+
/// </summary>
57+
public event Action<MultiplayerRoomUser?>? HostChanged;
58+
5459
/// <summary>
5560
/// Invoked when a new item is added to the playlist.
5661
/// </summary>
@@ -531,6 +536,7 @@ Task IMultiplayerClient.HostChanged(int userId)
531536
Room.Host = user;
532537
APIRoom.Host = user?.User;
533538

539+
HostChanged?.Invoke(user);
534540
RoomUpdated?.Invoke();
535541
}, false);
536542

osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomSounds.cs

+8-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4-
using System.Collections.Generic;
54
using osu.Framework.Allocation;
65
using osu.Framework.Audio;
76
using osu.Framework.Audio.Sample;
@@ -20,7 +19,6 @@ public partial class MultiplayerRoomSounds : CompositeDrawable
2019
private Sample? userJoinedSample;
2120
private Sample? userLeftSample;
2221
private Sample? userKickedSample;
23-
private MultiplayerRoomUser? host;
2422

2523
[BackgroundDependencyLoader]
2624
private void load(AudioManager audio)
@@ -35,25 +33,10 @@ protected override void LoadComplete()
3533
{
3634
base.LoadComplete();
3735

38-
client.RoomUpdated += onRoomUpdated;
3936
client.UserJoined += onUserJoined;
4037
client.UserLeft += onUserLeft;
4138
client.UserKicked += onUserKicked;
42-
updateState();
43-
}
44-
45-
private void onRoomUpdated() => Scheduler.AddOnce(updateState);
46-
47-
private void updateState()
48-
{
49-
if (EqualityComparer<MultiplayerRoomUser>.Default.Equals(host, client.Room?.Host))
50-
return;
51-
52-
// only play sound when the host changes from an already-existing host.
53-
if (host != null)
54-
Scheduler.AddOnce(() => hostChangedSample?.Play());
55-
56-
host = client.Room?.Host;
39+
client.HostChanged += onHostChanged;
5740
}
5841

5942
private void onUserJoined(MultiplayerRoomUser user)
@@ -65,16 +48,22 @@ private void onUserLeft(MultiplayerRoomUser user)
6548
private void onUserKicked(MultiplayerRoomUser user)
6649
=> Scheduler.AddOnce(() => userKickedSample?.Play());
6750

51+
private void onHostChanged(MultiplayerRoomUser? host)
52+
{
53+
if (host != null)
54+
Scheduler.AddOnce(() => hostChangedSample?.Play());
55+
}
56+
6857
protected override void Dispose(bool isDisposing)
6958
{
7059
base.Dispose(isDisposing);
7160

7261
if (client.IsNotNull())
7362
{
74-
client.RoomUpdated -= onRoomUpdated;
7563
client.UserJoined -= onUserJoined;
7664
client.UserLeft -= onUserLeft;
7765
client.UserKicked -= onUserKicked;
66+
client.HostChanged -= onHostChanged;
7867
}
7968
}
8069
}

0 commit comments

Comments
 (0)