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

Lock around playingUsers

This commit is contained in:
smoogipoo 2021-04-19 16:06:40 +09:00
parent 5885c24e00
commit de9e37857e

View File

@ -47,6 +47,8 @@ namespace osu.Game.Online.Spectator
private readonly BindableList<int> playingUsers = new BindableList<int>();
private readonly Dictionary<int, SpectatorState> currentUserStates = new Dictionary<int, SpectatorState>();
[CanBeNull]
private IBeatmap currentBeatmap;
@ -60,7 +62,6 @@ namespace osu.Game.Online.Spectator
private IBindable<IReadOnlyList<Mod>> currentMods { get; set; }
private readonly SpectatorState currentState = new SpectatorState();
private readonly Dictionary<int, SpectatorState> currentUserStates = new Dictionary<int, SpectatorState>();
private bool isPlaying;
@ -123,21 +124,26 @@ namespace osu.Game.Online.Spectator
beginPlaying();
}
else
{
lock (userLock)
{
playingUsers.Clear();
currentUserStates.Clear();
}
}
}, true);
}
}
Task ISpectatorClient.UserBeganPlaying(int userId, SpectatorState state)
{
lock (userLock)
{
if (!playingUsers.Contains(userId))
playingUsers.Add(userId);
lock (userLock)
currentUserStates[userId] = state;
}
OnUserBeganPlaying?.Invoke(userId, state);
@ -146,10 +152,11 @@ namespace osu.Game.Online.Spectator
Task ISpectatorClient.UserFinishedPlaying(int userId, SpectatorState state)
{
playingUsers.Remove(userId);
lock (userLock)
{
playingUsers.Remove(userId);
currentUserStates.Remove(userId);
}
OnUserFinishedPlaying?.Invoke(userId, state);