From beb3d41f0c945a77a24307de5a4940616a1b10df Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 9 Aug 2022 16:38:12 +0900 Subject: [PATCH 1/4] Fix unsafe usage of `APIAccess.LocalUser` in `BeatmapListingOverlay` --- osu.Game/Overlays/BeatmapListingOverlay.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/BeatmapListingOverlay.cs b/osu.Game/Overlays/BeatmapListingOverlay.cs index cfa53009ef..3136492af0 100644 --- a/osu.Game/Overlays/BeatmapListingOverlay.cs +++ b/osu.Game/Overlays/BeatmapListingOverlay.cs @@ -104,11 +104,11 @@ namespace osu.Game.Overlays filterControl.CardSize.BindValueChanged(_ => onCardSizeChanged()); apiUser = api.LocalUser.GetBoundCopy(); - apiUser.BindValueChanged(_ => + apiUser.BindValueChanged(_ => Schedule(() => { if (api.IsLoggedIn) addContentToResultsArea(Drawable.Empty()); - }); + })); } public void ShowWithSearch(string query) From f9d0cc3c4e5a8c39034fab117ba3c622eb5a36e9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 9 Aug 2022 16:38:59 +0900 Subject: [PATCH 2/4] Change `APIAccess.IsLoggedIn` to also return `true` when connecting All usages of this are made with the intention of showing data when an api is going to eventually become available. In the case of a login failure, components are also able to display a correct state. With this change, it makes online components display in a more correct state during startup or initial logging in phase. --- osu.Game/Online/API/APIAccess.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index 7af19f6dd1..e198632ea6 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -402,7 +402,7 @@ namespace osu.Game.Online.API } } - public bool IsLoggedIn => localUser.Value.Id > 1; // TODO: should this also be true if attempting to connect? + public bool IsLoggedIn => State.Value > APIState.Offline; public void Queue(APIRequest request) { From 4a312d5658d5ce2ff22fd0a79d36006508400e9b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 9 Aug 2022 16:40:20 +0900 Subject: [PATCH 3/4] Use a placeholder user with the correct username during connecting process This allows for various components (like gameplay) to obtain a correct username even if the API is not yet in a connected state. The most common case is during startup, where a connection may not have been established yet, but the user's username was restored from their config file. By making the change, local scores will now have the correct username (although avatar etc. will be missing, which I think it fine) even if the API is not yet connected. Previously, they would show up as "Guest". --- osu.Game/Online/API/APIAccess.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index e198632ea6..42133160ca 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -137,6 +137,17 @@ namespace osu.Game.Online.API state.Value = APIState.Connecting; + if (localUser.IsDefault) + { + // Show a placeholder user if saved credentials are available. + // This is useful for storing local scores and showing a placeholder username after starting the game, + // until a valid connection has been established. + localUser.Value = new APIUser + { + Username = ProvidedUsername, + }; + } + // save the username at this point, if the user requested for it to be. config.SetValue(OsuSetting.Username, config.Get(OsuSetting.SaveUsername) ? ProvidedUsername : string.Empty); From a5081826b78b484d6efa9f8dce7e2377c07448b0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 9 Aug 2022 23:25:19 +0900 Subject: [PATCH 4/4] Handle cancellation at more points during `Player` initialisation As discussed in discord, this will help avoid null references during cancellation which can otherwise be quite confusing to debug. --- osu.Game/Screens/Play/Player.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 9c08c77d91..08b6da1921 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -249,6 +249,9 @@ namespace osu.Game.Screens.Play // this is intentionally done in two stages to ensure things are in a loaded state before exposing the ruleset to skin sources. GameplayClockContainer.Add(rulesetSkinProvider); + if (cancellationToken.IsCancellationRequested) + return; + rulesetSkinProvider.AddRange(new Drawable[] { failAnimationLayer = new FailAnimation(DrawableRuleset) @@ -279,6 +282,9 @@ namespace osu.Game.Screens.Play }, }); + if (cancellationToken.IsCancellationRequested) + return; + if (Configuration.AllowRestart) { rulesetSkinProvider.Add(new HotkeyRetryOverlay