Esempio n. 1
0
        protected override IEnumerator ModuleInitializer()
        {
#if UNITY_EDITOR
            if (!activeInEditor)
            {
                yield break;
            }
#endif
            Debug.Log("Handshake Start ------------");
            _dialogService = _serviceResolver.Get <IGeneralDialogService>();

            _handshakeState = HandshakeLoopState.TryHandshake;

            _connectionHandler = new ConnectionHandler();
            _connectionHandler.Init(null, this);


            while (_handshakeState != HandshakeLoopState.CanContinue)
            {
                if (_handshakeState == HandshakeLoopState.TryHandshake)
                {
                    yield return(StartCoroutine(_connectionHandler.SendRequest(ConnectionHandler.RequestType.GetVersion, HandleHandshakeResponse)));
                }
                else
                {
                    yield return(new WaitForSeconds(1.0f));
                }
            }

            Debug.Log("Handshake end ------------");
            yield break;
        }
Esempio n. 2
0
        //This is for editor scripts.
        public IEnumerator UploadConfig(IConfigData data)
        {
            if (!IsUploadScene() || !Application.isEditor)
            {
                logger.LogError(Tag, "Uploading is only allowed from upload scene & in unity editor");
                yield break;
            }


            JsonData jsonData = JsonMapper.ToObject(JsonMapper.ToJson(data, true));

            jsonData       = PreSend(jsonData, data.GetId(), data.GetTableName(), IsBlobObject(data));
            jsonData["id"] = data.GetId();
            JsonData jd = new JsonData();

            jd.Add(jsonData);

//			Debug.Log(jd.ToJson());

            string tableName = data.GetTableName();

            tableName = AdjustTableToServerTableName(tableName, data);


            yield return(_coroutineFactory.StartCoroutine(() => _connectionHandler.SendRequest(ConnectionHandler.RequestType.UploadConfig, HandleUploadConfigRepsonse, jd.ToJson(), null, tableName)));
        }
Esempio n. 3
0
        IEnumerator RemoteValidationCoro(InAppPurchasableItem item, Promise <bool> promise)
        {
            var data = new ReceiptValidationData();

            var receiptJson = JsonMapper.ToObject(item.receipt);

            data.receipt     = receiptJson["Payload"].ToString();
            data.appBundleId = appInfoService.BundleIdentifier;
            data.iapBundleId = item.id;

                        #if UNITY_ANDROID
            data.receipt  = Convert.ToBase64String(Encoding.UTF8.GetBytes(data.receipt));
            data.platform = "Android";
                        #elif UNITY_IPHONE
            data.platform = "iOS";
                        #endif

            data.nonce = DateTime.Now.ToString();

            string validationData = JsonMapper.ToJson(data);

            Action <ConnectionHandler.RequestResult, string> receiptValidationResponse = (result, responseData) => {
                logger.Log(Tag, "HandleLoginResponse (result=" + result + ")\nresponse=" + responseData.SSubstring(300));

                if (result == ConnectionHandler.RequestResult.Ok)
                {
                    ReceiptValidationResponse response = JsonMapper.ToObject <ReceiptValidationResponse>(responseData);

                    string encryptedNonce = Sha256(data.nonce);

                    if (response.nonce.Equals(encryptedNonce))
                    {
                        if (response.verified)
                        {
                            logger.Log(Tag, "Validation successful");
                            analyticsService.LogEvent(AnalyticsTargets.ANALYTICS_TARGET_FLURRY, Tag, new Dictionary <string, object>()
                            {
                                { "Validation", "successful" }
                            }, false);
                            promise.Resolve(true);
                        }
                        else
                        {
                            logger.LogError(Tag, "Validation failed - not verified");
                            analyticsService.LogEvent(AnalyticsTargets.ANALYTICS_TARGET_FLURRY, Tag, new Dictionary <string, object>()
                            {
                                { "Validation", "failed" }, { "Reason", "Not verified" }
                            }, false);
                            promise.Resolve(false);
                        }
                    }
                    else
                    {
                        logger.LogError(Tag, "Validation failed - non matching nonce");
                        analyticsService.LogEvent(AnalyticsTargets.ANALYTICS_TARGET_FLURRY, Tag, new Dictionary <string, object>()
                        {
                            { "Validation", "failed" }, { "Reason", "Non matching nonce" }
                        }, false);
                        promise.Resolve(false);
                    }
                }
                else
                {
                    logger.LogError(Tag, "Purchase Validation Failure");
                }
            };

            yield return(_coroutineFactory.StartCoroutine(() => _connectionHandler.SendRequest(ConnectionHandler.RequestType.ReceiptValidation,
                                                                                               receiptValidationResponse, validationData)));
        }