1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:47:29 +08:00

Add checksum validation to the ready/start button

This commit is contained in:
smoogipoo 2020-06-02 14:03:50 +09:00
parent 1ccdfd7364
commit 68fbe9f4c1

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -52,24 +53,14 @@ namespace osu.Game.Screens.Multi.Match.Components
private void updateSelectedItem(PlaylistItem item) private void updateSelectedItem(PlaylistItem item)
{ {
hasBeatmap = false; hasBeatmap = findBeatmap(expr => beatmaps.QueryBeatmap(expr));
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID;
if (beatmapId == null)
return;
hasBeatmap = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmapId) != null;
} }
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet) private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet)
{ {
if (weakSet.NewValue.TryGetTarget(out var set)) if (weakSet.NewValue.TryGetTarget(out var set))
{ {
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID; if (findBeatmap(expr => set.Beatmaps.AsQueryable().FirstOrDefault(expr)))
if (beatmapId == null)
return;
if (set.Beatmaps.Any(b => b.OnlineBeatmapID == beatmapId))
Schedule(() => hasBeatmap = true); Schedule(() => hasBeatmap = true);
} }
} }
@ -78,15 +69,22 @@ namespace osu.Game.Screens.Multi.Match.Components
{ {
if (weakSet.NewValue.TryGetTarget(out var set)) if (weakSet.NewValue.TryGetTarget(out var set))
{ {
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID; if (findBeatmap(expr => set.Beatmaps.AsQueryable().FirstOrDefault(expr)))
if (beatmapId == null)
return;
if (set.Beatmaps.Any(b => b.OnlineBeatmapID == beatmapId))
Schedule(() => hasBeatmap = false); Schedule(() => hasBeatmap = false);
} }
} }
private bool findBeatmap(Func<Expression<Func<BeatmapInfo, bool>>, BeatmapInfo> expression)
{
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID;
string checksum = SelectedItem.Value?.Beatmap.Value?.MD5Hash;
if (beatmapId == null || checksum == null)
return false;
return expression(b => b.OnlineBeatmapID == beatmapId && b.MD5Hash == checksum) != null;
}
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();