/// <summary> /// Generates a few random <see cref="LocationFix"/>es to act like a real GPS sensor. /// </summary> /// <param name="requestEnvelope">The <see cref="RequestEnvelope"/> these <see cref="LocationFix"/>es are used for.</param> /// <param name="timestampSinceStart">The milliseconds passed since starting the <see cref="Session"/> used by the current <see cref="RequestEnvelope"/>.</param> /// <returns></returns> private List <LocationFix> BuildLocationFixes(RequestEnvelope requestEnvelope, long timestampSinceStart) { var locationFixes = new List <LocationFix>(); if (requestEnvelope.Requests.Count == 0 || requestEnvelope.Requests[0] == null) { return(locationFixes); } var providerCount = _session.Random.Next(4, 10); for (var i = 0; i < providerCount; i++) { var timestampSnapshot = timestampSinceStart + (150 * (i + 1) + _session.Random.Next(250 * (i + 1) - 150 * (i + 1))); if (timestampSnapshot >= timestampSinceStart) { if (locationFixes.Count != 0) { break; } timestampSnapshot = timestampSinceStart - _session.Random.Next(20, 50); if (timestampSnapshot < 0) { timestampSnapshot = 0; } } locationFixes.Insert(0, new LocationFix { TimestampSnapshot = (ulong)timestampSnapshot, Latitude = LocationUtil.OffsetLatitudeLongitude(_session.Player.Coordinate.Latitude, _session.Random.Next(100) + 10), Longitude = LocationUtil.OffsetLatitudeLongitude(_session.Player.Coordinate.Longitude, _session.Random.Next(100) + 10), HorizontalAccuracy = (float)_session.Random.NextDouble(5.0, 25.0), VerticalAccuracy = (float)_session.Random.NextDouble(5.0, 25.0), Altitude = (float)_session.Random.NextDouble(10.0, 30.0), Provider = "fused", ProviderStatus = 3, LocationType = 1, // Speed = ?, Course = -1, // Floor = 0 }); } return(locationFixes); }
/// <summary> /// Generates a few random <see cref="LocationFix"/>es to act like a real GPS sensor. /// </summary> /// <param name="requestEnvelope">The <see cref="RequestEnvelope"/> these <see cref="LocationFix"/>es are used for.</param> /// <param name="timestampSinceStart">The milliseconds passed since starting the <see cref="Session"/> used by the current <see cref="RequestEnvelope"/>.</param> /// <returns></returns> private List <LocationFix> BuildLocationFixes(RequestEnvelope requestEnvelope, long timestampSinceStart) { var locationFixes = new List <LocationFix>(); try { if (requestEnvelope.Requests.Count == 0 || requestEnvelope.Requests[0] == null) { return(locationFixes); } // Determine amount of location fixes. // We look for the amount of seconds that have passed since the last location fixes request. // If that results in 0, send 1 location fix. var millisecondsPerFix = _session.Random.Next(995, 999); var providerCount = Math.Min((timestampSinceStart - _lastTimestampSinceStart) / millisecondsPerFix, _session.Random.Next(8, 11)); if (providerCount == 0) { providerCount = 1; } // Determine size of the "play around" window. // Not so relevant when starting up. var totalMilliseconds = providerCount * millisecondsPerFix; var baseTimestampSnapshot = Math.Max(timestampSinceStart - totalMilliseconds, 0); var playAroundWindow = baseTimestampSnapshot - _lastTimestampSinceStart; if (playAroundWindow == 0 && providerCount == 1 && millisecondsPerFix >= timestampSinceStart) { // We really need an offset for this one.. playAroundWindow = _session.Random.Next(0, (int)timestampSinceStart); } else { // A small offset between location fixes. playAroundWindow = Math.Min(playAroundWindow, providerCount * 2); } // Share "play around" window over all location fixes. var playAroundWindowPart = playAroundWindow != 0 ? playAroundWindow / providerCount : 1; for (var i = 0; i < providerCount; i++) { var timestampSnapshot = baseTimestampSnapshot; // Apply current location fix position. timestampSnapshot += i * millisecondsPerFix; // Apply an offset. timestampSnapshot += _session.Random.Next(0, (int)((i + 1) * Math.Abs(playAroundWindowPart))); locationFixes.Add(new LocationFix { TimestampSnapshot = (ulong)timestampSnapshot, Latitude = LocationUtil.OffsetLatitudeLongitude(_session.Player.Coordinate.Latitude, _session.Random.Next(100) + 10), Longitude = LocationUtil.OffsetLatitudeLongitude(_session.Player.Coordinate.Longitude, _session.Random.Next(100) + 10), HorizontalAccuracy = (float)_session.Random.NextDouble(5.0, 25.0), VerticalAccuracy = (float)_session.Random.NextDouble(5.0, 25.0), Altitude = (float)_session.Random.NextDouble(10.0, 30.0), Provider = "fused", ProviderStatus = 3, LocationType = 1, Course = -1, Speed = -1 // Floor = 0 }); } _lastTimestampSinceStart = timestampSinceStart; } catch (Exception ex) { } return(locationFixes); }