1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 13:37:25 +08:00

Add the ability to not use MessagePack when creating a HubConnector

This commit is contained in:
Dean Herbert 2021-08-02 14:44:51 +09:00
parent 1cd967b351
commit 617ff40de7
5 changed files with 13 additions and 7 deletions

View File

@ -257,8 +257,8 @@ namespace osu.Game.Online.API
this.password = password;
}
public IHubClientConnector GetHubConnector(string clientName, string endpoint) =>
new HubClientConnector(clientName, endpoint, this, versionHash);
public IHubClientConnector GetHubConnector(string clientName, string endpoint, bool preferMessagePack) =>
new HubClientConnector(clientName, endpoint, this, versionHash, preferMessagePack);
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password)
{

View File

@ -89,7 +89,7 @@ namespace osu.Game.Online.API
state.Value = APIState.Offline;
}
public IHubClientConnector GetHubConnector(string clientName, string endpoint) => null;
public IHubClientConnector GetHubConnector(string clientName, string endpoint, bool preferMessagePack) => null;
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password)
{

View File

@ -102,7 +102,8 @@ namespace osu.Game.Online.API
/// </summary>
/// <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>
IHubClientConnector? GetHubConnector(string clientName, string endpoint);
/// <param name="preferMessagePack"></param>
IHubClientConnector? GetHubConnector(string clientName, string endpoint, bool preferMessagePack = true);
/// <summary>
/// Create a new user account. This is a blocking operation.

View File

@ -26,6 +26,7 @@ namespace osu.Game.Online
private readonly string clientName;
private readonly string endpoint;
private readonly string versionHash;
private readonly bool preferMessagePack;
private readonly IAPIProvider api;
/// <summary>
@ -51,12 +52,14 @@ namespace osu.Game.Online
/// <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="versionHash">The hash representing the current game version, used for verification purposes.</param>
public HubClientConnector(string clientName, string endpoint, IAPIProvider api, string versionHash)
/// <param name="preferMessagePack">Whether to use MessagePack for serialisation if available on this platform.</param>
public HubClientConnector(string clientName, string endpoint, IAPIProvider api, string versionHash, bool preferMessagePack = true)
{
this.clientName = clientName;
this.endpoint = endpoint;
this.api = api;
this.versionHash = versionHash;
this.preferMessagePack = preferMessagePack;
apiState.BindTo(api.State);
apiState.BindValueChanged(state =>
@ -144,7 +147,7 @@ namespace osu.Game.Online
options.Headers.Add("OsuVersionHash", versionHash);
});
if (RuntimeInfo.SupportsJIT)
if (RuntimeInfo.SupportsJIT && preferMessagePack)
builder.AddMessagePackProtocol();
else
{

View File

@ -37,7 +37,9 @@ namespace osu.Game.Online.Multiplayer
[BackgroundDependencyLoader]
private void load(IAPIProvider api)
{
connector = api.GetHubConnector(nameof(OnlineMultiplayerClient), endpoint);
// Importantly, we are intentionally not using MessagePack here to correctly support derived class serialization.
// More information on the limitations / reasoning can be found in osu-server-spectator's initialisation code.
connector = api.GetHubConnector(nameof(OnlineMultiplayerClient), endpoint, false);
if (connector != null)
{