1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 15:12:57 +08:00

Merge branch 'master' into non-concurrent-sample-playback

This commit is contained in:
Dean Herbert 2021-02-15 22:05:11 +09:00 committed by GitHub
commit a1bee5d721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 5 deletions

View File

@ -25,6 +25,8 @@ namespace osu.Game.Online.API
{ {
private readonly OsuConfigManager config; private readonly OsuConfigManager config;
private readonly string versionHash;
private readonly OAuth authentication; private readonly OAuth authentication;
private readonly Queue<APIRequest> queue = new Queue<APIRequest>(); private readonly Queue<APIRequest> queue = new Queue<APIRequest>();
@ -56,9 +58,10 @@ namespace osu.Game.Online.API
private readonly Logger log; private readonly Logger log;
public APIAccess(OsuConfigManager config, EndpointConfiguration endpointConfiguration) public APIAccess(OsuConfigManager config, EndpointConfiguration endpointConfiguration, string versionHash)
{ {
this.config = config; this.config = config;
this.versionHash = versionHash;
APIEndpointUrl = endpointConfiguration.APIEndpointUrl; APIEndpointUrl = endpointConfiguration.APIEndpointUrl;
WebsiteRootUrl = endpointConfiguration.WebsiteRootUrl; WebsiteRootUrl = endpointConfiguration.WebsiteRootUrl;
@ -243,7 +246,7 @@ namespace osu.Game.Online.API
this.password = password; this.password = password;
} }
public IHubClientConnector GetHubConnector(string clientName, string endpoint) => new HubClientConnector(clientName, endpoint, this); public IHubClientConnector GetHubConnector(string clientName, string endpoint) => new HubClientConnector(clientName, endpoint, this, versionHash);
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password) public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password)
{ {

View File

@ -25,6 +25,7 @@ namespace osu.Game.Online
private readonly string clientName; private readonly string clientName;
private readonly string endpoint; private readonly string endpoint;
private readonly string versionHash;
private readonly IAPIProvider api; private readonly IAPIProvider api;
/// <summary> /// <summary>
@ -49,11 +50,13 @@ namespace osu.Game.Online
/// <param name="clientName">The name of the client this connector connects for, used for logging.</param> /// <param name="clientName">The name of the client this connector connects for, used for logging.</param>
/// <param name="endpoint">The endpoint to the hub.</param> /// <param name="endpoint">The endpoint to the hub.</param>
/// <param name="api"> An API provider used to react to connection state changes.</param> /// <param name="api"> An API provider used to react to connection state changes.</param>
public HubClientConnector(string clientName, string endpoint, IAPIProvider api) /// <param name="versionHash">The hash representing the current game version, used for verification purposes.</param>
public HubClientConnector(string clientName, string endpoint, IAPIProvider api, string versionHash)
{ {
this.clientName = clientName; this.clientName = clientName;
this.endpoint = endpoint; this.endpoint = endpoint;
this.api = api; this.api = api;
this.versionHash = versionHash;
apiState.BindTo(api.State); apiState.BindTo(api.State);
apiState.BindValueChanged(state => apiState.BindValueChanged(state =>
@ -129,7 +132,11 @@ namespace osu.Game.Online
private HubConnection buildConnection(CancellationToken cancellationToken) private HubConnection buildConnection(CancellationToken cancellationToken)
{ {
var builder = new HubConnectionBuilder() var builder = new HubConnectionBuilder()
.WithUrl(endpoint, options => { options.Headers.Add("Authorization", $"Bearer {api.AccessToken}"); }); .WithUrl(endpoint, options =>
{
options.Headers.Add("Authorization", $"Bearer {api.AccessToken}");
options.Headers.Add("OsuVersionHash", versionHash);
});
if (RuntimeInfo.SupportsJIT) if (RuntimeInfo.SupportsJIT)
builder.AddMessagePackProtocol(); builder.AddMessagePackProtocol();

View File

@ -228,7 +228,7 @@ namespace osu.Game
MessageFormatter.WebsiteRootUrl = endpoints.WebsiteRootUrl; MessageFormatter.WebsiteRootUrl = endpoints.WebsiteRootUrl;
dependencies.CacheAs(API ??= new APIAccess(LocalConfig, endpoints)); dependencies.CacheAs(API ??= new APIAccess(LocalConfig, endpoints, VersionHash));
dependencies.CacheAs(spectatorStreaming = new SpectatorStreamingClient(endpoints)); dependencies.CacheAs(spectatorStreaming = new SpectatorStreamingClient(endpoints));
dependencies.CacheAs(multiplayerClient = new MultiplayerClient(endpoints)); dependencies.CacheAs(multiplayerClient = new MultiplayerClient(endpoints));