mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 02:32:59 +08:00
Thread safety, username saving correctly etc.
This commit is contained in:
parent
3fa80d2376
commit
01dc7cb5c2
@ -156,7 +156,7 @@ namespace osu.Game.Configuration
|
||||
Set(OsuConfig.AudioDevice, string.Empty);
|
||||
//Set(OsuConfig.ReleaseStream, ReleaseStream.Lazer, true);
|
||||
Set(OsuConfig.UpdateFailCount, 0);
|
||||
//Set(OsuConfig.SavePassword, Password != null);
|
||||
Set(OsuConfig.SavePassword, false);
|
||||
Set(OsuConfig.SaveUsername, true);
|
||||
//Set(OsuConfig.TreeSortMode, TreeGroupMode.Show_All);
|
||||
//Set(OsuConfig.TreeSortMode2, TreeSortMode.Title);
|
||||
|
@ -28,15 +28,9 @@ namespace osu.Game.Online.API
|
||||
|
||||
public string Username;
|
||||
|
||||
private SecurePassword password;
|
||||
//private SecurePassword password;
|
||||
|
||||
public string Password
|
||||
{
|
||||
set
|
||||
{
|
||||
password = string.IsNullOrEmpty(value) ? null : new SecurePassword(value);
|
||||
}
|
||||
}
|
||||
public string Password;
|
||||
|
||||
public string Token
|
||||
{
|
||||
@ -52,7 +46,7 @@ namespace osu.Game.Online.API
|
||||
}
|
||||
}
|
||||
|
||||
protected bool HasLogin => Token != null || (!string.IsNullOrEmpty(Username) && password != null);
|
||||
protected bool HasLogin => Token != null || (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password));
|
||||
|
||||
private Thread thread;
|
||||
|
||||
@ -71,13 +65,19 @@ namespace osu.Game.Online.API
|
||||
|
||||
public void Register(IOnlineComponent component)
|
||||
{
|
||||
components.Add(component);
|
||||
component.APIStateChanged(this, state);
|
||||
Scheduler.Add(delegate
|
||||
{
|
||||
components.Add(component);
|
||||
component.APIStateChanged(this, state);
|
||||
});
|
||||
}
|
||||
|
||||
public void Unregister(IOnlineComponent component)
|
||||
{
|
||||
components.Remove(component);
|
||||
Scheduler.Add(delegate
|
||||
{
|
||||
components.Remove(component);
|
||||
});
|
||||
}
|
||||
|
||||
public string AccessToken => authentication.RequestAccessToken();
|
||||
@ -117,7 +117,7 @@ namespace osu.Game.Online.API
|
||||
if (State < APIState.Connecting)
|
||||
State = APIState.Connecting;
|
||||
|
||||
if (!authentication.HasValidAccessToken && !authentication.AuthenticateWithLogin(Username, password.Get(Representation.Raw)))
|
||||
if (!authentication.HasValidAccessToken && !authentication.AuthenticateWithLogin(Username, Password))
|
||||
{
|
||||
//todo: this fails even on network-related issues. we should probably handle those differently.
|
||||
//NotificationManager.ShowMessage("Login failed!");
|
||||
@ -157,7 +157,7 @@ namespace osu.Game.Online.API
|
||||
private void ClearCredentials()
|
||||
{
|
||||
Username = null;
|
||||
password = null;
|
||||
Password = null;
|
||||
}
|
||||
|
||||
public void Login(string username, string password)
|
||||
|
@ -73,6 +73,19 @@ namespace osu.Game
|
||||
Password = Config.Get<string>(OsuConfig.Password),
|
||||
Token = Config.Get<string>(OsuConfig.Token)
|
||||
});
|
||||
|
||||
API.OnStateChange += apiStateChanged;
|
||||
}
|
||||
|
||||
private void apiStateChanged(APIState oldState, APIState newState)
|
||||
{
|
||||
switch (newState)
|
||||
{
|
||||
case APIState.Online:
|
||||
Config.Set(OsuConfig.Username, Config.Get<bool>(OsuConfig.SaveUsername) ? API.Username : string.Empty);
|
||||
Config.Set(OsuConfig.Password, Config.Get<bool>(OsuConfig.SavePassword) ? API.Password : string.Empty);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
|
@ -139,6 +139,10 @@ namespace osu.Game.Overlays
|
||||
private void load(OsuConfigManager config)
|
||||
{
|
||||
userButton.Text = config.Get<string>(OsuConfig.Username);
|
||||
config.GetBindable<string>(OsuConfig.Username).ValueChanged += delegate
|
||||
{
|
||||
userButton.Text = config.Get<string>(OsuConfig.Username);
|
||||
};
|
||||
}
|
||||
|
||||
public void SetGameMode(PlayMode mode) => modeSelector.SetGameMode(mode);
|
||||
|
Loading…
Reference in New Issue
Block a user