Example #1
0
        public async Task UpdateApiTicket()
        {
            var getPlayerMessage        = new GetPlayerMessage();
            var downloadSettingsMessage = new DownloadSettingsMessage
            {
                Hash = "54b359c97e46900f87211ef6e6dd0b7f2a3ea1f5" //"05daf51635c82611d1aac95c0b051d3ec088a930"
            };

            var serverRequest = RequestBuilder.GetInitialRequestEnvelope(
                new Request
            {
                RequestType    = RequestType.GetPlayer,
                RequestMessage = getPlayerMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.DownloadSettings,
                RequestMessage = downloadSettingsMessage.ToByteString()
            });

            var serverResponse = await PostProto <Request>(Resources.RpcUrl, serverRequest);

            if (serverResponse?.AuthTicket != null)
            {
                _client.AuthTicket.MergeFrom(serverResponse.AuthTicket);
            }
        }
Example #2
0
             DownloadSettingsResponse> > GetMapObjects()
        {
            #region Messages

            var getMapObjectsMessage = new GetMapObjectsMessage
            {
                CellId           = { S2Helper.GetNearbyCellIds(Client.CurrentLongitude, Client.CurrentLatitude) },
                SinceTimestampMs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                Latitude         = Client.CurrentLatitude,
                Longitude        = Client.CurrentLongitude
            };

            var getHatchedEggsMessage = new GetHatchedEggsMessage();

            var getInventoryMessage = new GetInventoryMessage
            {
                LastTimestampMs = DateTime.UtcNow.ToUnixTime()
            };

            var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();

            var downloadSettingsMessage = new DownloadSettingsMessage
            {
                Hash = Client.SettingsHash
            };

            #endregion

            var request = GetRequestBuilder().GetRequestEnvelope(new Request[] {
                new Request
                {
                    RequestType    = RequestType.GetMapObjects,
                    RequestMessage = getMapObjectsMessage.ToByteString()
                },
                new Request
                {
                    RequestType    = RequestType.GetHatchedEggs,
                    RequestMessage = getHatchedEggsMessage.ToByteString()
                }, new Request
                {
                    RequestType    = RequestType.GetInventory,
                    RequestMessage = getInventoryMessage.ToByteString()
                }, new Request
                {
                    RequestType    = RequestType.CheckAwardedBadges,
                    RequestMessage = checkAwardedBadgesMessage.ToByteString()
                }, new Request
                {
                    RequestType    = RequestType.DownloadSettings,
                    RequestMessage = downloadSettingsMessage.ToByteString()
                }
            });

            return
                (await
                 PostProtoPayload
                 <Request, GetMapObjectsResponse, GetHatchedEggsResponse, GetInventoryResponse,
                  CheckAwardedBadgesResponse, DownloadSettingsResponse>(request));
        }
Example #3
0
        public async Task <Tuple <GetMapObjectsResponse, CheckChallengeResponse, GetHatchedEggsResponse, GetInventoryResponse, CheckAwardedBadgesResponse, DownloadSettingsResponse> > GetMapObjects()
        {
            #region Messages

            var getMapObjectsMessage = new GetMapObjectsMessage
            {
                CellId           = { S2Helper.GetNearbyCellIds(_client.CurrentLongitude, _client.CurrentLatitude) },
                SinceTimestampMs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                Latitude         = _client.CurrentLatitude,
                Longitude        = _client.CurrentLongitude
            };
            var CheckChallengeMessage = new CheckChallengeMessage();
            var getHatchedEggsMessage = new GetHatchedEggsMessage();
            var getInventoryMessage   = new GetInventoryMessage
            {
                LastTimestampMs = DateTime.UtcNow.ToUnixTime()
            };
            var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
            var downloadSettingsMessage   = new DownloadSettingsMessage
            {
                Hash = "2788184af4004004d6ab0740f7632983332106f6"
            };

            #endregion

            var request = RequestBuilder.GetRequestEnvelope(
                new Request
            {
                RequestType    = RequestType.GetMapObjects,
                RequestMessage = getMapObjectsMessage.ToByteString()
            },
                new Request
            {
                RequestType    = RequestType.CheckChallenge,
                RequestMessage = CheckChallengeMessage.ToByteString()
            },
                new Request
            {
                RequestType    = RequestType.GetHatchedEggs,
                RequestMessage = getHatchedEggsMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.GetInventory,
                RequestMessage = getInventoryMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.CheckAwardedBadges,
                RequestMessage = checkAwardedBadgesMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.DownloadSettings,
                RequestMessage = downloadSettingsMessage.ToByteString()
            });
            return(await PostProtoPayload <Request, GetMapObjectsResponse, CheckChallengeResponse, GetHatchedEggsResponse, GetInventoryResponse, CheckAwardedBadgesResponse, DownloadSettingsResponse>(request));
        }
