public async Task <RequestEnvelope> GetRequestEnvelope(IEnumerable <Request> customRequests) { // Save the location var currentLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude); currentLocation.Latitude = Math.Round(currentLocation.Latitude, GEOLOCATION_PRECISION); currentLocation.Longitude = Math.Round(currentLocation.Longitude, GEOLOCATION_PRECISION); currentLocation.Altitude = Math.Round(currentLocation.Altitude, GEOLOCATION_PRECISION); var e = new RequestEnvelope { StatusCode = 2, //1 RequestId = (ulong)GetNextRequestId(), //3 Latitude = currentLocation.Latitude, //7 Longitude = currentLocation.Longitude, //8 Accuracy = TRandomDevice.Choice(new List <int>(new int[] { 5, 5, 5, 5, 10, 10, 10, 30, 30, 50, 65, TRandomDevice.Next(66, 80) })), //9 MsSinceLastLocationfix = (long)TRandomDevice.Triangular(300, 30000, 10000) //12 }; e.Requests.AddRange(customRequests); if (_client.AuthTicket != null) { e.AuthTicket = _client.AuthTicket; } else { var accessToken = await _client.Login.GetValidAccessToken().ConfigureAwait(false); e.AuthInfo = new RequestEnvelope.Types.AuthInfo { Provider = accessToken.ProviderID, Token = new RequestEnvelope.Types.AuthInfo.Types.JWT { Contents = accessToken.Token, Unknown2 = (accessToken.ProviderID == "ptc") ? TRandomDevice.Choice(new List <int>(new int[] { 0, 21, 28, 28, 56, 59, 59, 59 })) : 0 } }; } if (_client.AppVersion > 4500) { // Only add UnknownPtr8Request if not using the legacy API. // Chat with SLxTnT - this is required for all request and needed before the main envelope. //if(customRequests.Any(x=>x.RequestType == RequestType.GetMapObjects || x.RequestType == RequestType.GetPlayer)) var plat8Message = new UnknownPtr8Request() { Message = _client.UnknownPlat8Field }; e.PlatformRequests.Add(new RequestEnvelope.Types.PlatformRequest() { Type = PlatformRequestType.UnknownPtr8, RequestMessage = plat8Message.ToByteString() }); } e.PlatformRequests.Add(await GenerateSignature(e, currentLocation).ConfigureAwait(false)); return(e); }
public RequestEnvelope GetRequestEnvelope(Request[] customRequests, bool firstRequest = false) { var _requestEnvelope = new RequestEnvelope { StatusCode = 2, //1 RequestId = _requestBuilderID.Next(), //3 Requests = { customRequests }, //4 Latitude = _latitude, //7 Longitude = _longitude, //8 Accuracy = _altitude, //9 AuthTicket = _authTicket, //11 MsSinceLastLocationfix = (long)TRandomDevice.Triangular(300, 30000, 10000) //12 }; if (_authTicket != null && !firstRequest) { _requestEnvelope.AuthTicket = _authTicket; } else { _requestEnvelope.AuthInfo = new RequestEnvelope.Types.AuthInfo { Provider = _authType == AuthType.Google ? "google" : "ptc", Token = new RequestEnvelope.Types.AuthInfo.Types.JWT { Contents = _authToken, Unknown2 = _token2 } }; } //Logger.Debug("GetRequestEnvelope"); //Logger.Debug("_requestEnvelope"+ _requestEnvelope); _requestEnvelope.PlatformRequests.Add(GenerateSignature(_requestEnvelope)); if (customRequests.Length > 0 && (customRequests[0].RequestType == RequestType.GetPlayer || customRequests[0].RequestType == RequestType.GetMapObjects) && !string.IsNullOrEmpty(Resources.Api.UnknownPtr8Message) ) { var plat8Message = new UnknownPtr8Request() { Message = Resources.Api.UnknownPtr8Message }; _requestEnvelope.PlatformRequests.Add(new RequestEnvelope.Types.PlatformRequest() { Type = PlatformRequestType.UnknownPtr8, RequestMessage = plat8Message.ToByteString() }); /*_requestEnvelope.Requests.Add(new Request * { * RequestType = RequestType.GetInbox, * RequestMessage = new GetInboxMessage { }.ToByteString() * });*/ } return(_requestEnvelope); }
public RequestEnvelope GetRequestEnvelope(Request[] customRequests, bool firstRequest = false) { var _requestEnvelope = new RequestEnvelope { StatusCode = 2, //1 RequestId = _requestBuilderID.Next(), //3 Requests = { customRequests }, //4 Latitude = _latitude, //7 Longitude = _longitude, //8 Accuracy = _altitude, //9 AuthTicket = _authTicket, //11 MsSinceLastLocationfix = (long)TRandomDevice.Triangular(300, 30000, 10000) //12 }; var randValue = TRandomDevice.Next(1, 100); var insertUnknptr8 = (randValue != 1); // insert it 99 times of each 100 times if (customRequests.Length > 0) { if (customRequests[0].RequestType != RequestType.GetPlayer && customRequests[0].RequestType != RequestType.GetMapObjects) { insertUnknptr8 = (randValue == 1); // insert it 1 time of each 100 times } } if (insertUnknptr8) { var plat8Message = new UnknownPtr8Request() { Message = Resources.Api.UnknownPtr8Message }; _requestEnvelope.PlatformRequests.Add(new RequestEnvelope.Types.PlatformRequest() { Type = PlatformRequestType.UnknownPtr8, RequestMessage = plat8Message.ToByteString() }); } if (_authTicket != null && !firstRequest) { _requestEnvelope.AuthTicket = _authTicket; } else { _requestEnvelope.AuthInfo = new RequestEnvelope.Types.AuthInfo { Provider = _authType == AuthType.Google ? "google" : "ptc", Token = new RequestEnvelope.Types.AuthInfo.Types.JWT { Contents = _authToken, Unknown2 = _token2 } }; } _requestEnvelope.PlatformRequests.Add(GenerateSignature(_requestEnvelope)); return(_requestEnvelope); }
public async Task RegenerateRequestEnvelopeWithNewAccessToken(RequestEnvelope requestEnvelope) { var accessToken = await _client.Login.GetValidAccessToken(true /* force refresh */).ConfigureAwait(false); requestEnvelope.AuthTicket = null; requestEnvelope.AuthInfo = new RequestEnvelope.Types.AuthInfo { Provider = accessToken.ProviderID, Token = new RequestEnvelope.Types.AuthInfo.Types.JWT { Contents = accessToken.Token, Unknown2 = (accessToken.ProviderID == "ptc") ? TRandomDevice.Choice(new List <int>(new int[] { 2, 8, 21, 21, 21, 28, 37, 56, 59, 59, 59 })) : 59 } }; requestEnvelope.PlatformRequests.Clear(); if (_client.AppVersion > 4500) { // Only add UnknownPtr8Request if not using the legacy API. // Chat with SLxTnT - this is required for all request and needed before the main envelope. //if(customRequests.Any(x=>x.RequestType == RequestType.GetMapObjects || x.RequestType == RequestType.GetPlayer)) var plat8Message = new UnknownPtr8Request() { Message = _client.UnknownPlat8Field }; requestEnvelope.PlatformRequests.Add(new RequestEnvelope.Types.PlatformRequest() { Type = PlatformRequestType.UnknownPtr8, RequestMessage = plat8Message.ToByteString() }); } if (requestEnvelope.Requests.Count > 0) { requestEnvelope.Requests.Add(new Request { RequestType = RequestType.GetInbox, RequestMessage = new GetInboxMessage { IsHistory = true }.ToByteString() }); } var currentLocation = new GeoCoordinate(requestEnvelope.Latitude, requestEnvelope.Longitude, _client.CurrentAltitude); requestEnvelope.PlatformRequests.Add(await GenerateSignature(requestEnvelope, currentLocation).ConfigureAwait(false)); }