Exemplo n.º 1
0
    // +++ unity lifecycle ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    async void Start()
    {
        // register ui events
        _ui.OnCreateMatch += OnUiCreateMatch;
        _ui.OnJoinMatch   += OnUiJoinMatch;
        _ui.OnStartGame   += OnStartGame;

        // start nakama client
        _client = new Client("defaultkey", _host, _port, false);

        // const string email = "*****@*****.**";
        // const string password = "******";
        // _session = await _client.AuthenticateEmailAsync(email, password);
        _session = await _client.AuthenticateDeviceAsync(System.Guid.NewGuid().ToString());

        Debug.LogFormat("Authenticated session: {0}", _session);
        Debug.Log(_session.AuthToken); // raw JWT token
        Debug.LogFormat("User id '{0}'", _session.UserId);
        Debug.LogFormat("User username '{0}'", _session.Username);
        Debug.LogFormat("Session has expired: {0}", _session.IsExpired);
        Debug.LogFormat("Session expires at: {0}", _session.ExpireTime); // in seconds.

        _account = await _client.GetAccountAsync(_session);

        Debug.LogFormat("User id '{0}'", _account.User.Id);
        Debug.LogFormat("User username '{0}'", _account.User.Username);
        Debug.LogFormat("Account virtual wallet '{0}'", _account.Wallet);

        _socket                      = _client.CreateWebSocket();
        _socket.OnConnect           += _socket_OnConnect;
        _socket.OnDisconnect        += _socket_OnDisconnect;
        _socket.OnChannelMessage    += _socket_OnChannelMessage;
        _socket.OnChannelPresence   += _socket_OnChannelPresence;
        _socket.OnError             += _socket_OnError;
        _socket.OnMatchmakerMatched += _socket_OnMatchmakerMatched;
        _socket.OnMatchPresence     += _socket_OnMatchPresence;
        _socket.OnMatchState        += _socket_OnMatchState;
        _socket.OnNotification      += _socket_OnNotification;
        _socket.OnStatusPresence    += _socket_OnStatusPresence;
        _socket.OnStreamPresence    += _socket_OnStreamPresence;
        _socket.OnStreamState       += _socket_OnStreamState;
        await _socket.ConnectAsync(_session);
    }
Exemplo n.º 2
0
    // Member variables here, example:
    // private int a = 2;
    // private string b = "textvar";

    public override void _Ready()
    {
        // Called every time the node is added to the scene.
        // Initialization here
        GD.Print("gay stuff");

        try
        {
            var client = new Nakama.Client("defaultkey", "localhost", 7350, true)
            {
                Timeout = 10000, // set timeout on requests (default is 5000).
                Retries = 5      // set retries on requests (default is 3).
            };
            GD.Print("gay stuff");
            var auth = client.AuthenticateEmailAsync("*****@*****.**", "lolpwd").Result;

            GD.Print("auth", auth.Username);
        }
        catch (System.Exception e)
        {
            GD.Print("err", e.ToString());
        }
    }