1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 19:22:54 +08:00

Add sanity check to prevent TimeshiftPlayer from starting with incorrect beatmap/ruleset/mods

This commit is contained in:
Jamie Taylor 2019-02-27 16:17:04 +09:00
parent a3f71d69a9
commit c59d84fd21
No known key found for this signature in database
GPG Key ID: 2ACFA8B6370B8C8C

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -11,6 +12,8 @@ using osu.Framework.Screens;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.Multi.Ranking; using osu.Game.Screens.Multi.Ranking;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
@ -30,6 +33,12 @@ namespace osu.Game.Screens.Multi.Play
[Resolved] [Resolved]
private APIAccess api { get; set; } private APIAccess api { get; set; }
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; }
[Resolved]
protected Bindable<IEnumerable<Mod>> CurrentMods { get; private set; }
public TimeshiftPlayer(PlaylistItem playlistItem) public TimeshiftPlayer(PlaylistItem playlistItem)
{ {
this.playlistItem = playlistItem; this.playlistItem = playlistItem;
@ -44,6 +53,16 @@ namespace osu.Game.Screens.Multi.Play
bool failed = false; bool failed = false;
// Sanity checks to ensure that TimeshiftPlayer matches the settings for the current PlaylistItem
if (Beatmap.Value.BeatmapInfo.OnlineBeatmapID != playlistItem.Beatmap.OnlineBeatmapID)
throw new InvalidOperationException("Current Beatmap does not match PlaylistItem's Beatmap");
if (ruleset.Value.ID != playlistItem.Ruleset.ID)
throw new InvalidOperationException("Current Ruleset does not match PlaylistItem's Ruleset");
if (!CurrentMods.Value.Equals(playlistItem.RequiredMods))
throw new InvalidOperationException("Current Mods do not match PlaylistItem's RequiredMods");
var req = new CreateRoomScoreRequest(roomId.Value ?? 0, playlistItem.ID); var req = new CreateRoomScoreRequest(roomId.Value ?? 0, playlistItem.ID);
req.Success += r => token = r.ID; req.Success += r => token = r.ID;
req.Failure += e => req.Failure += e =>