mirror of
https://github.com/osukey/osukey.git
synced 2025-05-17 11:37:32 +09:00
Merge pull request #1317 from peppy/api-state-fixes
Move all APIAccess State changes to the local thread
This commit is contained in:
commit
23d688bb35
@ -101,18 +101,16 @@ namespace osu.Game.Online.API
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case APIState.Offline:
|
case APIState.Offline:
|
||||||
|
case APIState.Connecting:
|
||||||
//work to restore a connection...
|
//work to restore a connection...
|
||||||
if (!HasLogin)
|
if (!HasLogin)
|
||||||
{
|
{
|
||||||
//OsuGame.Scheduler.Add(() => { OsuGame.ShowLogin(); });
|
|
||||||
|
|
||||||
State = APIState.Offline;
|
State = APIState.Offline;
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(50);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (State < APIState.Connecting)
|
State = APIState.Connecting;
|
||||||
State = APIState.Connecting;
|
|
||||||
|
|
||||||
if (!authentication.HasValidAccessToken && !authentication.AuthenticateWithLogin(Username, Password))
|
if (!authentication.HasValidAccessToken && !authentication.AuthenticateWithLogin(Username, Password))
|
||||||
{
|
{
|
||||||
@ -125,7 +123,8 @@ namespace osu.Game.Online.API
|
|||||||
|
|
||||||
|
|
||||||
var userReq = new GetUserRequest();
|
var userReq = new GetUserRequest();
|
||||||
userReq.Success += u => {
|
userReq.Success += u =>
|
||||||
|
{
|
||||||
LocalUser.Value = u;
|
LocalUser.Value = u;
|
||||||
//we're connected!
|
//we're connected!
|
||||||
State = APIState.Online;
|
State = APIState.Online;
|
||||||
@ -133,16 +132,14 @@ namespace osu.Game.Online.API
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!handleRequest(userReq))
|
if (!handleRequest(userReq))
|
||||||
{
|
|
||||||
State = APIState.Failing;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//hard bail if we can't get a valid access token.
|
//hard bail if we can't get a valid access token.
|
||||||
if (authentication.RequestAccessToken() == null)
|
if (authentication.RequestAccessToken() == null)
|
||||||
{
|
{
|
||||||
|
Logout(false);
|
||||||
State = APIState.Offline;
|
State = APIState.Offline;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -162,20 +159,12 @@ namespace osu.Game.Online.API
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearCredentials()
|
|
||||||
{
|
|
||||||
Username = null;
|
|
||||||
Password = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Login(string username, string password)
|
public void Login(string username, string password)
|
||||||
{
|
{
|
||||||
Debug.Assert(State == APIState.Offline);
|
Debug.Assert(State == APIState.Offline);
|
||||||
|
|
||||||
Username = username;
|
Username = username;
|
||||||
Password = password;
|
Password = password;
|
||||||
|
|
||||||
State = APIState.Connecting;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -204,7 +193,7 @@ namespace osu.Game.Online.API
|
|||||||
switch (statusCode)
|
switch (statusCode)
|
||||||
{
|
{
|
||||||
case HttpStatusCode.Unauthorized:
|
case HttpStatusCode.Unauthorized:
|
||||||
State = APIState.Offline;
|
Logout(false);
|
||||||
return true;
|
return true;
|
||||||
case HttpStatusCode.RequestTimeout:
|
case HttpStatusCode.RequestTimeout:
|
||||||
failureCount++;
|
failureCount++;
|
||||||
@ -215,6 +204,7 @@ namespace osu.Game.Online.API
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
State = APIState.Failing;
|
State = APIState.Failing;
|
||||||
|
flushQueue();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,26 +232,14 @@ namespace osu.Game.Online.API
|
|||||||
|
|
||||||
state = value;
|
state = value;
|
||||||
|
|
||||||
switch (state)
|
|
||||||
{
|
|
||||||
case APIState.Failing:
|
|
||||||
case APIState.Offline:
|
|
||||||
flushQueue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldState != newState)
|
if (oldState != newState)
|
||||||
{
|
{
|
||||||
//OsuGame.Scheduler.Add(delegate
|
log.Add($@"We just went {newState}!");
|
||||||
|
Scheduler.Add(delegate
|
||||||
{
|
{
|
||||||
//NotificationOverlay.ShowMessage($@"We just went {newState}!", newState == APIState.Online ? Color4.YellowGreen : Color4.OrangeRed, 5000);
|
components.ForEach(c => c.APIStateChanged(this, newState));
|
||||||
log.Add($@"We just went {newState}!");
|
OnStateChange?.Invoke(oldState, newState);
|
||||||
Scheduler.Add(delegate
|
});
|
||||||
{
|
|
||||||
components.ForEach(c => c.APIStateChanged(this, newState));
|
|
||||||
OnStateChange?.Invoke(oldState, newState);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -292,11 +270,12 @@ namespace osu.Game.Online.API
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Logout()
|
public void Logout(bool clearUsername = true)
|
||||||
{
|
{
|
||||||
clearCredentials();
|
flushQueue();
|
||||||
|
if (clearUsername) Username = null;
|
||||||
|
Password = null;
|
||||||
authentication.Clear();
|
authentication.Clear();
|
||||||
State = APIState.Offline;
|
|
||||||
LocalUser.Value = createGuestUser();
|
LocalUser.Value = createGuestUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user