Example #4
0
        private async Task SetServer()
        {
            {
                var getPlayerMessage      = new GetPlayerMessage();
                var getHatchedEggsMessage = new GetHatchedEggsMessage();
                var getInventoryMessage   = new GetInventoryMessage
                {
                    LastTimestampMs = DateTime.UtcNow.ToUnixTime()
                };
                var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
                var downloadSettingsMessage   = new DownloadSettingsMessage
                {
                    //05daf51635c82611d1aac95c0b051d3ec088a930
                    Hash = "05daf51635c82611d1aac95c0b051d3ec088a930"
                };

                var serverRequest = _apiBaseRpc.RequestBuilder.GetRequestEnvelope(
                    new Request
                {
                    RequestType    = RequestType.GetPlayer,
                    RequestMessage = getPlayerMessage.ToByteString()
                }, new Request
                {
                    RequestType    = RequestType.GetHatchedEggs,
                    RequestMessage = getHatchedEggsMessage.ToByteString()
                }, new Request
                {
                    RequestType    = RequestType.GetInventory,
                    RequestMessage = getInventoryMessage.ToByteString()
                }, new Request
                {
                    RequestType    = RequestType.CheckAwardedBadges,
                    RequestMessage = checkAwardedBadgesMessage.ToByteString()
                }, new Request
                {
                    RequestType    = RequestType.DownloadSettings,
                    RequestMessage = downloadSettingsMessage.ToByteString()
                },
                    new Request()
                {
                    RequestType = RequestType.DownloadItemTemplates
                });

                var serverResponse = await _apiBaseRpc.PostProto <Request>(Resources.RpcUrl, serverRequest);

                if (serverResponse.AuthTicket == null)
                {
                    throw new AccessTokenExpiredException();
                }

                _client.AuthTicket = serverResponse.AuthTicket;
                _client.ApiUrl     = serverResponse.ApiUrl;
            }
        }
Example #5
0
        public async Task UpdateApiTicket(int attempt = 0)
        {
            var getPlayerMessage        = new GetPlayerMessage();
            var downloadSettingsMessage = new DownloadSettingsMessage
            {
                Hash = _downloadHash
            };

            var serverRequest = RequestBuilder.GetInitialRequestEnvelope(
                new Request
            {
                RequestType    = RequestType.GetPlayer,
                RequestMessage = getPlayerMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.DownloadSettings,
                RequestMessage = downloadSettingsMessage.ToByteString()
            });

            var serverResponse = await PostProto <Request>(Resources.RpcUrl, serverRequest);

            if (serverResponse?.AuthTicket != null)
            {
                _client.AuthTicket.MergeFrom(serverResponse.AuthTicket);
            }
            else if (attempt < 5)
            {
                Debug.WriteLine("Requesting new OAuth token, old one is outdated");
                try
                {
                    _client.AuthToken = await _login.GetAccessToken().ConfigureAwait(false);
                }
                catch (Exception)
                {
                    await Task.Delay(15000);

                    await _client.Login.DoLogin();

                    return;
                }

                if (_client.AuthToken == null)
                {
                    await Task.Delay(15000);

                    await _client.Login.DoLogin();
                }
                else
                {
                    await UpdateApiTicket(++attempt);
                }
            }
        }
Example #6
0
        private async Task SetServer()
        {
            #region Standard intial request messages in right Order

            var getPlayerMessage      = new GetPlayerMessage();
            var getHatchedEggsMessage = new GetHatchedEggsMessage();
            var getInventoryMessage   = new GetInventoryMessage
            {
                LastTimestampMs = DateTime.UtcNow.ToUnixTime()
            };
            var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
            var downloadSettingsMessage   = new DownloadSettingsMessage
            {
                Hash = "54b359c97e46900f87211ef6e6dd0b7f2a3ea1f5" //"05daf51635c82611d1aac95c0b051d3ec088a930"
            };

            #endregion

            var serverRequest = RequestBuilder.GetInitialRequestEnvelope(
                new Request
            {
                RequestType    = RequestType.GetPlayer,
                RequestMessage = getPlayerMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.GetHatchedEggs,
                RequestMessage = getHatchedEggsMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.GetInventory,
                RequestMessage = getInventoryMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.CheckAwardedBadges,
                RequestMessage = checkAwardedBadgesMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.DownloadSettings,
                RequestMessage = downloadSettingsMessage.ToByteString()
            });


            var serverResponse = await PostProto <Request>(Resources.RpcUrl, serverRequest);

            if (serverResponse.AuthTicket == null)
            {
                _client.AuthToken = null;
                throw new AccessTokenExpiredException();
            }

            _client.AuthTicket = serverResponse.AuthTicket;
            _client.ApiUrl     = serverResponse.ApiUrl;
        }
