Skip to content

Commit 9d14292

Browse files
authored
Merge pull request #21588 from smoogipoo/beginplaying-score-token
Add score token to `BeginPlaySession()`
2 parents 9d549c3 + 849245b commit 9d14292

File tree

7 files changed

+15
-12
lines changed

7 files changed

+15
-12
lines changed

osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public void TestWatchingBeatmapThatDoesntExistLocally()
261261
[Test]
262262
public void TestFinalFramesPurgedBeforeEndingPlay()
263263
{
264-
AddStep("begin playing", () => spectatorClient.BeginPlaying(TestGameplayState.Create(new OsuRuleset()), new Score()));
264+
AddStep("begin playing", () => spectatorClient.BeginPlaying(0, TestGameplayState.Create(new OsuRuleset()), new Score()));
265265

266266
AddStep("send frames and finish play", () =>
267267
{

osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorPlayback.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void SetUpSteps()
147147
}
148148
};
149149

150-
spectatorClient.BeginPlaying(TestGameplayState.Create(new OsuRuleset()), recordingScore);
150+
spectatorClient.BeginPlaying(0, TestGameplayState.Create(new OsuRuleset()), recordingScore);
151151
spectatorClient.OnNewFrames += onNewFrames;
152152
});
153153
}

osu.Game/Online/Spectator/ISpectatorServer.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ public interface ISpectatorServer
1515
/// <summary>
1616
/// Signal the start of a new play session.
1717
/// </summary>
18+
/// <param name="scoreToken">The score submission token.</param>
1819
/// <param name="state">The state of gameplay.</param>
19-
Task BeginPlaySession(SpectatorState state);
20+
Task BeginPlaySession(long? scoreToken, SpectatorState state);
2021

2122
/// <summary>
2223
/// Send a bundle of frame data for the current play session.

osu.Game/Online/Spectator/OnlineSpectatorClient.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private void load(IAPIProvider api)
4747
}
4848
}
4949

50-
protected override async Task BeginPlayingInternal(SpectatorState state)
50+
protected override async Task BeginPlayingInternal(long? scoreToken, SpectatorState state)
5151
{
5252
if (!IsConnected.Value)
5353
return;
@@ -56,7 +56,7 @@ protected override async Task BeginPlayingInternal(SpectatorState state)
5656

5757
try
5858
{
59-
await connection.InvokeAsync(nameof(ISpectatorServer.BeginPlaySession), state);
59+
await connection.InvokeAsync(nameof(ISpectatorServer.BeginPlaySession), scoreToken, state);
6060
}
6161
catch (Exception exception)
6262
{
@@ -65,7 +65,7 @@ protected override async Task BeginPlayingInternal(SpectatorState state)
6565
Debug.Assert(connector != null);
6666

6767
await connector.Reconnect();
68-
await BeginPlayingInternal(state);
68+
await BeginPlayingInternal(scoreToken, state);
6969
}
7070

7171
// Exceptions can occur if, for instance, the locally played beatmap doesn't have a server-side counterpart.

osu.Game/Online/Spectator/SpectatorClient.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public abstract partial class SpectatorClient : Component, ISpectatorClient
7676

7777
private IBeatmap? currentBeatmap;
7878
private Score? currentScore;
79+
private long? currentScoreToken;
7980

8081
private readonly Queue<FrameDataBundle> pendingFrameBundles = new Queue<FrameDataBundle>();
8182

@@ -108,7 +109,7 @@ private void load()
108109
// re-send state in case it wasn't received
109110
if (IsPlaying)
110111
// TODO: this is likely sent out of order after a reconnect scenario. needs further consideration.
111-
BeginPlayingInternal(currentState);
112+
BeginPlayingInternal(currentScoreToken, currentState);
112113
}
113114
else
114115
{
@@ -159,7 +160,7 @@ Task ISpectatorClient.UserSentFrames(int userId, FrameDataBundle data)
159160
return Task.CompletedTask;
160161
}
161162

162-
public void BeginPlaying(GameplayState state, Score score)
163+
public void BeginPlaying(long? scoreToken, GameplayState state, Score score)
163164
{
164165
// This schedule is only here to match the one below in `EndPlaying`.
165166
Schedule(() =>
@@ -178,8 +179,9 @@ public void BeginPlaying(GameplayState state, Score score)
178179

179180
currentBeatmap = state.Beatmap;
180181
currentScore = score;
182+
currentScoreToken = scoreToken;
181183

182-
BeginPlayingInternal(currentState);
184+
BeginPlayingInternal(currentScoreToken, currentState);
183185
});
184186
}
185187

@@ -264,7 +266,7 @@ public void StopWatchingUser(int userId)
264266
});
265267
}
266268

267-
protected abstract Task BeginPlayingInternal(SpectatorState state);
269+
protected abstract Task BeginPlayingInternal(long? scoreToken, SpectatorState state);
268270

269271
protected abstract Task SendFramesInternal(FrameDataBundle bundle);
270272

osu.Game/Screens/Play/SubmittingPlayer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ protected override void StartGameplay()
148148
realmBeatmap.LastPlayed = DateTimeOffset.Now;
149149
});
150150

151-
spectatorClient.BeginPlaying(GameplayState, Score);
151+
spectatorClient.BeginPlaying(token, GameplayState, Score);
152152
}
153153

154154
public override bool OnExiting(ScreenExitEvent e)

osu.Game/Tests/Visual/Spectator/TestSpectatorClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void flush()
126126
}
127127
}
128128

129-
protected override Task BeginPlayingInternal(SpectatorState state)
129+
protected override Task BeginPlayingInternal(long? scoreToken, SpectatorState state)
130130
{
131131
// Track the local user's playing beatmap ID.
132132
Debug.Assert(state.BeatmapID != null);

0 commit comments

Comments
 (0)