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:
parent
5885c24e00
commit
de9e37857e
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user