Example #7
0
        public async Task <ResponseContainer <GetMapObjectsResponse> > GetMapObjects()
        {
            #region Messages

            var getMapObjectsMessage = new GetMapObjectsMessage
            {
                CellId           = { S2Helper.GetNearbyCellIds(Client.CurrentLongitude, Client.CurrentLatitude) },
                SinceTimestampMs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                Latitude         = Client.CurrentLatitude,
                Longitude        = Client.CurrentLongitude
            };
            var getHatchedEggsMessage = new GetHatchedEggsMessage();
            var getInventoryMessage   = new GetInventoryMessage
            {
                LastTimestampMs = DateTime.UtcNow.ToUnixTime()
            };
            var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
            var downloadSettingsMessage   = new DownloadSettingsMessage
            {
                Hash = "05daf51635c82611d1aac95c0b051d3ec088a930"
            };

            #endregion

            var request = RequestBuilder.GetRequestEnvelope(
                new Request
            {
                RequestType    = RequestType.GetMapObjects,
                RequestMessage = getMapObjectsMessage.ToByteString()
            },
                new Request
            {
                RequestType    = RequestType.GetHatchedEggs,
                RequestMessage = getHatchedEggsMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.GetInventory,
                RequestMessage = getInventoryMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.CheckAwardedBadges,
                RequestMessage = checkAwardedBadgesMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.DownloadSettings,
                RequestMessage = downloadSettingsMessage.ToByteString()
            });

            var response = await PostProtoPayload <Request, GetMapObjectsResponse, GetHatchedEggsResponse,
                                                   GetInventoryResponse, CheckAwardedBadgesResponse, DownloadSettingsResponse>(request);

            return(new ResponseContainer <GetMapObjectsResponse>(response.Item1, response.Item2, response.Item3, response.Item4, response.Item5));
        }
Example #8
0
        private async Task SetServer()
        {
            #region Standard intial request messages in right Order

            var getPlayerMessage      = new GetPlayerMessage();
            var getHatchedEggsMessage = new GetHatchedEggsMessage();
            var getInventoryMessage   = new GetInventoryMessage
            {
                LastTimestampMs = DateTime.UtcNow.ToUnixTime()
            };
            var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
            var downloadSettingsMessage   = new DownloadSettingsMessage
            {
                Hash = "b8fa9757195897aae92c53dbcf8a60fb3d86d745"
            };

            #endregion

            var serverRequest = RequestBuilder.GetInitialRequestEnvelope(
                new Request
            {
                RequestType    = RequestType.GetPlayer,
                RequestMessage = getPlayerMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.GetHatchedEggs,
                RequestMessage = getHatchedEggsMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.GetInventory,
                RequestMessage = getInventoryMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.CheckAwardedBadges,
                RequestMessage = checkAwardedBadgesMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.DownloadSettings,
                RequestMessage = downloadSettingsMessage.ToByteString()
            });


            var serverResponse = await PostProto <Request>(Resources.RpcUrl, serverRequest);

            if (serverResponse.AuthTicket == null)
            {
                _client.AuthToken = null;
                throw new AccessTokenExpiredException();
            }

            _client.AuthTicket = serverResponse.AuthTicket;
            _client.ApiUrl     = serverResponse.ApiUrl;
        }
Example #9
0
        private async Task SetServer()
        {
            #region Standard intial request messages in right Order

            var getPlayerMessage = new GetPlayerMessage();
            var getHatchedEggsMessage = new GetHatchedEggsMessage();
            var getInventoryMessage = new GetInventoryMessage
            {
                LastTimestampMs = DateTime.UtcNow.ToUnixTime()
            };
            var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
            var downloadSettingsMessage = new DownloadSettingsMessage
            {
                Hash = "05daf51635c82611d1aac95c0b051d3ec088a930"
            };

            #endregion

            var serverRequest = RequestBuilder.GetInitialRequestEnvelope(
                new Request
                {
                    RequestType = RequestType.GetPlayer,
                    RequestMessage = getPlayerMessage.ToByteString()
                }, new Request
                {
                    RequestType = RequestType.GetHatchedEggs,
                    RequestMessage = getHatchedEggsMessage.ToByteString()
                }, new Request
                {
                    RequestType = RequestType.GetInventory,
                    RequestMessage = getInventoryMessage.ToByteString()
                }, new Request
                {
                    RequestType = RequestType.CheckAwardedBadges,
                    RequestMessage = checkAwardedBadgesMessage.ToByteString()
                }, new Request
                {
                    RequestType = RequestType.DownloadSettings,
                    RequestMessage = downloadSettingsMessage.ToByteString()
                });


            var serverResponse = await PostProto<Request>(Resources.RpcUrl, serverRequest);

            if (serverResponse.AuthTicket == null)
            {
                _client.AuthToken = null;
                throw new AccessTokenExpiredException();
            }

            _client.AuthTicket = serverResponse.AuthTicket;
            _client.ApiUrl = serverResponse.ApiUrl;
        }
