mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 13:22:55 +08:00
Add proper user data retrieval on connect.
This commit is contained in:
parent
d7ab74363d
commit
6ccce88a0e
@ -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<User> LocalUser = new Bindable<User>();
|
||||
|
||||
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;
|
||||
|
18
osu.Game/Online/API/Requests/GetUserRequest.cs
Normal file
18
osu.Game/Online/API/Requests/GetUserRequest.cs
Normal file
@ -0,0 +1,18 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class GetUserRequest : APIRequest<User>
|
||||
{
|
||||
private int? userId;
|
||||
|
||||
public GetUserRequest(int? userId = null)
|
||||
{
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
protected override string Target => userId.HasValue ? $@"users/{userId}" : @"me";
|
||||
}
|
||||
}
|
@ -10,6 +10,9 @@ namespace osu.Game.Online
|
||||
[JsonProperty(@"username")]
|
||||
public string Name;
|
||||
|
||||
[JsonProperty(@"id")]
|
||||
public int Id;
|
||||
|
||||
[JsonProperty(@"colour")]
|
||||
public string Colour;
|
||||
}
|
||||
|
@ -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<string>(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<bool>(OsuConfig.SaveUsername) ? API.Username : string.Empty);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +70,7 @@
|
||||
<Compile Include="Modes\Score.cs" />
|
||||
<Compile Include="Modes\ScoreProcesssor.cs" />
|
||||
<Compile Include="Online\API\IOnlineComponent.cs" />
|
||||
<Compile Include="Online\API\Requests\GetUserRequest.cs" />
|
||||
<Compile Include="Overlays\DragBar.cs" />
|
||||
<Compile Include="Overlays\MusicController.cs" />
|
||||
<Compile Include="Beatmaps\Beatmap.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user