From 2384f7b0c132597dd88ee7e395fcbb7b8bb6ada7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 May 2017 19:49:50 +0900 Subject: [PATCH 1/3] Ensure LocalUser is never null --- osu.Game/Online/API/APIAccess.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index c4b679fc92..e56e4efe24 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -34,7 +34,7 @@ namespace osu.Game.Online.API public string Password; - public Bindable LocalUser = new Bindable(); + public Bindable LocalUser = new Bindable(createGustUser()); public string Token { @@ -295,8 +295,15 @@ namespace osu.Game.Online.API clearCredentials(); authentication.Clear(); State = APIState.Offline; + LocalUser.Value = createGustUser(); } + private static User createGustUser() => new User + { + Username = @"Guest", + Id = 1, + }; + public void Update() { Scheduler.Update(); From 23807aa3b99419447e8a4d117eb973eac6ed0984 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 May 2017 19:55:45 +0900 Subject: [PATCH 2/3] Better handling of logged in state --- osu.Game/Online/API/APIAccess.cs | 4 +++- osu.Game/Overlays/ChatOverlay.cs | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index e56e4efe24..9d48c38908 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -191,7 +191,7 @@ namespace osu.Game.Online.API req.Perform(this); //we could still be in initialisation, at which point we don't want to say we're Online yet. - if (LocalUser.Value != null) + if (IsLoggedIn) State = APIState.Online; failureCount = 0; @@ -266,6 +266,8 @@ namespace osu.Game.Online.API } } + public bool IsLoggedIn => LocalUser.Value.Id > 1; + public void Queue(APIRequest request) { queue.Enqueue(request); diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index 4748eb7de6..b360417dfd 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -353,7 +353,15 @@ namespace osu.Game.Overlays { var postText = textbox.Text; - if (string.IsNullOrEmpty(postText) || api.LocalUser.Value == null) return; + if (string.IsNullOrEmpty(postText)) + return; + + if (!api.IsLoggedIn) + { + currentChannel?.AddNewMessages(new ErrorMessage("Please login to participate in chat!")); + textbox.Text = string.Empty; + return; + } if (currentChannel == null) return; From 041d4f93c0a66e84b9496b629a477965bfc983e2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 May 2017 20:08:22 +0900 Subject: [PATCH 3/3] Fix typo --- osu.Game/Online/API/APIAccess.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index 9d48c38908..032e5ccc6e 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -34,7 +34,7 @@ namespace osu.Game.Online.API public string Password; - public Bindable LocalUser = new Bindable(createGustUser()); + public Bindable LocalUser = new Bindable(createGuestUser()); public string Token { @@ -297,10 +297,10 @@ namespace osu.Game.Online.API clearCredentials(); authentication.Clear(); State = APIState.Offline; - LocalUser.Value = createGustUser(); + LocalUser.Value = createGuestUser(); } - private static User createGustUser() => new User + private static User createGuestUser() => new User { Username = @"Guest", Id = 1,