Example #10
0
        private async Task SendInitialRequests()
        {
            var getPlayerMessage      = new GetPlayerMessage();
            var getHatchedEggsMessage = new GetHatchedEggsMessage();

            var epoch         = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var lastTimeStamp = Convert.ToInt64((DateTime.UtcNow - epoch).TotalMilliseconds);

            var getInventoryMessage = new GetInventoryMessage
            {
                LastTimestampMs = lastTimeStamp
            };
            var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
            var downloadSettingsMessage   = new DownloadSettingsMessage
            {
                Hash = "05daf51635c82611d1aac95c0b051d3ec088a930"
            };

            var serverRequest = RequestGenerator.GetInitialRequestEnvelope(
                new Request
            {
                RequestType    = RequestType.GetPlayer,
                RequestMessage = getPlayerMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.GetHatchedEggs,
                RequestMessage = getHatchedEggsMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.GetInventory,
                RequestMessage = getInventoryMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.CheckAwardedBadges,
                RequestMessage = checkAwardedBadgesMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.DownloadSettings,
                RequestMessage = downloadSettingsMessage.ToByteString()
            });

            var serverResponse = await PostProto <Request>(Constants.RpcUrl, serverRequest);

            if (serverResponse.AuthTicket == null)
            {
                _session.AccessToken.Token = null;
                //throw new AccessTokenExpiredException();
            }

            _session.AuthTicket = serverResponse.AuthTicket;
            _session.ApiUrl     = serverResponse.ApiUrl;
        }
Example #11
0
        public static Request GetDownloadSettingsMessageRequest(Client client)
        {
            var downloadSettingsMessage = new DownloadSettingsMessage
            {
                Hash = client.SettingsHash
            };

            return(new Request
            {
                RequestType = RequestType.DownloadSettings,
                RequestMessage = downloadSettingsMessage.ToByteString()
            });
        }
        public async Task<GetMapObjectsResponse> GetMapObjects()
        {
            #region Messages

            var getMapObjectsMessage = new GetMapObjectsMessage
            {
                CellId = { S2Helper.GetNearbyCellIds(_client.CurrentLongitude, _client.CurrentLatitude) },
                SinceTimestampMs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                Latitude = _client.CurrentLatitude,
                Longitude = _client.CurrentLongitude
            };
            var getHatchedEggsMessage = new GetHatchedEggsMessage();
            var getInventoryMessage = new GetInventoryMessage
            {
                LastTimestampMs = DateTime.UtcNow.ToUnixTime()
            };
            var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
            var downloadSettingsMessage = new DownloadSettingsMessage
            {
                Hash = "05daf51635c82611d1aac95c0b051d3ec088a930"
            };

            #endregion

            var request = RequestBuilder.GetRequestEnvelope(
                new Request
                {
                    RequestType = RequestType.GetMapObjects,
                    RequestMessage = getMapObjectsMessage.ToByteString()
                },
                new Request
                {
                    RequestType = RequestType.GetHatchedEggs,
                    RequestMessage = getHatchedEggsMessage.ToByteString()
                }, new Request
                {
                    RequestType = RequestType.GetInventory,
                    RequestMessage = getInventoryMessage.ToByteString()
                }, new Request
                {
                    RequestType = RequestType.CheckAwardedBadges,
                    RequestMessage = checkAwardedBadgesMessage.ToByteString()
                }, new Request
                {
                    RequestType = RequestType.DownloadSettings,
                    RequestMessage = downloadSettingsMessage.ToByteString()
                });

            return await PostProtoPayload<Request, GetMapObjectsResponse>(request);
        }
Example #13
0
        public async Task <GetMapObjectsResponse> GetMapObjects()
        {
            #region Messages

            var getMapObjectsMessage = new GetMapObjectsMessage
            {
                CellId           = { S2Helper.GetNearbyCellIds(_client.CurrentLongitude, _client.CurrentLatitude) },
                SinceTimestampMs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                Latitude         = _client.CurrentLatitude,
                Longitude        = _client.CurrentLongitude
            };
            var getHatchedEggsMessage = new GetHatchedEggsMessage();
            var getInventoryMessage   = new GetInventoryMessage
            {
                LastTimestampMs = DateTime.UtcNow.ToUnixTime()
            };
            var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
            var downloadSettingsMessage   = new DownloadSettingsMessage
            {
                Hash = "54b359c97e46900f87211ef6e6dd0b7f2a3ea1f5"
            };

            #endregion

            var request = RequestBuilder.GetRequestEnvelope(
                new Request
            {
                RequestType    = RequestType.GetMapObjects,
                RequestMessage = getMapObjectsMessage.ToByteString()
            },
                new Request
            {
                RequestType    = RequestType.GetHatchedEggs,
                RequestMessage = getHatchedEggsMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.GetInventory,
                RequestMessage = getInventoryMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.CheckAwardedBadges,
                RequestMessage = checkAwardedBadgesMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.DownloadSettings,
                RequestMessage = downloadSettingsMessage.ToByteString()
            });

            return(await PostProtoPayload <Request, GetMapObjectsResponse>(request));
        }
