Esempio n. 1
0
        public static void Parse(Client client, RequestType requestType, ByteString data)
        {
            try
            {
                switch (requestType)
                {
                case RequestType.GetInventory:
                    var getInventoryResponse = new GetInventoryResponse();
                    getInventoryResponse.MergeFrom(data);
                    ProcessGetInventoryResponse(client, getInventoryResponse);
                    break;

                case RequestType.DownloadSettings:
                    //TODO Update settings
                    //api.getSettings().updateSettings(DownloadSettingsResponse.parseFrom(data));
                    // Update settings hash
                    var downloadSettingsResponse = new DownloadSettingsResponse();
                    downloadSettingsResponse.MergeFrom(data);
                    client.SettingsHash = downloadSettingsResponse.Hash;

                    break;
                }
            }
            catch (InvalidProtocolBufferException e)
            {
                throw e;
            }
        }
Esempio n. 2
0
        private async Task FireRequestBlock(Request request)
        {
            var requests = CommonRequest.FillRequest(request, Client);

            var serverRequest = await GetRequestBuilder().GetRequestEnvelope(requests);

            var serverResponse = await PostProto <Request>(serverRequest);

            var responses = serverResponse.Returns;

            if (responses != null)
            {
                var checkChallengeResponse = new CheckChallengeResponse();
                if (2 <= responses.Count)
                {
                    checkChallengeResponse.MergeFrom(responses[1]);

                    CommonRequest.ProcessCheckChallengeResponse(Client, checkChallengeResponse);
                }

                var getInventoryResponse = new GetInventoryResponse();
                if (4 <= responses.Count)
                {
                    getInventoryResponse.MergeFrom(responses[3]);

                    CommonRequest.ProcessGetInventoryResponse(Client, getInventoryResponse);
                }

                var downloadSettingsResponse = new DownloadSettingsResponse();
                if (6 <= responses.Count)
                {
                    downloadSettingsResponse.MergeFrom(responses[5]);

                    CommonRequest.ProcessDownloadSettingsResponse(Client, downloadSettingsResponse);
                }
            }
        }
