mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 02:32:55 +08:00
Basic score submission implementation
This commit is contained in:
parent
e8007ac37f
commit
9726eea0d0
@ -64,6 +64,9 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
|
|
||||||
public class PlaylistItem
|
public class PlaylistItem
|
||||||
{
|
{
|
||||||
|
[JsonProperty("id")]
|
||||||
|
public int ID { get; set; }
|
||||||
|
|
||||||
[JsonProperty("beatmap")]
|
[JsonProperty("beatmap")]
|
||||||
private APIBeatmap beatmap { get; set; }
|
private APIBeatmap beatmap { get; set; }
|
||||||
|
|
||||||
@ -73,7 +76,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
public BeatmapInfo Beatmap { get; set; }
|
public BeatmapInfo Beatmap { get; set; }
|
||||||
|
|
||||||
[JsonProperty("beatmap_id")]
|
[JsonProperty("beatmap_id")]
|
||||||
public int BeatmapID => 847296; //Beatmap.OnlineBeatmapID ?? 0;
|
public int BeatmapID => Beatmap.OnlineBeatmapID ?? 0;
|
||||||
|
|
||||||
[JsonProperty("ruleset_id")]
|
[JsonProperty("ruleset_id")]
|
||||||
public int RulesetID { get; set; }
|
public int RulesetID { get; set; }
|
||||||
|
@ -19,25 +19,38 @@ namespace osu.Game.Scoring
|
|||||||
{
|
{
|
||||||
public int ID { get; set; }
|
public int ID { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("rank")]
|
||||||
public ScoreRank Rank { get; set; }
|
public ScoreRank Rank { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("total_score")]
|
||||||
public int TotalScore { get; set; }
|
public int TotalScore { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("accuracy")]
|
||||||
[Column(TypeName="DECIMAL(1,4)")]
|
[Column(TypeName="DECIMAL(1,4)")]
|
||||||
public double Accuracy { get; set; }
|
public double Accuracy { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public double? PP { get; set; }
|
public double? PP { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("max_combo")]
|
||||||
public int MaxCombo { get; set; }
|
public int MaxCombo { get; set; }
|
||||||
|
|
||||||
public int Combo { get; set; }
|
[JsonIgnore]
|
||||||
|
public int Combo { get; set; } // Todo: Shouldn't exist in here
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public int RulesetID { get; set; }
|
public int RulesetID { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("passed")]
|
||||||
|
[NotMapped]
|
||||||
|
public bool Passed { get; set; } = true;
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public virtual RulesetInfo Ruleset { get; set; }
|
public virtual RulesetInfo Ruleset { get; set; }
|
||||||
|
|
||||||
private Mod[] mods;
|
private Mod[] mods;
|
||||||
|
|
||||||
|
[JsonProperty("mods")]
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public Mod[] Mods
|
public Mod[] Mods
|
||||||
{
|
{
|
||||||
@ -62,6 +75,7 @@ namespace osu.Game.Scoring
|
|||||||
|
|
||||||
private string modsJson;
|
private string modsJson;
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
[Column("Mods")]
|
[Column("Mods")]
|
||||||
public string ModsJson
|
public string ModsJson
|
||||||
{
|
{
|
||||||
@ -87,6 +101,7 @@ namespace osu.Game.Scoring
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public User User;
|
public User User;
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
[Column("User")]
|
[Column("User")]
|
||||||
public string UserString
|
public string UserString
|
||||||
{
|
{
|
||||||
@ -97,15 +112,19 @@ namespace osu.Game.Scoring
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int BeatmapInfoID { get; set; }
|
public int BeatmapInfoID { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public virtual BeatmapInfo Beatmap { get; set; }
|
public virtual BeatmapInfo Beatmap { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public long? OnlineScoreID { get; set; }
|
public long? OnlineScoreID { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public DateTimeOffset Date { get; set; }
|
public DateTimeOffset Date { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonProperty("statistics")]
|
||||||
public Dictionary<HitResult, int> Statistics = new Dictionary<HitResult, int>();
|
public Dictionary<HitResult, int> Statistics = new Dictionary<HitResult, int>();
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
[Column("Statistics")]
|
[Column("Statistics")]
|
||||||
public string StatisticsJson
|
public string StatisticsJson
|
||||||
{
|
{
|
||||||
@ -125,8 +144,10 @@ namespace osu.Game.Scoring
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public List<ScoreFileInfo> Files { get; set; }
|
public List<ScoreFileInfo> Files { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public string Hash { get; set; }
|
public string Hash { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public bool DeletePending { get; set; }
|
public bool DeletePending { get; set; }
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
|
@ -183,7 +183,7 @@ namespace osu.Game.Screens.Multi.Match
|
|||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
case GameTypeTimeshift _:
|
case GameTypeTimeshift _:
|
||||||
multiplayer.Push(new PlayerLoader(new TimeshiftPlayer()));
|
multiplayer.Push(new PlayerLoader(new TimeshiftPlayer(room.RoomID.Value ?? 0, room.Playlist.First().ID)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,108 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System.Net.Http;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.IO.Network;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Multi.Play
|
namespace osu.Game.Screens.Multi.Play
|
||||||
{
|
{
|
||||||
public class TimeshiftPlayer : Player
|
public class TimeshiftPlayer : Player
|
||||||
{
|
{
|
||||||
|
private readonly int roomId;
|
||||||
|
private readonly int playlistItemId;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private APIAccess api { get; set; }
|
||||||
|
|
||||||
|
public TimeshiftPlayer(int roomId, int playlistItemId)
|
||||||
|
{
|
||||||
|
this.roomId = roomId;
|
||||||
|
this.playlistItemId = playlistItemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int token;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
var req = new CreateScoreRequest(roomId, playlistItemId);
|
||||||
|
req.Success += r => token = r.ID;
|
||||||
|
req.Failure += e => { };
|
||||||
|
api.Queue(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override ScoreInfo CreateScore()
|
||||||
|
{
|
||||||
|
var score = base.CreateScore();
|
||||||
|
|
||||||
|
var request = new SubmitScoreRequest(token, roomId, playlistItemId, score);
|
||||||
|
request.Success += () => { };
|
||||||
|
request.Failure += e => { };
|
||||||
|
api.Queue(request);
|
||||||
|
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SubmitScoreRequest : APIRequest
|
||||||
|
{
|
||||||
|
private readonly int scoreId;
|
||||||
|
private readonly int roomId;
|
||||||
|
private readonly int playlistItemId;
|
||||||
|
private readonly ScoreInfo scoreInfo;
|
||||||
|
|
||||||
|
public SubmitScoreRequest(int scoreId, int roomId, int playlistItemId, ScoreInfo scoreInfo)
|
||||||
|
{
|
||||||
|
this.scoreId = scoreId;
|
||||||
|
this.roomId = roomId;
|
||||||
|
this.playlistItemId = playlistItemId;
|
||||||
|
this.scoreInfo = scoreInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override WebRequest CreateWebRequest()
|
||||||
|
{
|
||||||
|
var req = base.CreateWebRequest();
|
||||||
|
|
||||||
|
req.ContentType = "application/json";
|
||||||
|
req.Method = HttpMethod.Put;
|
||||||
|
|
||||||
|
req.AddRaw(JsonConvert.SerializeObject(scoreInfo));
|
||||||
|
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Target => $@"rooms/{roomId}/playlist/{playlistItemId}/scores/{scoreId}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CreateScoreRequest : APIRequest<CreateScoreResult>
|
||||||
|
{
|
||||||
|
private readonly int roomId;
|
||||||
|
private readonly int playlistItemId;
|
||||||
|
|
||||||
|
public CreateScoreRequest(int roomId, int playlistItemId)
|
||||||
|
{
|
||||||
|
this.roomId = roomId;
|
||||||
|
this.playlistItemId = playlistItemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override WebRequest CreateWebRequest()
|
||||||
|
{
|
||||||
|
var req = base.CreateWebRequest();
|
||||||
|
req.Method = HttpMethod.Post;
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Target => $@"rooms/{roomId}/playlist/{playlistItemId}/scores";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CreateScoreResult
|
||||||
|
{
|
||||||
|
[JsonProperty("id")]
|
||||||
|
public int ID { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user