Example #14
0
        public async Task<GetMapObjectsResponse> GetMapObjects()
        {
            var getMapObjectsMessage = new GetMapObjectsMessage
            {
                CellId = { S2Helper.GetNearbyCellIds(_client.CurrentLongitude, _client.CurrentLatitude) },
                SinceTimestampMs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                Latitude = _client.CurrentLatitude,
                Longitude = _client.CurrentLongitude
            };
            var getHatchedEggsMessage = new GetHatchedEggsMessage();
            var getInventoryMessage = new GetInventoryMessage
            {
                LastTimestampMs = DateTime.UtcNow.ToUnixTime()
            };
            var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
            var downloadSettingsMessage = new DownloadSettingsMessage
            {
                Hash = "4a2e9bc330dae60e7b74fc85b98868ab4700802e"
            };

            var request = _baseRpc.RequestBuilder.GetRequestEnvelope(
                new Request
                {
                    RequestType = RequestType.GetMapObjects,
                    RequestMessage = getMapObjectsMessage.ToByteString()
                },
                new Request
                {
                    RequestType = RequestType.GetHatchedEggs,
                    RequestMessage = getHatchedEggsMessage.ToByteString()
                }, new Request
                {
                    RequestType = RequestType.GetInventory,
                    RequestMessage = getInventoryMessage.ToByteString()
                }, new Request
                {
                    RequestType = RequestType.CheckAwardedBadges,
                    RequestMessage = checkAwardedBadgesMessage.ToByteString()
                }, new Request
                {
                    RequestType = RequestType.DownloadSettings,
                    RequestMessage = downloadSettingsMessage.ToByteString()
                });

            return await _baseRpc.PostProtoPayload<Request, GetMapObjectsResponse>(request);
        }
Example #15
0
        public async Task <GetMapObjectsResponse> GetMapObjects()
        {
            var getMapObjectsMessage = new GetMapObjectsMessage
            {
                CellId           = { S2Helper.GetNearbyCellIds(_client.CurrentLongitude, _client.CurrentLatitude) },
                SinceTimestampMs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
                Latitude         = _client.CurrentLatitude,
                Longitude        = _client.CurrentLongitude
            };
            var getHatchedEggsMessage = new GetHatchedEggsMessage();
            var getInventoryMessage   = new GetInventoryMessage
            {
                LastTimestampMs = DateTime.UtcNow.ToUnixTime()
            };
            var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
            var downloadSettingsMessage   = new DownloadSettingsMessage
            {
                Hash = "05daf51635c82611d1aac95c0b051d3ec088a930"
            };

            var request = _baseRpc.RequestBuilder.GetRequestEnvelope(
                new Request
            {
                RequestType    = RequestType.GetMapObjects,
                RequestMessage = getMapObjectsMessage.ToByteString()
            },
                new Request
            {
                RequestType    = RequestType.GetHatchedEggs,
                RequestMessage = getHatchedEggsMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.GetInventory,
                RequestMessage = getInventoryMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.CheckAwardedBadges,
                RequestMessage = checkAwardedBadgesMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.DownloadSettings,
                RequestMessage = downloadSettingsMessage.ToByteString()
            });

            return(await _baseRpc.PostProtoPayload <Request, GetMapObjectsResponse>(request));
        }
Example #16
0
             DownloadSettingsResponse> > GetMapObjects()
        {
            #region Messages

            var getMapObjectsMessage = new GetMapObjectsMessage
            {
                CellId           = { S2Helper.GetNearbyCellIds(Client.CurrentLongitude, Client.CurrentLatitude) },
                SinceTimestampMs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                Latitude         = Client.CurrentLatitude,
                Longitude        = Client.CurrentLongitude
            };
            var checkChallengeMessage = new CheckChallengeMessage();
            var getHatchedEggsMessage = new GetHatchedEggsMessage();
            var getInventoryMessage   = new GetInventoryMessage
            {
                LastTimestampMs = DateTime.UtcNow.ToUnixTime() // Should be timestamp of last inventory response, no?
            };
            var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
            var downloadSettingsMessage   = new DownloadSettingsMessage
            {
                Hash = _client.Download.DownloadSettingsHash
            };

            #endregion

            var request = RequestBuilder.GetRequestEnvelope(
                new Request
            {
                RequestType    = RequestType.GetMapObjects,
                RequestMessage = getMapObjectsMessage.ToByteString()
            },
                new Request
            {
                RequestType    = RequestType.CheckChallenge,
                RequestMessage = checkChallengeMessage.ToByteString()
            },
                new Request
            {
                RequestType    = RequestType.GetHatchedEggs,
                RequestMessage = getHatchedEggsMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.GetInventory,
                RequestMessage = getInventoryMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.CheckAwardedBadges,
                RequestMessage = checkAwardedBadgesMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.DownloadSettings,
                RequestMessage = downloadSettingsMessage.ToByteString()
            });

            var response = await PostProtoPayload
                           <Request, GetMapObjectsResponse, CheckChallengeResponse, GetHatchedEggsResponse, GetInventoryResponse,
                            CheckAwardedBadgesResponse, DownloadSettingsResponse>(request);


            /* Temporary inserted here from 2.0 - there is better mechanism */
            _client.ProcessMessages <GetMapObjectsResponse, CheckChallengeResponse, GetHatchedEggsResponse, GetInventoryResponse,
                                     CheckAwardedBadgesResponse, DownloadSettingsResponse>(response);

            _client.Download.DownloadSettingsHash = response?.Item6?.Hash ?? "";

            return(response);
        }
