1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-05 03:03:21 +08:00

Compare commits

...

13 Commits

Author SHA1 Message Date
Salman Alshamrani
e25f7a4cb8
Merge ee369ef86d into be05f2a1c2 2024-12-03 16:58:59 +09:00
Dan Balasescu
be05f2a1c2
Merge pull request #30929 from timschumi/rate-change-ready
Account for rate changing mods when disabling the "Ready" button
2024-12-03 16:30:16 +09:00
Dan Balasescu
6ff1dec7b2
Add tests 2024-12-03 15:45:58 +09:00
Tim Schumacher
e920cfa187 Move rate-changing TODO to a common place in CalculateRateWithMods 2024-12-02 23:49:51 +01:00
Salman Alshamrani
ee369ef86d Remove unused using directives 2024-11-30 22:38:43 -05:00
Salman Alshamrani
9a4c419c56 Remove unnecessary usage of link proxying in OsuOnlineStore
Links are checked to be in the ppy.sh domain here.
2024-11-30 22:37:50 -05:00
Tim Schumacher
164b809c89 Document ready button enable state with some comments 2024-11-30 23:02:22 +01:00
Tim Schumacher
f4e155bfa6 Account for rate changing mods when disabling the "Ready" button 2024-11-30 16:01:32 +01:00
Salman Alshamrani
dbe2741982 Update specified endpoint 2024-11-28 22:19:44 -05:00
Salman Alshamrani
83f8fa7472 Update test scene 2024-11-25 00:41:40 -05:00
Salman Alshamrani
9a89d402b9 Perform proxying only on osu! markdown images 2024-11-25 00:40:56 -05:00
Salman Alshamrani
2a7133d6d3 Add test scene using OsuOnlineStore to test lookups 2024-11-24 21:47:33 -05:00
Salman Alshamrani
2417d4de83 Add OsuOnlineStore for proxying external media lookups 2024-11-24 21:47:33 -05:00
10 changed files with 185 additions and 10 deletions

View File

@ -0,0 +1,47 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Game.Graphics.Containers.Markdown;
namespace osu.Game.Tests.Visual.Online
{
public partial class TestSceneImageProxying : OsuTestScene
{
[Resolved]
private GameHost host { get; set; } = null!;
[Test]
public void TestExternalImageLink()
{
AddStep("load image", () => Child = new OsuMarkdownContainer
{
RelativeSizeAxes = Axes.Both,
Text = "![](https://github.com/ppy/osu-wiki/blob/master/wiki/Announcement_messages/img/notification.png?raw=true)",
});
}
[Test]
public void TestLocalImageLink()
{
AddStep("load image", () => Child = new OsuMarkdownContainer
{
RelativeSizeAxes = Axes.Both,
Text = "![](https://osu.ppy.sh/help/wiki/shared/news/banners/monthly-beatmapping-contest.png)",
});
}
[Test]
public void TestInvalidImageLink()
{
AddStep("load image", () => Child = new OsuMarkdownContainer
{
RelativeSizeAxes = Axes.Both,
Text = "![](https://this-site-does-not-exist.com/img.png)",
});
}
}
}

View File

@ -5,25 +5,64 @@ using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Extensions;
using osu.Framework.Platform;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Rooms;
using osu.Game.Online.Rooms.RoomStatuses;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Scoring;
using osu.Game.Screens.OnlinePlay.Playlists;
using osu.Game.Tests.Resources;
using osu.Game.Tests.Visual.OnlinePlay;
namespace osu.Game.Tests.Visual.Playlists
{
public partial class TestScenePlaylistsRoomSubScreen : OnlinePlayTestScene
{
private const double track_length = 10000;
[Resolved]
private IAPIProvider api { get; set; } = null!;
protected new TestRoomManager RoomManager => (TestRoomManager)base.RoomManager;
private BeatmapManager beatmaps = null!;
private RulesetStore rulesets = null!;
private BeatmapSetInfo? importedSet;
[BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio)
{
Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, null, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(new ScoreManager(rulesets, () => beatmaps, LocalStorage, Realm, API));
Dependencies.Cache(Realm);
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
Realm.Write(r =>
{
foreach (var set in r.All<BeatmapSetInfo>())
{
foreach (var b in set.Beatmaps)
{
// These will all have a virtual track length of 1000, see WorkingBeatmap.GetVirtualTrack().
b.Length = track_length - 1000;
}
}
});
importedSet = beatmaps.GetAllUsableBeatmapSets().First();
}
[Test]
public void TestStatusUpdateOnEnter()
{
@ -69,5 +108,42 @@ namespace osu.Game.Tests.Visual.Playlists
AddAssert("close button present", () => roomScreen.ChildrenOfType<DangerousRoundedButton>().Any());
AddUntilStep("wait for close button to disappear", () => !roomScreen.ChildrenOfType<DangerousRoundedButton>().Any());
}
[TestCase(120_000, true)] // Definitely enough time.
[TestCase(45_000, true)] // Enough time.
[TestCase(35_000, false)] // Not enough time to complete beatmap after lenience.
[TestCase(20_000, false)] // Not enough time.
[TestCase(5_000, false)] // Not enough time to complete beatmap before lenience.
[TestCase(37_500, true, 2)] // Enough time to complete beatmap after mods are applied.
public void TestReadyButtonEnablementPeriod(int offsetMs, bool enabled, double rate = 1)
{
Room room = null!;
PlaylistsRoomSubScreen roomScreen = null!;
AddStep("create room", () =>
{
RoomManager.AddRoom(room = new Room
{
Name = @"Test Room",
Host = api.LocalUser.Value,
Category = RoomCategory.Normal,
StartDate = DateTimeOffset.Now,
EndDate = DateTimeOffset.Now.AddMilliseconds(offsetMs),
Playlist =
[
new PlaylistItem(importedSet!.Beatmaps[0])
{
RequiredMods = rate == 1
? []
: [new APIMod(new OsuModDoubleTime { SpeedChange = { Value = rate } })]
}
]
});
});
AddStep("push screen", () => LoadScreen(roomScreen = new PlaylistsRoomSubScreen(room)));
AddUntilStep("wait for screen load", () => roomScreen.IsCurrentScreen());
AddUntilStep("ready button enabled", () => roomScreen.ChildrenOfType<PlaylistsReadyButton>().SingleOrDefault()?.Enabled.Value, () => Is.EqualTo(enabled));
}
}
}

