heroiclabs / nakama-dotnet

.NET client for Nakama server written in C#.
https://heroiclabs.com/docs/nakama/client-libraries/unity/
Apache License 2.0
122 stars 45 forks source link

C# - RpcAsync called with HttpKey+Payload does not execute as a POST request #26

Open novabyte opened 4 years ago

novabyte commented 4 years ago

As a workaround its possible to add the attached extension method to the IClient type which will enable usage which looks like:

var payload = new Dictionary<string, string>
{
    {"foo", "bar"}
};
try
{
    var rpcResponse = await _client.RpcAsyncPost(HttpKey, RpcId, payload.ToJson());
    Debug.LogFormat("rpcResponse: {0}", rpcResponse);
}
catch (ApiResponseException e)
{
    Debug.LogException(e);
}

A proper fix should be implemented in the code generator for the client sdk to handle this special case logic.

RpcHttpKeyExtensions.cs.txt

ShadowFactoryTeam commented 3 years ago

We're using the provided RpcHttpKeyExtensions.cs and until now it was working perfectly!

We've just rolled out HTTPS support across our solutions and we're getting an issue with the only implementation that uses RPCAsyncPost. The returned exception is Cert handshake failed. verify result: UNITYTLS_X509VERIFY_FATAL_ERROR.

novabyte commented 3 years ago

@ShadowFactoryTeam I took another look at the extension code I'd written to refresh it in my mind. There's nothing in it that does anything different to the rest of the SDK. It uses the same UnityWebRequestAdapter.Instance as all the other SDK functions would.

Can you share code for how you initialize the Client type in your project?

ShadowFactoryTeam commented 3 years ago

There's no difference with how we initialize

public Client Client
{
    get
    {
        if (_client == null)
        {
            _client = new Client(_httpScheme, _ipAddress, _port, _authSocketString, UnityWebRequestAdapter.Instance);
        }
        return _client;
    }
}

This particular function with the issue is run on headless unity servers, we now believe it has to do with another issue that plagues Linux / Unity projects outlined here - https://forum.unity.com/threads/ubuntu-headless-build-tls-handshake-fails.546704/

novabyte commented 3 years ago

@ShadowFactoryTeam I had a read of the issue on that forum thread and it looks like what you'll need to do:

  1. Make sure the curl package is installed on the base distro that your headless instances are running on.
  2. Figure out where the certificate store is on your base distro and symlink it to the location that Unity expects to find it at startup.

Hope that helps.

ShadowFactoryTeam commented 3 years ago

@novabyte the missing CURL package was indeed the issue. Thanks for helping.