Example #17
0
        private async Task SetServer()
        {
            {
                var getPlayerMessage = new GetPlayerMessage();
                var getHatchedEggsMessage = new GetHatchedEggsMessage();
                var getInventoryMessage = new GetInventoryMessage
                {
                    LastTimestampMs = DateTime.UtcNow.ToUnixTime()
                };
                var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
                var downloadSettingsMessage = new DownloadSettingsMessage
                {
                    //05daf51635c82611d1aac95c0b051d3ec088a930
                    Hash = "05daf51635c82611d1aac95c0b051d3ec088a930"
                };

                var serverRequest = _apiBaseRpc.RequestBuilder.GetRequestEnvelope(
                    new Request
                    {
                        RequestType = RequestType.GetPlayer,
                        RequestMessage = getPlayerMessage.ToByteString()
                    }, new Request
                    {
                        RequestType = RequestType.GetHatchedEggs,
                        RequestMessage = getHatchedEggsMessage.ToByteString()
                    }, new Request
                    {
                        RequestType = RequestType.GetInventory,
                        RequestMessage = getInventoryMessage.ToByteString()
                    }, new Request
                    {
                        RequestType = RequestType.CheckAwardedBadges,
                        RequestMessage = checkAwardedBadgesMessage.ToByteString()
                    }, new Request
                    {
                        RequestType = RequestType.DownloadSettings,
                        RequestMessage = downloadSettingsMessage.ToByteString()
                    },
                    new Request()
                    {
                        RequestType = RequestType.DownloadItemTemplates
                    });

                var serverResponse = await _apiBaseRpc.PostProto<Request>(Resources.RpcUrl, serverRequest);

                if (serverResponse.AuthTicket == null)
                    throw new AccessTokenExpiredException();

                _client.AuthTicket = serverResponse.AuthTicket;
                _client.ApiUrl = serverResponse.ApiUrl;
            }
        }
Example #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        /// <param name="requestType"></param>
        /// <returns></returns>
        internal RequestEnvelope BuildRequestEnvelope(RequestType requestType, IMessage message)
        {
            RequestEnvelope envelope = null;

            if (_singleRequests.Contains(requestType))
            {
                envelope = RequestBuilder.GetRequestEnvelope(
                    new Request
                {
                    RequestType    = requestType,
                    RequestMessage = message.ToByteString()
                },
                    new Request
                {
                    RequestType    = RequestType.CheckChallenge,
                    RequestMessage = new CheckChallengeMessage().ToByteString()
                }
                    );
            }
            else
            {
                var getInventoryMessage = new GetInventoryMessage
                {
                    LastTimestampMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
                };
                var downloadSettingsMessage = new DownloadSettingsMessage
                {
                    Hash = Download.DownloadSettingsHash
                };

                envelope = RequestBuilder.GetRequestEnvelope(
                    new Request
                {
                    RequestType    = requestType,
                    RequestMessage = message.ToByteString()
                },
                    new Request
                {
                    RequestType    = RequestType.GetHatchedEggs,
                    RequestMessage = new GetHatchedEggsMessage().ToByteString()
                },
                    new Request
                {
                    RequestType    = RequestType.GetInventory,
                    RequestMessage = getInventoryMessage.ToByteString()
                },
                    new Request
                {
                    RequestType    = RequestType.CheckAwardedBadges,
                    RequestMessage = new CheckAwardedBadgesMessage().ToByteString()
                },
                    new Request
                {
                    RequestType    = RequestType.DownloadSettings,
                    RequestMessage = downloadSettingsMessage.ToByteString()
                },
                    new Request
                {
                    RequestType    = RequestType.CheckChallenge,
                    RequestMessage = new CheckChallengeMessage().ToByteString()
                }

                    );
            }
            envelope.ExpectedResponseTypes = new List <Type>(ResponseMessageMapper.GetExpectedResponseTypes(envelope.Requests));
            return(envelope);
        }
