Merge pull request #765 from peppy/fix-guest-user

Fix guest user being null
This commit is contained in:
Dan Balasescu 2017-05-16 20:52:25 +09:00 committed by GitHub
commit 14b06f3600
2 changed files with 20 additions and 3 deletions

View File

@ -34,7 +34,7 @@ namespace osu.Game.Online.API
public string Password; public string Password;
public Bindable<User> LocalUser = new Bindable<User>(); public Bindable<User> LocalUser = new Bindable<User>(createGuestUser());
public string Token public string Token
{ {
@ -191,7 +191,7 @@ namespace osu.Game.Online.API
req.Perform(this); req.Perform(this);
//we could still be in initialisation, at which point we don't want to say we're Online yet. //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; State = APIState.Online;
failureCount = 0; failureCount = 0;
@ -266,6 +266,8 @@ namespace osu.Game.Online.API
} }
} }
public bool IsLoggedIn => LocalUser.Value.Id > 1;
public void Queue(APIRequest request) public void Queue(APIRequest request)
{ {
queue.Enqueue(request); queue.Enqueue(request);
@ -295,8 +297,15 @@ namespace osu.Game.Online.API
clearCredentials(); clearCredentials();
authentication.Clear(); authentication.Clear();
State = APIState.Offline; State = APIState.Offline;
LocalUser.Value = createGuestUser();
} }
private static User createGuestUser() => new User
{
Username = @"Guest",
Id = 1,
};
public void Update() public void Update()
{ {
Scheduler.Update(); Scheduler.Update();

View File

@ -353,7 +353,15 @@ namespace osu.Game.Overlays
{ {
var postText = textbox.Text; 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; if (currentChannel == null) return;