2021-03-23 05:44:06 +00:00
|
|
|
// 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.
|
|
|
|
|
2021-10-29 04:02:19 +00:00
|
|
|
using System.Collections.Generic;
|
2021-03-23 05:44:06 +00:00
|
|
|
using System.Net.Http;
|
|
|
|
using Newtonsoft.Json;
|
2021-10-29 04:02:19 +00:00
|
|
|
using Newtonsoft.Json.Converters;
|
2021-03-23 05:44:06 +00:00
|
|
|
using osu.Framework.IO.Network;
|
|
|
|
using osu.Game.Online.API;
|
2021-10-29 04:02:19 +00:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-03-23 05:44:06 +00:00
|
|
|
using osu.Game.Online.Rooms;
|
2021-10-29 04:02:19 +00:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
2021-03-23 05:44:06 +00:00
|
|
|
using osu.Game.Scoring;
|
2021-10-29 04:02:19 +00:00
|
|
|
using osu.Game.Users;
|
2021-03-23 05:44:06 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Online.Solo
|
|
|
|
{
|
|
|
|
public class SubmitSoloScoreRequest : APIRequest<MultiplayerScore>
|
|
|
|
{
|
|
|
|
private readonly long scoreId;
|
|
|
|
|
|
|
|
private readonly int beatmapId;
|
|
|
|
|
2021-10-29 04:02:19 +00:00
|
|
|
private readonly SubmittableScore score;
|
2021-03-23 05:44:06 +00:00
|
|
|
|
|
|
|
public SubmitSoloScoreRequest(int beatmapId, long scoreId, ScoreInfo scoreInfo)
|
|
|
|
{
|
|
|
|
this.beatmapId = beatmapId;
|
|
|
|
this.scoreId = scoreId;
|
2021-10-29 04:02:19 +00:00
|
|
|
score = new SubmittableScore(scoreInfo);
|
2021-03-23 05:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override WebRequest CreateWebRequest()
|
|
|
|
{
|
|
|
|
var req = base.CreateWebRequest();
|
|
|
|
|
|
|
|
req.ContentType = "application/json";
|
|
|
|
req.Method = HttpMethod.Put;
|
|
|
|
|
2021-10-29 04:02:19 +00:00
|
|
|
req.AddRaw(JsonConvert.SerializeObject(score, new JsonSerializerSettings
|
2021-03-23 05:44:06 +00:00
|
|
|
{
|
|
|
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
|
|
|
}));
|
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2021-04-08 14:15:08 +00:00
|
|
|
protected override string Target => $@"beatmaps/{beatmapId}/solo/scores/{scoreId}";
|
2021-03-23 05:44:06 +00:00
|
|
|
}
|
2021-10-29 04:02:19 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A class specifically for sending scores to the API during score submission.
|
|
|
|
/// This is used instead of <see cref="APIScoreInfo"/> due to marginally different serialisation naming requirements.
|
|
|
|
/// </summary>
|
|
|
|
public class SubmittableScore
|
|
|
|
{
|
|
|
|
[JsonProperty("rank")]
|
|
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
|
|
|
public ScoreRank Rank { get; }
|
|
|
|
|
|
|
|
[JsonProperty("total_score")]
|
|
|
|
public long TotalScore { get; }
|
|
|
|
|
|
|
|
[JsonProperty("accuracy")]
|
|
|
|
public double Accuracy { get; }
|
|
|
|
|
|
|
|
[JsonProperty(@"pp")]
|
|
|
|
public double? PP { get; }
|
|
|
|
|
|
|
|
[JsonProperty("max_combo")]
|
|
|
|
public int MaxCombo { get; }
|
|
|
|
|
|
|
|
[JsonProperty("ruleset_id")]
|
|
|
|
public int RulesetID { get; }
|
|
|
|
|
|
|
|
[JsonProperty("passed")]
|
|
|
|
public bool Passed { get; }
|
|
|
|
|
|
|
|
// Used for API serialisation/deserialisation.
|
|
|
|
[JsonProperty("mods")]
|
|
|
|
public APIMod[] Mods { get; }
|
|
|
|
|
|
|
|
[JsonProperty("user")]
|
|
|
|
public User User { get; }
|
|
|
|
|
|
|
|
[JsonProperty("statistics")]
|
|
|
|
public Dictionary<HitResult, int> Statistics { get; }
|
|
|
|
|
|
|
|
public SubmittableScore(ScoreInfo score)
|
|
|
|
{
|
|
|
|
Rank = score.Rank;
|
|
|
|
TotalScore = score.TotalScore;
|
|
|
|
Accuracy = score.Accuracy;
|
|
|
|
PP = score.PP;
|
|
|
|
MaxCombo = score.MaxCombo;
|
|
|
|
RulesetID = score.RulesetID;
|
|
|
|
Passed = score.Passed;
|
|
|
|
Mods = score.APIMods;
|
|
|
|
User = score.User;
|
|
|
|
Statistics = score.Statistics;
|
|
|
|
}
|
|
|
|
}
|
2021-03-23 05:44:06 +00:00
|
|
|
}
|