1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-14 05:47:20 +08:00

Boot player back to lobby if token request fails

This commit is contained in:
smoogipoo 2018-12-17 11:51:12 +09:00
parent 2fd2425cc4
commit bf8aae8d9b

View File

@ -1,10 +1,13 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Diagnostics;
using System.Net.Http;
using System.Threading;
using Newtonsoft.Json;
using osu.Framework.Allocation;
using osu.Framework.IO.Network;
using osu.Framework.Logging;
using osu.Game.Online.API;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
@ -25,24 +28,44 @@ namespace osu.Game.Screens.Multi.Play
this.playlistItemId = playlistItemId;
}
private int token;
private int? token;
[BackgroundDependencyLoader]
private void load()
{
token = null;
bool failed = false;
var req = new CreateScoreRequest(roomId, playlistItemId);
req.Success += r => token = r.ID;
req.Failure += e => { };
req.Failure += e =>
{
failed = true;
Logger.Error(e, "Failed to retrieve a score submission token.");
Schedule(() =>
{
ValidForResume = false;
Exit();
});
};
api.Queue(req);
while (!failed && !token.HasValue)
Thread.Sleep(1000);
}
protected override ScoreInfo CreateScore()
{
var score = base.CreateScore();
var request = new SubmitScoreRequest(token, roomId, playlistItemId, score);
request.Success += () => { };
request.Failure += e => { };
Debug.Assert(token != null);
var request = new SubmitScoreRequest(token.Value, roomId, playlistItemId, score);
request.Failure += e => Logger.Error(e, "Failed to submit score");
api.Queue(request);
return score;