Merge pull request #16854 from peppy/combine-score-submission-request-implementation

Standardise and combine base implementation of score submission requests
This commit is contained in:
Dan Balasescu 2022-02-11 17:31:55 +09:00 committed by GitHub
commit 8b05b35b8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 59 deletions

View File

@ -1,46 +1,22 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Net.Http;
using Newtonsoft.Json;
using osu.Framework.IO.Network;
using osu.Game.Online.API;
using osu.Game.Online.Solo;
using osu.Game.Scoring;
namespace osu.Game.Online.Rooms
{
public class SubmitRoomScoreRequest : APIRequest<MultiplayerScore>
public class SubmitRoomScoreRequest : SubmitScoreRequest
{
private readonly long scoreId;
private readonly long roomId;
private readonly long playlistItemId;
private readonly SubmittableScore score;
public SubmitRoomScoreRequest(long scoreId, long roomId, long playlistItemId, ScoreInfo scoreInfo)
public SubmitRoomScoreRequest(ScoreInfo scoreInfo, long scoreId, long roomId, long playlistItemId)
: base(scoreInfo, scoreId)
{
this.scoreId = scoreId;
this.roomId = roomId;
this.playlistItemId = playlistItemId;
score = new SubmittableScore(scoreInfo);
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.ContentType = "application/json";
req.Method = HttpMethod.Put;
req.Timeout = 30000;
req.AddRaw(JsonConvert.SerializeObject(score, new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}));
return req;
}
protected override string Target => $@"rooms/{roomId}/playlist/{playlistItemId}/scores/{scoreId}";
protected override string Target => $@"rooms/{roomId}/playlist/{playlistItemId}/scores/{ScoreId}";
}
}

View File

@ -0,0 +1,41 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Net.Http;
using Newtonsoft.Json;
using osu.Framework.IO.Network;
using osu.Game.Online.API;
using osu.Game.Online.Solo;
using osu.Game.Scoring;
namespace osu.Game.Online.Rooms
{
public abstract class SubmitScoreRequest : APIRequest<MultiplayerScore>
{
public readonly SubmittableScore Score;
protected readonly long ScoreId;
protected SubmitScoreRequest(ScoreInfo scoreInfo, long scoreId)
{
Score = new SubmittableScore(scoreInfo);
ScoreId = scoreId;
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.ContentType = "application/json";
req.Method = HttpMethod.Put;
req.Timeout = 30000;
req.AddRaw(JsonConvert.SerializeObject(Score, new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}));
return req;
}
}
}

View File

@ -1,46 +1,21 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Net.Http;
using Newtonsoft.Json;
using osu.Framework.IO.Network;
using osu.Game.Online.API;
using osu.Game.Online.Rooms;
using osu.Game.Scoring;
namespace osu.Game.Online.Solo
{
public class SubmitSoloScoreRequest : APIRequest<MultiplayerScore>
public class SubmitSoloScoreRequest : SubmitScoreRequest
{
public readonly SubmittableScore Score;
private readonly long scoreId;
private readonly int beatmapId;
public SubmitSoloScoreRequest(int beatmapId, long scoreId, ScoreInfo scoreInfo)
public SubmitSoloScoreRequest(ScoreInfo scoreInfo, long scoreId, int beatmapId)
: base(scoreInfo, scoreId)
{
this.beatmapId = beatmapId;
this.scoreId = scoreId;
Score = new SubmittableScore(scoreInfo);
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.ContentType = "application/json";
req.Method = HttpMethod.Put;
req.Timeout = 30000;
req.AddRaw(JsonConvert.SerializeObject(Score, new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}));
return req;
}
protected override string Target => $@"beatmaps/{beatmapId}/solo/scores/{scoreId}";
protected override string Target => $@"beatmaps/{beatmapId}/solo/scores/{ScoreId}";
}
}

View File

@ -34,7 +34,7 @@ namespace osu.Game.Screens.Play
protected override APIRequest<MultiplayerScore> CreateSubmissionRequest(Score score, long token)
{
Debug.Assert(Room.RoomID.Value != null);
return new SubmitRoomScoreRequest(token, Room.RoomID.Value.Value, PlaylistItem.ID, score.ScoreInfo);
return new SubmitRoomScoreRequest(score.ScoreInfo, token, Room.RoomID.Value.Value, PlaylistItem.ID);
}
}
}

View File

@ -46,7 +46,7 @@ namespace osu.Game.Screens.Play
Debug.Assert(beatmap.OnlineID > 0);
return new SubmitSoloScoreRequest(beatmap.OnlineID, token, score.ScoreInfo);
return new SubmitSoloScoreRequest(score.ScoreInfo, token, beatmap.OnlineID);
}
}
}