1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-29 06:33:21 +08:00

Thread safety, username saving correctly etc.

This commit is contained in:
Dean Herbert 2016-11-30 19:22:36 +09:00
parent 3fa80d2376
commit 01dc7cb5c2
4 changed files with 32 additions and 15 deletions

View File

@ -156,7 +156,7 @@ namespace osu.Game.Configuration
Set(OsuConfig.AudioDevice, string.Empty); Set(OsuConfig.AudioDevice, string.Empty);
//Set(OsuConfig.ReleaseStream, ReleaseStream.Lazer, true); //Set(OsuConfig.ReleaseStream, ReleaseStream.Lazer, true);
Set(OsuConfig.UpdateFailCount, 0); Set(OsuConfig.UpdateFailCount, 0);
//Set(OsuConfig.SavePassword, Password != null); Set(OsuConfig.SavePassword, false);
Set(OsuConfig.SaveUsername, true); Set(OsuConfig.SaveUsername, true);
//Set(OsuConfig.TreeSortMode, TreeGroupMode.Show_All); //Set(OsuConfig.TreeSortMode, TreeGroupMode.Show_All);
//Set(OsuConfig.TreeSortMode2, TreeSortMode.Title); //Set(OsuConfig.TreeSortMode2, TreeSortMode.Title);

View File

@ -28,15 +28,9 @@ namespace osu.Game.Online.API
public string Username; public string Username;
private SecurePassword password; //private SecurePassword password;
public string Password public string Password;
{
set
{
password = string.IsNullOrEmpty(value) ? null : new SecurePassword(value);
}
}
public string Token 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; private Thread thread;
@ -70,14 +64,20 @@ namespace osu.Game.Online.API
private List<IOnlineComponent> components = new List<IOnlineComponent>(); private List<IOnlineComponent> components = new List<IOnlineComponent>();
public void Register(IOnlineComponent component) public void Register(IOnlineComponent component)
{
Scheduler.Add(delegate
{ {
components.Add(component); components.Add(component);
component.APIStateChanged(this, state); component.APIStateChanged(this, state);
});
} }
public void Unregister(IOnlineComponent component) public void Unregister(IOnlineComponent component)
{
Scheduler.Add(delegate
{ {
components.Remove(component); components.Remove(component);
});
} }
public string AccessToken => authentication.RequestAccessToken(); public string AccessToken => authentication.RequestAccessToken();
@ -117,7 +117,7 @@ namespace osu.Game.Online.API
if (State < APIState.Connecting) if (State < APIState.Connecting)
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. //todo: this fails even on network-related issues. we should probably handle those differently.
//NotificationManager.ShowMessage("Login failed!"); //NotificationManager.ShowMessage("Login failed!");
@ -157,7 +157,7 @@ namespace osu.Game.Online.API
private void ClearCredentials() private void ClearCredentials()
{ {
Username = null; Username = null;
password = null; Password = null;
} }
public void Login(string username, string password) public void Login(string username, string password)

View File

@ -73,6 +73,19 @@ namespace osu.Game
Password = Config.Get<string>(OsuConfig.Password), Password = Config.Get<string>(OsuConfig.Password),
Token = Config.Get<string>(OsuConfig.Token) 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() protected override void LoadComplete()

View File

@ -139,6 +139,10 @@ namespace osu.Game.Overlays
private void load(OsuConfigManager config) private void load(OsuConfigManager config)
{ {
userButton.Text = config.Get<string>(OsuConfig.Username); 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); public void SetGameMode(PlayMode mode) => modeSelector.SetGameMode(mode);