Skip to content

Commit

Permalink
Merge pull request #28892 from bdach/better-client-identifier
Browse files Browse the repository at this point in the history
Send client-generated session GUID for identification purposes
  • Loading branch information
peppy authored Jul 17, 2024
2 parents d32fef8 + 2a601ce commit 99c5025
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions osu.Game/Online/API/APIAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ private WebSocketNotificationsClientConnector setUpNotificationsClient()

public string AccessToken => authentication.RequestAccessToken();

public Guid SessionIdentifier { get; } = Guid.NewGuid();

/// <summary>
/// Number of consecutive requests which failed due to network issues.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions osu.Game/Online/API/DummyAPIAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public partial class DummyAPIAccess : Component, IAPIProvider

public string AccessToken => "token";

public Guid SessionIdentifier { get; } = Guid.NewGuid();

/// <seealso cref="APIAccess.IsLoggedIn"/>
public bool IsLoggedIn => State.Value > APIState.Offline;

Expand Down
6 changes: 6 additions & 0 deletions osu.Game/Online/API/IAPIProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public interface IAPIProvider
/// </summary>
string AccessToken { get; }

/// <summary>
/// Used as an identifier of a single local lazer session.
/// Sent across the wire for the purposes of concurrency control to spectator server.
/// </summary>
Guid SessionIdentifier { get; }

/// <summary>
/// Returns whether the local user is logged in.
/// </summary>
Expand Down
10 changes: 8 additions & 2 deletions osu.Game/Online/HubClientConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class HubClientConnector : PersistentEndpointClientConnector, IHubClientC
{
public const string SERVER_SHUTDOWN_MESSAGE = "Server is shutting down.";

public const string VERSION_HASH_HEADER = @"X-Osu-Version-Hash";
public const string CLIENT_SESSION_ID_HEADER = @"X-Client-Session-ID";

/// <summary>
/// Invoked whenever a new hub connection is built, to configure it before it's started.
/// </summary>
Expand Down Expand Up @@ -68,8 +71,11 @@ protected override Task<PersistentEndpointClient> BuildConnectionAsync(Cancellat
options.Proxy.Credentials = CredentialCache.DefaultCredentials;
}
options.Headers.Add("Authorization", $"Bearer {API.AccessToken}");
options.Headers.Add("OsuVersionHash", versionHash);
options.Headers.Add(@"Authorization", @$"Bearer {API.AccessToken}");
// non-standard header name kept for backwards compatibility, can be removed after server side has migrated to `VERSION_HASH_HEADER`
options.Headers.Add(@"OsuVersionHash", versionHash);
options.Headers.Add(VERSION_HASH_HEADER, versionHash);
options.Headers.Add(CLIENT_SESSION_ID_HEADER, API.SessionIdentifier.ToString());
});

if (RuntimeFeature.IsDynamicCodeCompiled && preferMessagePack)
Expand Down

0 comments on commit 99c5025

Please sign in to comment.