2018-04-13 17:19:50 +08:00
|
|
|
|
// 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;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using osu.Game.Screens.Select.Leaderboards;
|
|
|
|
|
using osu.Framework.IO.Network;
|
2018-06-08 10:41:54 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Online.API.Requests
|
|
|
|
|
{
|
2018-06-08 10:41:54 +08:00
|
|
|
|
public class GetScoresRequest : APIRequest<APIScores>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly BeatmapInfo beatmap;
|
2018-12-14 18:51:27 +08:00
|
|
|
|
private readonly BeatmapLeaderboardScope scope;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private readonly RulesetInfo ruleset;
|
|
|
|
|
|
2018-12-14 18:51:27 +08:00
|
|
|
|
public GetScoresRequest(BeatmapInfo beatmap, RulesetInfo ruleset, BeatmapLeaderboardScope scope = BeatmapLeaderboardScope.Global)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
if (!beatmap.OnlineBeatmapID.HasValue)
|
|
|
|
|
throw new InvalidOperationException($"Cannot lookup a beatmap's scores without having a populated {nameof(BeatmapInfo.OnlineBeatmapID)}.");
|
|
|
|
|
|
2018-12-14 18:51:27 +08:00
|
|
|
|
if (scope == BeatmapLeaderboardScope.Local)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
throw new InvalidOperationException("Should not attempt to request online scores for a local scoped leaderboard");
|
|
|
|
|
|
|
|
|
|
this.beatmap = beatmap;
|
|
|
|
|
this.scope = scope;
|
|
|
|
|
this.ruleset = ruleset ?? throw new ArgumentNullException(nameof(ruleset));
|
|
|
|
|
|
|
|
|
|
Success += onSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-08 10:41:54 +08:00
|
|
|
|
private void onSuccess(APIScores r)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-11-28 17:33:01 +08:00
|
|
|
|
foreach (APIScoreInfo score in r.Scores)
|
2018-11-30 15:11:09 +08:00
|
|
|
|
score.Beatmap = beatmap;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override WebRequest CreateWebRequest()
|
|
|
|
|
{
|
|
|
|
|
var req = base.CreateWebRequest();
|
|
|
|
|
|
|
|
|
|
req.Timeout = 30000;
|
|
|
|
|
req.AddParameter(@"type", scope.ToString().ToLowerInvariant());
|
|
|
|
|
req.AddParameter(@"mode", ruleset.ShortName);
|
|
|
|
|
|
|
|
|
|
return req;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}/scores";
|
|
|
|
|
}
|
|
|
|
|
}
|