Пример #1
0
        public void ConnectToNetwork(SocialConnectData socialConnectData)
        {
            string userIdAfterOverride = socialConnectData.userId;

            if (socialConnectData.network == SocialNetwork.Facebook && _fakeFacebookId != "0")
            {
                userIdAfterOverride = _fakeFacebookId;
            }
            if (socialConnectData.network == SocialNetwork.GameCenter && _fakeGameCenterId != "0")
            {
                userIdAfterOverride = _fakeGameCenterId;
            }
            if (socialConnectData.network == SocialNetwork.PlayServices && _fakePlayServicesId != "0")
            {
                userIdAfterOverride = _fakePlayServicesId;
            }
            if (userIdAfterOverride == socialConnectData.userId)
            {
                logger.Log(Tag, "SocialSync.ConnectToNetwork: network=" + socialConnectData.network.ToString() + " userId=" + socialConnectData.userId
                           + " (not overriden by config) token=" + socialConnectData.userToken);
            }
            else
            {
                logger.Log(Tag, "SocialSync.ConnectToNetwork: network=" + socialConnectData.network.ToString() + " userId=" + socialConnectData.userId
                           + " (after config override=" + userIdAfterOverride + ") token=" + socialConnectData.userToken);
            }
            socialConnectData.userId = userIdAfterOverride;

            _coroutineFactory.StartCoroutine(() => ConnectToNetworkCoro(socialConnectData));
        }
Пример #2
0
        private IEnumerator ConnectToNetworkCoro(SocialConnectData socialConnectData)
        {
            _socialUserId[socialConnectData.network] = socialConnectData.userId;
            if (socialStateModel.GetNetworkUserId(socialConnectData.network) == socialConnectData.userId)             // 1. If no change done - dont call server
            {
                logger.Log(Tag, "ConnectToNetwork - connected to " + socialConnectData.network.ToString());
                _socialConnectionStatus[socialConnectData.network] = true;
                if (socialConnectData.initiatedByUser)
                {
                    handleSocialServerVerificationSignal.Dispatch(socialConnectData.network);
                }

                socialSyncCompletedSignal.Dispatch();
                yield break;
            }

            logger.Log(Tag, "ConnectToNetworkCoro - attempting to set user id of " + socialConnectData.network.ToString() + " to " + socialConnectData.userId);

            logger.Log(Tag, "ConnectToNetworkCoro - waiting for ModelSync to connect");
            yield return(_coroutineFactory.StartCoroutine(() => modelSyncService.WaitForState(ModelSyncService.SyncLoopState.Connected)));

            logger.Log(Tag, "ConnectToNetworkCoro - sending request");
            string previousUserId   = socialStateModel.GetNetworkUserId(socialConnectData.network);
            bool   firstTimeConnect = (previousUserId == null || previousUserId.Length == 0);           // this will dictate GET/POST request (by adding body if true)

            logger.Log(Tag, "firstTimeConnect= " + firstTimeConnect + " previousUserId=[" + previousUserId + "]");

            socialConnectData.firstTimeConnect = firstTimeConnect;

            socialSyncStartedSignal.Dispatch();

            yield return(_coroutineFactory.StartCoroutine(() => _connectionHandler.SendRequest(ConnectionHandler.RequestType.ConnectToSocialNetwork,
                                                                                               HandleConnectToNetworkResponse, "", socialConnectData)));
        }
        public IEnumerator SendConnectToNetworkRequest(SocialConnectData socialConnectData)
        {
            BuildConnectToNetworkRequest(socialConnectData);
            byte[] body = "FirstTimeConnect".ToByteArray();

            if (socialConnectData.firstTimeConnect)
            {
                SetHeaders(body.Length);
                LogRequest("ConnectToNetworkRequest", "FirstTimeConnect");

                WWW wwwRequest = new WWW(_requestUrl, body, _headers);
                yield return(wwwRequest);

                yield return(_coroutineFactory.StartCoroutine(() => EvaluateRequestStatus(wwwRequest)));
            }
            else
            {
                SetHeaders(0);
                LogRequest("ConnectToNetworkRequest", null);

                WWW wwwRequest = new WWW(_requestUrl, null, _headers);
                yield return(wwwRequest);

                yield return(_coroutineFactory.StartCoroutine(() => EvaluateRequestStatus(wwwRequest)));
            }
        }
        public override void Execute()
        {
            CoreLogger.LogDebug(LoggerModules.SocialServices, "Execute IsLoggedIn " + isLoggedIn);

            socialStateModel.WaitingForSocialLogin = false;


            if (!isLoggedIn)
            {
                //toggleLoadingDialogSignal.Dispatch(false);
                return;
            }

            SocialConnectData socialConnectData = new SocialConnectData();

            socialConnectData.network         = SocialNetwork.Facebook;
            socialConnectData.email           = socialNetworkService.Email;
            socialConnectData.photoUrl        = socialNetworkService.PhotoUrl;
            socialConnectData.userName        = socialNetworkService.UserName;
            socialConnectData.userId          = socialNetworkService.UserId;
            socialConnectData.userToken       = socialNetworkService.UserToken;
            socialConnectData.initiatedByUser = true;

            socialSync.ConnectToNetwork(socialConnectData);
        }
        private void BuildConnectToNetworkRequest(SocialConnectData socialConnectData)
        {
            string playerId = TTPlayerPrefs.GetValue(_keyPlayerId, "0");

            //string playerId = _gameDB.LoadSyncInfo(_keyPlayerId);

            _requestUrl = String.Format("{0}{1}{2}{3}?{4}={5}&{6}={7}&{8}={9}&{10}={11}&{12}={13}&{14}={15}",
                                        _url, _connectSocialNetworkRequestPrefix, playerId, _connectSocialNetworkRequestSuffix,
                                        _keySocialNetworkType, socialConnectData.network, _keySocialNetworkUserId, socialConnectData.userId,
                                        _keySocialNetworkToken, socialConnectData.userToken,
                                        _keySocialNetworkPlayerName, WWW.EscapeURL(socialConnectData.userName),
                                        _keySocialNetworkPlayerEmail, WWW.EscapeURL(socialConnectData.email),
                                        _keySocialNetworkPlayerImage, WWW.EscapeURL(socialConnectData.photoUrl));
        }
