Fix up TestSpectatorClient implementation

Rather than using a list which is supposed to be updated "client"-side,
now uses the "server"-side list.
This commit is contained in:
Dan Balasescu 2022-02-02 23:00:43 +09:00
parent 6d3bc005ea
commit 9d1d13c715
1 changed files with 9 additions and 8 deletions

View File

@ -39,11 +39,7 @@ public class TestSpectatorClient : SpectatorClient
public TestSpectatorClient()
{
OnNewFrames += (i, bundle) =>
{
if (PlayingUserStates.ContainsKey(i))
lastReceivedUserFrames[i] = bundle.Frames[^1];
};
OnNewFrames += (i, bundle) => lastReceivedUserFrames[i] = bundle.Frames[^1];
}
/// <summary>
@ -62,16 +58,20 @@ public void StartPlay(int userId, int beatmapId)
/// Ends play for an arbitrary user.
/// </summary>
/// <param name="userId">The user to end play for.</param>
public void EndPlay(int userId)
/// <param name="state">The spectator state to end play with.</param>
public void EndPlay(int userId, SpectatingUserState state = SpectatingUserState.Quit)
{
if (!PlayingUserStates.ContainsKey(userId))
if (!userBeatmapDictionary.ContainsKey(userId))
return;
((ISpectatorClient)this).UserFinishedPlaying(userId, new SpectatorState
{
BeatmapID = userBeatmapDictionary[userId],
RulesetID = 0,
State = state
});
userBeatmapDictionary.Remove(userId);
}
public new void Schedule(Action action) => base.Schedule(action);
@ -130,7 +130,7 @@ protected override Task BeginPlayingInternal(SpectatorState state)
protected override Task WatchUserInternal(int userId)
{
// When newly watching a user, the server sends the playing state immediately.
if (PlayingUserStates.ContainsKey(userId))
if (userBeatmapDictionary.ContainsKey(userId))
sendPlayingState(userId);
return Task.CompletedTask;
@ -144,6 +144,7 @@ private void sendPlayingState(int userId)
{
BeatmapID = userBeatmapDictionary[userId],
RulesetID = 0,
State = SpectatingUserState.Playing
});
}
}