From 303d0c56c32fc75e3fa3531ffeaaff0753f06190 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 24 Mar 2025 17:37:11 +0900 Subject: [PATCH] Validate freestyle selection post-selection --- .../MultiplayerMatchFreestyleSelect.cs | 3 ++ .../OnlinePlay/OnlinePlayFreestyleSelect.cs | 35 +++++++++++++++++++ .../Playlists/PlaylistsRoomFreestyleSelect.cs | 7 ++-- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchFreestyleSelect.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchFreestyleSelect.cs index 0c04c2712c..846f781cdc 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchFreestyleSelect.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchFreestyleSelect.cs @@ -60,6 +60,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer return false; } + if (!base.OnStart()) + return false; + selectionOperation = operationTracker.BeginOperation(); client.ChangeUserStyle(Beatmap.Value.BeatmapInfo.OnlineID, Ruleset.Value.OnlineID) diff --git a/osu.Game/Screens/OnlinePlay/OnlinePlayFreestyleSelect.cs b/osu.Game/Screens/OnlinePlay/OnlinePlayFreestyleSelect.cs index 4844d096ce..66218c0e9e 100644 --- a/osu.Game/Screens/OnlinePlay/OnlinePlayFreestyleSelect.cs +++ b/osu.Game/Screens/OnlinePlay/OnlinePlayFreestyleSelect.cs @@ -7,6 +7,7 @@ using Humanizer; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Logging; using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.Online.Rooms; @@ -43,6 +44,40 @@ namespace osu.Game.Screens.OnlinePlay LeftArea.Padding = new MarginPadding { Top = Header.HEIGHT }; } + protected override bool OnStart() + { + FilterCriteria criteria = FilterControl.CreateCriteria(); + + // Beatmaps with too different of a duration are filtered away; this is just a final safety. + if (!criteria.Length.IsInRange(Beatmap.Value.BeatmapInfo.Length)) + { + Logger.Log("The selected beatmap's duration differs too much from the host's selection.", level: LogLevel.Error); + return false; + } + + // Beatmaps without a valid online ID are filtered away; this is just a final safety. + if (Beatmap.Value.BeatmapInfo.OnlineID < 0) + { + Logger.Log("The selected beatmap is not available online.", level: LogLevel.Error); + return false; + } + + // Beatmaps from different sets are filtered away; this is just a final safety. + if (Beatmap.Value.BeatmapSetInfo.OnlineID != criteria.BeatmapSetId) + { + Logger.Log("The selected beatmap is from a different beatmap set.", level: LogLevel.Error); + return false; + } + + if (Ruleset.Value.OnlineID < 0) + { + Logger.Log("The selected ruleset is not available online.", level: LogLevel.Error); + return false; + } + + return true; + } + protected override FilterControl CreateFilterControl() => new DifficultySelectFilterControl(item); protected override IEnumerable<(FooterButton button, OverlayContainer? overlay)> CreateSongSelectFooterButtons() diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomFreestyleSelect.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomFreestyleSelect.cs index 9c85088cc9..1f0f92aea2 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomFreestyleSelect.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomFreestyleSelect.cs @@ -21,15 +21,12 @@ namespace osu.Game.Screens.OnlinePlay.Playlists protected override bool OnStart() { - // Beatmaps without a valid online ID are filtered away; this is just a final safety. - if (base.Beatmap.Value.BeatmapInfo.OnlineID < 0) - return false; - - if (base.Ruleset.Value.OnlineID < 0) + if (!base.OnStart()) return false; Beatmap.Value = base.Beatmap.Value.BeatmapInfo; Ruleset.Value = base.Ruleset.Value; + this.Exit(); return true; }