View File

@ -6,9 +6,10 @@ using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.IO.Stores;
using osu.Framework.Logging;
using osu.Game.Beatmaps;
using osu.Game.Online;
using osu.Game.Online.API;
namespace osu.Game.Audio
{
@ -28,9 +29,9 @@ namespace osu.Game.Audio
}
[BackgroundDependencyLoader]
private void load(AudioManager audioManager)
private void load(AudioManager audioManager, IAPIProvider api)
{
trackStore = audioManager.GetTrackStore(new OnlineStore());
trackStore = audioManager.GetTrackStore(new OsuOnlineStore(api.APIEndpointUrl));
}
/// <summary>

View File

@ -17,5 +17,8 @@ namespace osu.Game.Graphics.Containers.Markdown
{
TooltipText = linkInline.Title;
}
protected override ImageContainer CreateImageContainer(string url)
=> base.CreateImageContainer($@"https://osu.ppy.sh/media-url?url={url}");
}
}

View File

@ -0,0 +1,31 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.IO.Stores;
using osu.Framework.Logging;
namespace osu.Game.Online
{
public class OsuOnlineStore : OnlineStore
{
private readonly string apiEndpointUrl;
public OsuOnlineStore(string apiEndpointUrl)
{
this.apiEndpointUrl = apiEndpointUrl;
}
protected override string GetLookupUrl(string url)
{
// add leading dot to avoid matching hosts named "<anything>ppy.sh"
if (!Uri.TryCreate(url, UriKind.Absolute, out Uri? uri) || !uri.Host.EndsWith(@".ppy.sh", StringComparison.OrdinalIgnoreCase))
{
Logger.Log($@"Blocking resource lookup from external website: {url}", LoggingTarget.Network, LogLevel.Important);
return string.Empty;
}
return url;
}
}
}

View File

@ -29,6 +29,7 @@ using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Input.Handlers.Tablet;
using osu.Framework.IO.Stores;
using osu.Framework.Localisation;
using osu.Framework.Logging;
using osu.Framework.Platform;
@ -824,6 +825,8 @@ namespace osu.Game
protected override Container CreateScalingContainer() => new ScalingContainer(ScalingMode.Everything);
protected override OnlineStore CreateOnlineStore() => new OsuOnlineStore(CreateEndpoints().APIEndpointUrl);
#region Beatmap progression
private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> beatmap)

View File

@ -277,7 +277,7 @@ namespace osu.Game
dependencies.CacheAs(Storage);
var largeStore = new LargeTextureStore(Host.Renderer, Host.CreateTextureLoaderStore(new NamespacedResourceStore<byte[]>(Resources, @"Textures")));
largeStore.AddTextureSource(Host.CreateTextureLoaderStore(new OnlineStore()));
largeStore.AddTextureSource(Host.CreateTextureLoaderStore(CreateOnlineStore()));
dependencies.Cache(largeStore);
dependencies.CacheAs(LocalConfig);

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using osu.Framework.Allocation;
@ -10,7 +11,9 @@ using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Online.Rooms;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Utils;
namespace osu.Game.Screens.OnlinePlay.Playlists
{
@ -19,6 +22,9 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
[Resolved]
private IBindable<WorkingBeatmap> gameBeatmap { get; set; } = null!;
[Resolved]
private IBindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
private readonly Room room;
public PlaylistsReadyButton(Room room)
@ -63,14 +69,14 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
{
base.Update();
Enabled.Value = hasRemainingAttempts && enoughTimeLeft;
Enabled.Value = hasRemainingAttempts && enoughTimeLeft();
}
public override LocalisableString TooltipText
{
get
{
if (!enoughTimeLeft)
if (!enoughTimeLeft())
return "No time left!";
if (!hasRemainingAttempts)
@ -80,9 +86,17 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
}
}
private bool enoughTimeLeft =>
// This should probably consider the length of the currently selected item, rather than a constant 30 seconds.
room.EndDate != null && DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(gameBeatmap.Value.Track.Length) < room.EndDate;
private bool enoughTimeLeft()
{
double rate = ModUtils.CalculateRateWithMods(mods.Value);
// We want to avoid users not being able to submit scores if they chose to not skip,
// so track length is chosen over playable length.
double trackLength = Math.Round(gameBeatmap.Value.Track.Length / rate);
// Additional 30 second delay added to account for load and/or submit time.
return room.EndDate != null && DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(trackLength) < room.EndDate;
}
protected override void Dispose(bool isDisposing)
{

View File

@ -401,7 +401,6 @@ namespace osu.Game.Screens.Select
if (beatmap == null || bpmLabelContainer == null)
return;
// this doesn't consider mods which apply variable rates, yet.
double rate = ModUtils.CalculateRateWithMods(mods.Value);
int bpmMax = FormatUtils.RoundBPM(beatmap.ControlPointInfo.BPMMaximum, rate);

View File

@ -286,6 +286,7 @@ namespace osu.Game.Utils
{
double rate = 1;
// TODO: This doesn't consider mods which apply variable rates, yet.
foreach (var mod in mods.OfType<IApplicableToRate>())
rate = mod.ApplyToRate(0, rate);