Пример #1
0
        /// <summary>
        /// Send the given request durable.
        /// Durable requests are persisted automatically.
        /// If it cannot be send right now the sdk will try to send it later.
        /// </summary>
        private void SendDurable(GSRequest request)
        {
            request.AddString("requestId", "d_" + DateTime.Now.Ticks + "_" + (_requestCounter++));

            _persistantQueue.AddLast(request);

            _durableQueueDirty = true;
        }
Пример #2
0
        private void SendHandshake(GSObject response, GSConnection connection)
        {
            GSRequest handshakeRequest = new GSRequest(this, "AuthenticatedConnectRequest");

            if (OnGameSparksNonce != null)
            {
                handshakeRequest.AddString("hmac", OnGameSparksNonce(response.GetString("nonce")));
            }
            else
            {
                handshakeRequest.AddString("hmac", GSPlatform.MakeHmac(response.GetString("nonce"), GSPlatform.ApiSecret));
            }

            handshakeRequest.AddString("os", GSPlatform.DeviceOS);
            handshakeRequest.AddString("platform", GSPlatform.Platform);
            handshakeRequest.AddString("deviceId", GSPlatform.DeviceId);

            if (GSPlatform.AuthToken != null && !GSPlatform.AuthToken.Equals("0"))
            {
                handshakeRequest.AddString("authToken", GSPlatform.AuthToken);
            }

            if (_sessionId != null)
            {
                handshakeRequest.AddString("sessionId", _sessionId);
            }

            connection.SendImmediate(handshakeRequest);
        }
Пример #3
0
        internal void SendImmediate(GSRequest request)
        {
            if (_WebSocketClient != null)
            {
                lock (_WebSocketClient)
                {
                    if (_WebSocketClient != null)
                    {
                        if (!request.Type.Equals(".AuthenticatedConnectRequest"))
                        {
                            if (request.GetString("requestId") == null)
                            {
                                request.AddString("requestId", DateTime.Now.Ticks + "_" + (_gs._requestCounter++));
                            }

                            //if (request.MaxResponseTimeInMillis != _gs.RequestTimeout) {
                            //	request.AddNumber ("timeout", request.MaxResponseTimeInMillis);
                            //}

                            lock (_pendingRequests) {
                                _pendingRequests.Add(request.GetString("requestId"), request);
                            }
                        }

                        String requestJson = request.JSON;

                        _gSPlatform.DebugMsg("SEND:" + requestJson);

                        //Wrap it in a secure request
                        if (_gs.GSPlatform.ApiSecret.Contains(":") && SessionId != null)
                        {
                            GSRequestData secureRequest = new GSRequestData();

                            secureRequest.AddString("json", requestJson);
                            secureRequest.AddString("hmac", _gs.GSPlatform.MakeHmac(requestJson, _gs.GSPlatform.ApiSecret + "-" + SessionId));

                            requestJson = secureRequest.JSON;
                        }

                        if (_gs.GSPlatform.ApiSecret.Contains(":"))
                        {
                            requestJson = Encrypt(requestJson);
                        }

                        if (_gs.TraceMessages)
                        {
                            _gSPlatform.DebugMsg("SOCKET-SEND:" + requestJson);
                        }

                        _WebSocketClient.Send(requestJson);
                    }
                }
            }
        }