1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-22 16:16:07 +08:00

Merge pull request #31925 from bdach/wtfffffffffff

Fix several issues with API login flow which manifest on second factor authentication
This commit is contained in:
Dean Herbert 2025-02-18 23:52:42 +09:00 committed by GitHub
commit b905a92b20
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -238,12 +238,13 @@ namespace osu.Game.Online.API
/// <returns>Whether the connection attempt was successful.</returns>
private void attemptConnect()
{
Scheduler.Add(setPlaceholderLocalUser, false);
if (localUser.IsDefault)
Scheduler.Add(setPlaceholderLocalUser, false);
// save the username at this point, if the user requested for it to be.
config.SetValue(OsuSetting.Username, config.Get<bool>(OsuSetting.SaveUsername) ? ProvidedUsername : string.Empty);
if (!authentication.HasValidAccessToken)
if (!authentication.HasValidAccessToken && HasLogin)
{
state.Value = APIState.Connecting;
LastLoginError = null;
@ -252,6 +253,10 @@ namespace osu.Game.Online.API
{
authentication.AuthenticateWithLogin(ProvidedUsername, password);
}
catch (WebRequestFlushedException)
{
return;
}
catch (Exception e)
{
//todo: this fails even on network-related issues. we should probably handle those differently.
@ -312,7 +317,7 @@ namespace osu.Game.Online.API
log.Add(@"Login no longer valid");
Logout();
}
else
else if (ex is not WebRequestFlushedException)
{
state.Value = APIState.Failing;
}
@ -493,6 +498,11 @@ namespace osu.Game.Online.API
handleWebException(we);
return false;
}
catch (WebRequestFlushedException wrf)
{
log.Add(wrf.Message);
return false;
}
catch (Exception ex)
{
Logger.Error(ex, "Error occurred while handling an API request.");
@ -574,7 +584,7 @@ namespace osu.Game.Online.API
if (failOldRequests)
{
foreach (var req in oldQueueRequests)
req.Fail(new WebException($@"Request failed from flush operation (state {state.Value})"));
req.Fail(new WebRequestFlushedException(state.Value));
}
}
}
@ -605,7 +615,11 @@ namespace osu.Game.Online.API
return;
var friendsReq = new GetFriendsRequest();
friendsReq.Failure += _ => state.Value = APIState.Failing;
friendsReq.Failure += ex =>
{
if (ex is not WebRequestFlushedException)
state.Value = APIState.Failing;
};
friendsReq.Success += res =>
{
var existingFriends = friends.Select(f => f.TargetID).ToHashSet();
@ -630,6 +644,14 @@ namespace osu.Game.Online.API
flushQueue();
cancellationToken.Cancel();
}
private class WebRequestFlushedException : Exception
{
public WebRequestFlushedException(APIState state)
: base($@"Request failed from flush operation (state {state})")
{
}
}
}
internal class GuestUser : APIUser