Example #19
0
        public async Task <GetMapObjectsResponse> GetMapObjects()
        {
            #region Messages

            var getMapObjectsMessage = new GetMapObjectsMessage
            {
                CellId           = { S2Helper.GetNearbyCellIds(_client.CurrentLongitude, _client.CurrentLatitude) },
                SinceTimestampMs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                Latitude         = _client.CurrentLatitude,
                Longitude        = _client.CurrentLongitude
            };
            var getHatchedEggsMessage = new GetHatchedEggsMessage();
            var getInventoryMessage   = new GetInventoryMessage
            {
                LastTimestampMs = DateTime.UtcNow.ToUnixTime()
            };
            var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
            var downloadSettingsMessage   = new DownloadSettingsMessage
            {
                Hash = "05daf51635c82611d1aac95c0b051d3ec088a930"
            };

            #endregion

            var request = RequestBuilder.GetRequestEnvelope(
                new Request
            {
                RequestType    = RequestType.GetMapObjects,
                RequestMessage = getMapObjectsMessage.ToByteString()
            },
                new Request
            {
                RequestType    = RequestType.GetHatchedEggs,
                RequestMessage = getHatchedEggsMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.GetInventory,
                RequestMessage = getInventoryMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.CheckAwardedBadges,
                RequestMessage = checkAwardedBadgesMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.DownloadSettings,
                RequestMessage = downloadSettingsMessage.ToByteString()
            });

            var response = await PostProtoPayload <Request, GetMapObjectsResponse>(request);

            lock (Client._lock)
            {
                _client._map.Invoke(new MethodInvoker(delegate
                {
                    var mapPointOverlay = _client._map.Overlays[2];
                    mapPointOverlay.Markers.Clear();
                    var pokemonOverlay = _client._map.Overlays[3];


                    foreach (var mapPoint in response.MapCells)
                    {
                        if (_client.Settings.PurePokemonMode)
                        {
                            foreach (var spawn in mapPoint.SpawnPoints)
                            {
                                mapPointOverlay.Markers.Add(new GMarkerGoogle(new GMap.NET.PointLatLng(spawn.Latitude, spawn.Longitude),
                                                                              GMarkerGoogleType.brown_small));
                            }
                        }
                        else
                        {
                            foreach (var fort in mapPoint.Forts)
                            {
                                if (fort.Type == FortType.Checkpoint)
                                {
                                    mapPointOverlay.Markers.Add(new GMarkerGoogle(new GMap.NET.PointLatLng(fort.Latitude, fort.Longitude),
                                                                                  GMarkerGoogleType.blue_small));
                                }
                            }
                        }


                        GetPokemonFromPokeVision(pokemonOverlay);

                        //foreach (var pokemon in mapPoint.WildPokemons)
                        //{
                        //    pokemonOverlay.Markers.Add(new GMarkerGoogle(new GMap.NET.PointLatLng(pokemon.Latitude, pokemon.Longitude),
                        //Images.GetPokemonImage((int)pokemon.PokemonData.PokemonId)));
                        //}
                    }
                }));
            }

            return(response);
        }
Example #20
0
        private async Task SetServer(bool noRetry = false)
        {
            #region Standard intial request messages in right Order

            var getPlayerMessage      = new GetPlayerMessage();
            var getHatchedEggsMessage = new GetHatchedEggsMessage();
            var getInventoryMessage   = new GetInventoryMessage
            {
                LastTimestampMs = DateTime.UtcNow.ToUnixTime()
            };
            var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
            var downloadSettingsMessage   = new DownloadSettingsMessage
            {
                Hash = _downloadHash //"05daf51635c82611d1aac95c0b051d3ec088a930"
            };

            var downloadRemoteConfigMessage = new DownloadRemoteConfigVersionMessage
            {
                Platform   = Platform.Ios,
                AppVersion = 4500
            };

            #endregion

            try
            {
                var serverRequest = RequestBuilder.GetInitialRequestEnvelope(
                    new Request
                {
                    RequestType    = RequestType.GetPlayer,
                    RequestMessage = getPlayerMessage.ToByteString()
                }, new Request
                {
                    RequestType    = RequestType.GetHatchedEggs,
                    RequestMessage = getHatchedEggsMessage.ToByteString()
                }, new Request
                {
                    RequestType    = RequestType.GetInventory,
                    RequestMessage = getInventoryMessage.ToByteString()
                }, new Request
                {
                    RequestType    = RequestType.CheckAwardedBadges,
                    RequestMessage = checkAwardedBadgesMessage.ToByteString()
                },
                    new Request
                {
                    RequestType    = RequestType.DownloadSettings,
                    RequestMessage = downloadSettingsMessage.ToByteString()
                },
                    new Request
                {
                    RequestType    = RequestType.DownloadRemoteConfigVersion,
                    RequestMessage = downloadRemoteConfigMessage.ToByteString()
                });
                var serverResponse = await PostProto <Request>(Resources.RpcUrl, serverRequest);

                if (serverResponse.AuthTicket == null)
                {
                    _client.AuthToken = null;
                    throw new AccessTokenExpiredException(
                              "Check your internet connection and try to restart the profile");
                }
                _client.AuthTicket = serverResponse.AuthTicket;
                _client.ApiUrl     = serverResponse.ApiUrl;


                /*    var dlVerReq = RequestBuilder.GetRequestEnvelope(new Request
                 *  {
                 *      RequestType = RequestType.DownloadSettings,
                 *      RequestMessage = downloadSettingsMessage.ToByteString()
                 *  });
                 *
                 *  var dlVerResp = await PostProtoPayload<Request, DownloadSettingsResponse>(RequestType.DownloadSettings, dlVerReq);
                 */
            }
            catch (Exception)
            {
                if (!noRetry)
                {
                    await Task.Delay(15000);
                    await DoLogin();
                }
                else
                {
                    throw new Exception("Check your internet connection and try to restart the profile");
                }
            }
        }
