diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index c4b679fc92..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(); + public Bindable LocalUser = new Bindable(createGuestUser()); public string Token { @@ -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); @@ -295,8 +297,15 @@ namespace osu.Game.Online.API clearCredentials(); authentication.Clear(); State = APIState.Offline; + LocalUser.Value = createGuestUser(); } + private static User createGuestUser() => new User + { + Username = @"Guest", + Id = 1, + }; + public void Update() { Scheduler.Update(); 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;