Пример #6
0
        public override void Execute()
        {
            CoreLogger.LogDebug("SocialServiceAuthenticateCommand", "Execute IsAuthenticated:" + socialService.IsAuthenticated + " SocialId:" + socialService.SocialId);

            if (!socialService.IsAuthenticated)
            {
                return;
            }

            SocialConnectData socialConnectData = new SocialConnectData();

            socialConnectData.userId = socialService.SocialId;
            if (Application.platform == RuntimePlatform.Android)
            {
                socialConnectData.network = SocialNetwork.PlayServices;
            }
            else
            {
                socialConnectData.network = SocialNetwork.GameCenter;
            }

            socialSync.ConnectToNetwork(socialConnectData);
        }
        public IEnumerator SendRequest(RequestType type, Action <RequestResult, string> callback, string data = "",
                                       SocialConnectData socialConnectData = null, string uploadTableName = "")
        {
            bool requestSuccess    = false;
            int  requestTriesCount = 0;

            while (!requestSuccess)
            {
                if (requestTriesCount > 0)
                {
                    yield return(new WaitForSeconds(RequestFailWaitTime));

                    Debug.Log("Request [" + type + "] failed with result [" + _requestResult + "] retrying #" + requestTriesCount);
                }

                requestTriesCount++;
                if (requestTriesCount == MaxRequestRetries)
                {
                    Debug.Log("Failed to perform request 3 times. Canceling request.");
                    break;
                }

                switch (type)
                {
                case RequestType.Login:
                    yield return(_coroutineFactory.StartCoroutine(SendLoginRequest));

                    break;

                case RequestType.GetData:
                    yield return(_coroutineFactory.StartCoroutine(SendGetDataRequest));

                    break;

                case RequestType.SyncData:
                    yield return(_coroutineFactory.StartCoroutine(() => SendSyncStateRequest(data)));

                    break;

                case RequestType.ReceiptValidation:
                    yield return(_coroutineFactory.StartCoroutine(() => SendReceiptValidationRequest(data)));

                    break;

                case RequestType.ConnectToSocialNetwork:
                    yield return(_coroutineFactory.StartCoroutine(() => SendConnectToNetworkRequest(socialConnectData)));

                    break;

                case RequestType.GetVersion:
                    yield return(_coroutineFactory.StartCoroutine(SendGetVersionRequest));

                    break;

                case RequestType.GetAvatar:
                    yield return(_coroutineFactory.StartCoroutine(() => SendGetAvatarRequest(data)));

                    break;

                case RequestType.UploadConfig:
                    if (!string.IsNullOrEmpty(uploadTableName))
                    {
                        yield return(_coroutineFactory.StartCoroutine(() => UploadConfigData(uploadTableName, data)));
                    }
                    break;

                case RequestType.GetRelationshipsScores:
                    yield return(_coroutineFactory.StartCoroutine(() => SendGetRelationshipsScoresRequest(data)));

                    break;

                case RequestType.RefreshRelationships:
                    yield return(_coroutineFactory.StartCoroutine(SendRefreshRelationshipsRequest));

                    break;

                case RequestType.PushNotificationData:
                    yield return(_coroutineFactory.StartCoroutine(() => SendGetPushTokenRequest(data)));

                    break;

                case RequestType.GetServerTime:
                    yield return(_coroutineFactory.StartCoroutine(() => SendGetServerTimeRequest()));

                    break;

                case RequestType.EventSystemRegistration:
                    yield return(_coroutineFactory.StartCoroutine(() => SendRegisterEventRequest(data)));

                    break;

                case RequestType.GetTopLeaderboardRequest:
                    yield return(_coroutineFactory.StartCoroutine(() => SendTopLeaderboardRequest(data)));

                    break;

                case RequestType.GetRankAndNeighboursRequest:
                    yield return(_coroutineFactory.StartCoroutine(() => SendRankAndNeighboursRequest(data)));

                    break;

                case RequestType.GetCountry:
                    yield return(_coroutineFactory.StartCoroutine(SendGetCountryRequest));

                    break;
                }
                if (_requestResult != RequestResult.NoInternet && _requestResult != RequestResult.CantReachServer && _requestResult != RequestResult.InternalServerError)
                {
                    requestSuccess = true;
                }
            }

            callback(_requestResult, _requestData);
        }