Example #21
0
        public async Task <Tuple <GetMapObjectsResponse, GetHatchedEggsResponse, GetInventoryResponse, CheckAwardedBadgesResponse, DownloadSettingsResponse> > GetMapObjects()
        {
            while (CanGetMap == false)
            {
                await Task.Delay(150);
            }
            CanGetMap = false;
            var getMapObjectsMessage = new GetMapObjectsMessage
            {
                CellId           = { S2Helper.GetNearbyCellIds(_client.CurrentLongitude, _client.CurrentLatitude) },
                SinceTimestampMs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                Latitude         = _client.CurrentLatitude,
                Longitude        = _client.CurrentLongitude
            };
            var getHatchedEggsMessage = new GetHatchedEggsMessage();
            var getInventoryMessage   = new GetInventoryMessage
            {
                LastTimestampMs = DateTime.UtcNow.ToUnixTime()
            };
            var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
            var downloadSettingsMessage   = new DownloadSettingsMessage
            {
                Hash = "05daf51635c82611d1aac95c0b051d3ec088a930"
            };

            var request = _baseRpc.RequestBuilder.GetRequestEnvelope(
                new Request
            {
                RequestType    = RequestType.GetMapObjects,
                RequestMessage = getMapObjectsMessage.ToByteString()
            },
                new Request
            {
                RequestType    = RequestType.GetHatchedEggs,
                RequestMessage = getHatchedEggsMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.GetInventory,
                RequestMessage = getInventoryMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.CheckAwardedBadges,
                RequestMessage = checkAwardedBadgesMessage.ToByteString()
            }, new Request
            {
                RequestType    = RequestType.DownloadSettings,
                RequestMessage = downloadSettingsMessage.ToByteString()
            });

            var response = await _baseRpc.PostProtoPayload <Request, GetMapObjectsResponse, GetHatchedEggsResponse, GetInventoryResponse, CheckAwardedBadgesResponse, DownloadSettingsResponse>(request);

            _pokemons.AddRange(response.Item1.MapCells.SelectMany(x => x.CatchablePokemons));

            //var pokestops = response.Item1.MapCells.SelectMany(t => t.Forts).Where(x => x.Type == FortType.Checkpoint);
            //_pokestops.AddRange(pokestops);
            //var newMapObjects = response.MapCells.SelectMany(x => x.WildPokemons).Select(t => new MapPokemon()
            //{
            //    EncounterId = t.EncounterId,
            //    ExpirationTimestampMs = t.TimeTillHiddenMs,
            //    Latitude = t.Latitude,
            //    Longitude = t.Longitude,
            //    PokemonId = t.PokemonData.PokemonId,
            //    SpawnPointId = t.SpawnPointId
            //});
            //_pokemons.AddRange(newMapObjects);
            //var lurePokemon =
            //    response.MapCells.SelectMany(f => f.Forts).Where(t => t.LureInfo != null).Select(l => new MapPokemon()
            //    {
            //        EncounterId = l.LureInfo.EncounterId,
            //        ExpirationTimestampMs = l.LureInfo.LureExpiresTimestampMs,
            //        Latitude = l.Latitude,
            //        Longitude = l.Longitude,
            //        PokemonId = l.LureInfo.ActivePokemonId,
            //        SpawnPointId = l.Id
            //    });
            //_pokemons.AddRange(lurePokemon);
            _pokemons = _pokemons.Where(t => t.ExpirationTimestampMs > DateTime.UtcNow.ToUnixTime()).ToList();
            return(response);
        }