Esempio n. 3
0
        private async Task FireRequestBlock(Request request)
        {
            var requests = CommonRequest.FillRequest(request, Client);

            var serverRequest  = GetRequestBuilder().GetRequestEnvelope(requests, true);
            var serverResponse = await PostProto <Request>(serverRequest);

            if (!string.IsNullOrEmpty(serverResponse.ApiUrl))
            {
                Client.ApiUrl = "https://" + serverResponse.ApiUrl + "/rpc";
            }

            if (serverResponse.AuthTicket != null)
            {
                Client.AuthTicket = serverResponse.AuthTicket;
            }

            switch (serverResponse.StatusCode)
            {
            case ResponseEnvelope.Types.StatusCode.InvalidAuthToken:
                Client.AuthToken = null;
                throw new AccessTokenExpiredException();

            case ResponseEnvelope.Types.StatusCode.Redirect:
                // 53 means that the api_endpoint was not correctly set, should be at this point, though, so redo the request
                await FireRequestBlock(request);

                return;

            case ResponseEnvelope.Types.StatusCode.BadRequest:
                // Your account may be banned! please try from the official client.
                throw new LoginFailedException("Your account may be banned! please try from the official client.");

            case ResponseEnvelope.Types.StatusCode.Unknown:
                break;

            case ResponseEnvelope.Types.StatusCode.Ok:
                break;

            case ResponseEnvelope.Types.StatusCode.OkRpcUrlInResponse:
                break;

            case ResponseEnvelope.Types.StatusCode.InvalidRequest:
                break;

            case ResponseEnvelope.Types.StatusCode.InvalidPlatformRequest:
                break;

            case ResponseEnvelope.Types.StatusCode.SessionInvalidated:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var responses = serverResponse.Returns;

            if (responses != null)
            {
                var getInventoryResponse = new GetInventoryResponse();
                if (4 <= responses.Count)
                {
                    getInventoryResponse.MergeFrom(responses[3]);

                    Client.InventoryLastUpdateTimestamp = Utils.GetTime(true);
                }

                var downloadSettingsResponse = new DownloadSettingsResponse();
                if (6 <= responses.Count)
                {
                    downloadSettingsResponse.MergeFrom(responses[5]);

                    Client.SettingsHash = downloadSettingsResponse.Hash;
                }
            }
        }
Esempio n. 4
0
        public static void ProcessCommonResponses(Client client, RepeatedField <ByteString> responses, bool processBuddyWalked = true, bool processInBox = true)
        {
            if (responses != null)
            {
                var checkChallengeResponse = new CheckChallengeResponse();
                if (responses.Count > 1)
                {
                    checkChallengeResponse.MergeFrom(responses[1]);
                    CommonRequest.ProcessCheckChallengeResponse(client, checkChallengeResponse);
                }

                var getHatchedEggsResponse = new GetHatchedEggsResponse();
                if (responses.Count > 2)
                {
                    getHatchedEggsResponse.MergeFrom(responses[2]);
                    CommonRequest.ProcessGetHatchedEggsResponse(client, getHatchedEggsResponse);
                }

                var getInventoryResponse = new GetInventoryResponse();
                if (responses.Count > 3)
                {
                    getInventoryResponse.MergeFrom(responses[3]);
                    CommonRequest.ProcessGetInventoryResponse(client, getInventoryResponse);
                }

                var checkAwardedBadgesResponse = new CheckAwardedBadgesResponse();
                if (responses.Count > 4)
                {
                    checkAwardedBadgesResponse.MergeFrom(responses[4]);
                    CommonRequest.ProcessCheckAwardedBadgesResponse(client, checkAwardedBadgesResponse);
                }

                var downloadSettingsResponse = new DownloadSettingsResponse();
                if (responses.Count > 5)
                {
                    downloadSettingsResponse.MergeFrom(responses[5]);
                    CommonRequest.ProcessDownloadSettingsResponse(client, downloadSettingsResponse);
                }
                var index = 5;
                if (processBuddyWalked)
                {
                    index++;
                    var getBuddyWalkedResponse = new GetBuddyWalkedResponse();
                    if (responses.Count > index)
                    {
                        getBuddyWalkedResponse.MergeFrom(responses[index]);
                        CommonRequest.ProcessGetBuddyWalkedResponse(client, getBuddyWalkedResponse);
                    }
                }
                if (processInBox)
                {
                    index++;
                    var getInboxResponse = new GetInboxResponse();

                    if (responses.Count > index)
                    {
                        getInboxResponse.MergeFrom(responses[index]);
                        CommonRequest.ProcessGetInboxResponse(client, getInboxResponse);
                    }
                }
            }
        }
Esempio n. 5
0
        public async Task FireRequestBlock(Request request)
        {
            var requests = CommonRequest.FillRequest(request, Client);

            RequestBuilder ll = new RequestBuilder(Client, Client.AuthToken, Client.AuthType, Client.CurrentLatitude, Client.CurrentLongitude, Client.CurrentAltitude);

            //var player = Client.Player.GetPlayer();

            var serverRequest  = GetRequestBuilder().GetRequestEnvelope(requests, true);
            var serverResponse = await PostProto <Request>(serverRequest).ConfigureAwait(false);

            if (!string.IsNullOrEmpty(serverResponse.ApiUrl))
            {
                Client.ApiUrl = "https://" + serverResponse.ApiUrl + "/rpc";
            }

            if (serverResponse.AuthTicket != null)
            {
                Client.AuthTicket = serverResponse.AuthTicket;
            }

            switch (serverResponse.StatusCode)
            {
            case ResponseEnvelope.Types.StatusCode.InvalidAuthToken:
                Client.AuthToken = null;
                throw new AccessTokenExpiredException();

            case ResponseEnvelope.Types.StatusCode.Redirect:
                // 53 means that the api_endpoint was not correctly set, should be at this point, though, so redo the request
                await FireRequestBlock(request).ConfigureAwait(false);

                return;

            case ResponseEnvelope.Types.StatusCode.BadRequest:
                // Your account may be banned! please try from the official client.
                throw new LoginFailedException("Your account may be banned! please try from the official client.");

            case ResponseEnvelope.Types.StatusCode.Unknown:
                break;

            case ResponseEnvelope.Types.StatusCode.Ok:
                break;

            case ResponseEnvelope.Types.StatusCode.OkRpcUrlInResponse:
                break;

            case ResponseEnvelope.Types.StatusCode.InvalidRequest:
                break;

            case ResponseEnvelope.Types.StatusCode.InvalidPlatformRequest:
                break;

            case ResponseEnvelope.Types.StatusCode.SessionInvalidated:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var responses = serverResponse.Returns;

            if (responses != null)
            {
                var checkChallengeResponse = new CheckChallengeResponse();
                if (2 <= responses.Count)
                {
                    checkChallengeResponse.MergeFrom(responses[1]);

                    CommonRequest.ProcessCheckChallengeResponse(Client, checkChallengeResponse);
                }

                var getInventoryResponse = new GetInventoryResponse();
                if (4 <= responses.Count)
                {
                    getInventoryResponse.MergeFrom(responses[3]);

                    CommonRequest.ProcessGetInventoryResponse(Client, getInventoryResponse);
                }

                var downloadSettingsResponse = new DownloadSettingsResponse();
                if (6 <= responses.Count)
                {
                    downloadSettingsResponse.MergeFrom(responses[5]);

                    CommonRequest.ProcessDownloadSettingsResponse(Client, downloadSettingsResponse);
                }
            }
        }