diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index 195042ddb9..68557f63f2 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -8,6 +8,7 @@ using System.Diagnostics; using System.Net; using System.Threading; using osu.Framework; +using osu.Framework.Configuration; using osu.Framework.Logging; using osu.Framework.Threading; using osu.Game.Online.API.Requests; @@ -32,6 +33,8 @@ namespace osu.Game.Online.API public string Password; + public Bindable LocalUser = new Bindable(); + public string Token { get { return authentication.Token?.ToString(); } @@ -126,6 +129,17 @@ namespace osu.Game.Online.API continue; } + + var userReq = new GetUserRequest(); + userReq.Success += (u) => { + LocalUser.Value = u; + }; + if (!handleRequest(userReq)) + { + State = APIState.Failing; + continue; + } + //we're connected! State = APIState.Online; failureCount = 0; diff --git a/osu.Game/Online/API/Requests/GetUserRequest.cs b/osu.Game/Online/API/Requests/GetUserRequest.cs new file mode 100644 index 0000000000..1f6da1e1de --- /dev/null +++ b/osu.Game/Online/API/Requests/GetUserRequest.cs @@ -0,0 +1,18 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + + +namespace osu.Game.Online.API.Requests +{ + public class GetUserRequest : APIRequest + { + private int? userId; + + public GetUserRequest(int? userId = null) + { + this.userId = userId; + } + + protected override string Target => userId.HasValue ? $@"users/{userId}" : @"me"; + } +} diff --git a/osu.Game/Online/User.cs b/osu.Game/Online/User.cs index 27de5d8dc2..134167e868 100644 --- a/osu.Game/Online/User.cs +++ b/osu.Game/Online/User.cs @@ -10,6 +10,9 @@ namespace osu.Game.Online [JsonProperty(@"username")] public string Name; + [JsonProperty(@"id")] + public int Id; + [JsonProperty(@"colour")] public string Colour; } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 530f380305..5b35b1e672 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -16,12 +16,14 @@ using osu.Game.Database; using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Processing; using osu.Game.IPC; +using osu.Game.Online; using osu.Game.Online.API; using osu.Game.Overlays; +using osu.Game.Online.API.Requests; namespace osu.Game { - public class OsuGameBase : BaseGame + public class OsuGameBase : BaseGame, IOnlineComponent { internal OsuConfigManager Config; @@ -43,7 +45,7 @@ namespace osu.Game Dependencies.Cache(this); Dependencies.Cache(Config); Dependencies.Cache(new BeatmapDatabase(Host.Storage, Host)); - + //this completely overrides the framework default. will need to change once we make a proper FontStore. Dependencies.Cache(Fonts = new FontStore { ScaleAdjust = 0.01f }, true); @@ -74,12 +76,12 @@ namespace osu.Game Token = Config.Get(OsuConfig.Token) }); - API.OnStateChange += apiStateChanged; + API.Register(this); } - private void apiStateChanged(APIState oldState, APIState newState) + public void APIStateChanged(APIAccess api, APIState state) { - switch (newState) + switch (state) { case APIState.Online: Config.Set(OsuConfig.Username, Config.Get(OsuConfig.SaveUsername) ? API.Username : string.Empty); diff --git a/osu.Game/Overlays/Toolbar/ToolbarUserButton.cs b/osu.Game/Overlays/Toolbar/ToolbarUserButton.cs index 375074ad9e..0c7ea7b797 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarUserButton.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarUserButton.cs @@ -46,7 +46,7 @@ namespace osu.Game.Overlays.Toolbar break; case APIState.Online: Text = api.Username; - avatar.UserId = 2; + avatar.UserId = api.LocalUser.Value.Id; break; } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 76e59db76f..001eae8432 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -70,6 +70,7 @@ +