mirror of
https://github.com/osukey/osukey.git
synced 2025-05-30 01:47:30 +09:00
Fix spectator client not handling multiple watch calls properly
This commit is contained in:
parent
51e607e834
commit
7e5086c8d7
@ -65,11 +65,12 @@ namespace osu.Game.Online.Spectator
|
|||||||
public virtual event Action<int, SpectatorState>? OnUserFinishedPlaying;
|
public virtual event Action<int, SpectatorState>? OnUserFinishedPlaying;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All users currently being watched.
|
/// A dictionary containing all users currently being watched, with the number of watching components for each user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly List<int> watchedUsers = new List<int>();
|
private readonly Dictionary<int, int> watchedUsers = new Dictionary<int, int>();
|
||||||
|
|
||||||
private readonly BindableDictionary<int, SpectatorState> watchedUserStates = new BindableDictionary<int, SpectatorState>();
|
private readonly BindableDictionary<int, SpectatorState> watchedUserStates = new BindableDictionary<int, SpectatorState>();
|
||||||
|
|
||||||
private readonly BindableList<int> playingUsers = new BindableList<int>();
|
private readonly BindableList<int> playingUsers = new BindableList<int>();
|
||||||
private readonly SpectatorState currentState = new SpectatorState();
|
private readonly SpectatorState currentState = new SpectatorState();
|
||||||
|
|
||||||
@ -94,12 +95,15 @@ namespace osu.Game.Online.Spectator
|
|||||||
if (connected.NewValue)
|
if (connected.NewValue)
|
||||||
{
|
{
|
||||||
// get all the users that were previously being watched
|
// get all the users that were previously being watched
|
||||||
int[] users = watchedUsers.ToArray();
|
var users = new Dictionary<int, int>(watchedUsers);
|
||||||
watchedUsers.Clear();
|
watchedUsers.Clear();
|
||||||
|
|
||||||
// resubscribe to watched users.
|
// resubscribe to watched users.
|
||||||
foreach (int userId in users)
|
foreach ((int user, int watchers) in users)
|
||||||
WatchUser(userId);
|
{
|
||||||
|
for (int i = 0; i < watchers; i++)
|
||||||
|
WatchUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
// re-send state in case it wasn't received
|
// re-send state in case it wasn't received
|
||||||
if (IsPlaying)
|
if (IsPlaying)
|
||||||
@ -121,7 +125,7 @@ namespace osu.Game.Online.Spectator
|
|||||||
if (!playingUsers.Contains(userId))
|
if (!playingUsers.Contains(userId))
|
||||||
playingUsers.Add(userId);
|
playingUsers.Add(userId);
|
||||||
|
|
||||||
if (watchedUsers.Contains(userId))
|
if (watchedUsers.ContainsKey(userId))
|
||||||
watchedUserStates[userId] = state;
|
watchedUserStates[userId] = state;
|
||||||
|
|
||||||
OnUserBeganPlaying?.Invoke(userId, state);
|
OnUserBeganPlaying?.Invoke(userId, state);
|
||||||
@ -136,7 +140,7 @@ namespace osu.Game.Online.Spectator
|
|||||||
{
|
{
|
||||||
playingUsers.Remove(userId);
|
playingUsers.Remove(userId);
|
||||||
|
|
||||||
if (watchedUsers.Contains(userId))
|
if (watchedUsers.ContainsKey(userId))
|
||||||
watchedUserStates[userId] = state;
|
watchedUserStates[userId] = state;
|
||||||
|
|
||||||
OnUserFinishedPlaying?.Invoke(userId, state);
|
OnUserFinishedPlaying?.Invoke(userId, state);
|
||||||
@ -232,11 +236,13 @@ namespace osu.Game.Online.Spectator
|
|||||||
{
|
{
|
||||||
Debug.Assert(ThreadSafety.IsUpdateThread);
|
Debug.Assert(ThreadSafety.IsUpdateThread);
|
||||||
|
|
||||||
if (watchedUsers.Contains(userId))
|
if (watchedUsers.ContainsKey(userId))
|
||||||
|
{
|
||||||
|
watchedUsers[userId]++;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
watchedUsers.Add(userId);
|
watchedUsers.Add(userId, 1);
|
||||||
|
|
||||||
WatchUserInternal(userId);
|
WatchUserInternal(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,6 +252,12 @@ namespace osu.Game.Online.Spectator
|
|||||||
// Todo: This should not be a thing, but requires framework changes.
|
// Todo: This should not be a thing, but requires framework changes.
|
||||||
Schedule(() =>
|
Schedule(() =>
|
||||||
{
|
{
|
||||||
|
if (watchedUsers.TryGetValue(userId, out int watchers) && watchers > 1)
|
||||||
|
{
|
||||||
|
watchedUsers[userId]--;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
watchedUsers.Remove(userId);
|
watchedUsers.Remove(userId);
|
||||||
watchedUserStates.Remove(userId);
|
watchedUserStates.Remove(userId);
|
||||||
StopWatchingUserInternal(userId);
|
StopWatchingUserInternal(userId);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user