From c59d84fd21c0b6d33986709435f453786306d46e Mon Sep 17 00:00:00 2001 From: Jamie Taylor Date: Wed, 27 Feb 2019 16:17:04 +0900 Subject: [PATCH] Add sanity check to prevent TimeshiftPlayer from starting with incorrect beatmap/ruleset/mods --- .../Screens/Multi/Play/TimeshiftPlayer.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/osu.Game/Screens/Multi/Play/TimeshiftPlayer.cs b/osu.Game/Screens/Multi/Play/TimeshiftPlayer.cs index d127bdc0ea..7d35276442 100644 --- a/osu.Game/Screens/Multi/Play/TimeshiftPlayer.cs +++ b/osu.Game/Screens/Multi/Play/TimeshiftPlayer.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using System.Diagnostics; using System.Threading; using osu.Framework.Allocation; @@ -11,6 +12,8 @@ using osu.Framework.Screens; using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.Multiplayer; +using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; using osu.Game.Scoring; using osu.Game.Screens.Multi.Ranking; using osu.Game.Screens.Play; @@ -30,6 +33,12 @@ namespace osu.Game.Screens.Multi.Play [Resolved] private APIAccess api { get; set; } + [Resolved] + private IBindable ruleset { get; set; } + + [Resolved] + protected Bindable> CurrentMods { get; private set; } + public TimeshiftPlayer(PlaylistItem playlistItem) { this.playlistItem = playlistItem; @@ -44,6 +53,16 @@ namespace osu.Game.Screens.Multi.Play 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); req.Success += r => token = r.ID; req.Failure += e =>