Exemplo n.º 1
0
 def course(self):
     self._course = triangular(0, 359.99, self._course)
     return self._course
Exemplo n.º 2
0
    async def _build_main_request(self, subrequests, subplatforms, player_position, device_info=None):
        self.log.debug('Generating main RPC request...')

        request = RequestEnvelope()
        request.status_code = 2

        request.request_id = self.request_id

        # 5: 43%, 10: 30%, 30: 5%, 50: 4%, 65: 10%, 200: 1%, float: 7%
        request.accuracy = choose_weighted(
            (5, 10, 30, 50, 65, 200, -1),
            (43, 73, 78, 82, 92, 93, 100))
        if request.accuracy == -1:
            request.accuracy = uniform(65, 200)

        request.latitude, request.longitude, altitude = player_position

        # generate sub requests before SignalLog generation
        request = self._build_sub_requests(request, subrequests, subplatforms)

        if self._auth_provider.check_ticket():
            self.log.debug(
                'Found Session Ticket - using this instead of oauth token')
            request.auth_ticket.expire_timestamp_ms, request.auth_ticket.start, request.auth_ticket.end = self._auth_provider.get_ticket()
            ticket_serialized = request.auth_ticket.SerializeToString()
        else:
            self.log.debug(
                'No Session Ticket found - using OAUTH Access Token')
            request.auth_info.provider = self._auth_provider.provider
            request.auth_info.token.contents = await self._auth_provider.get_access_token()

            # 59: 50%, others: 5% each
            request.auth_info.token.unknown2 = choose_weighted(
                (4, 19, 22, 26, 30, 44, 45, 50, 57, 58, 59),
                (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20))
            # Sig uses this when no auth_ticket available
            ticket_serialized = request.auth_info.SerializeToString()

        sig = SignalLog()

        sig.field22 = self.state.session_hash
        sig.epoch_timestamp_ms = get_time_ms()
        if not self.state.start_time:
            self.state.start_time = sig.epoch_timestamp_ms - randint(6000, 10000)
        sig.timestamp_ms_since_start = sig.epoch_timestamp_ms - self.state.start_time

        hash_engine = HashServer()
        hashing = HashServer.loop.create_task(
            hash_engine.hash(
                sig.epoch_timestamp_ms,
                request.latitude,
                request.longitude,
                request.accuracy,
                ticket_serialized,
                sig.field22,
                request.requests))

        loc = sig.location_updates.add()
        sen = sig.sensor_updates.add()

        sen.timestamp = sig.timestamp_ms_since_start - triangular_int(93, 4900, 3000)
        loc.timestamp_ms = sig.timestamp_ms_since_start - triangular_int(320, 3000, 1000)

        loc.name = 'fused'
        loc.latitude = request.latitude
        loc.longitude = request.longitude

        loc.altitude = altitude or uniform(150, 250)

        if random() > .85:
            # no reading for roughly 1 in 7 updates
            loc.device_course = -1
            loc.device_speed = -1
        else:
            loc.device_course = self.state.course
            loc.device_speed = triangular(0.25, 9.7, 8.2)

        loc.provider_status = 3
        loc.location_type = 1
        if isinstance(request.accuracy, float):
            loc.horizontal_accuracy = choose_weighted(
                (request.accuracy, 65, 200), (50, 90, 100))
            loc.vertical_accuracy = choose_weighted(
                (-1, 10, 12, 16, 24, 32, 48, 96),
                (50, 84, 89, 92, 96, 98, 99, 100))
        else:
            loc.horizontal_accuracy = request.accuracy
            if request.accuracy >= 10:
                loc.vertical_accuracy = choose_weighted(
                    (6, 8, 10, 12, 16, 24, 32, 48),
                    (4, 38, 73, 84, 88, 96, 99, 100))
            else:
                loc.vertical_accuracy = choose_weighted(
                    (3, 4, 6, 8, 10, 12),
                    (15, 54, 68, 81, 95, 100))

        if loc.vertical_accuracy == -1:
            loc.vertical_accuracy = uniform(10, 96)

        sen.acceleration_x = triangular(-1.5, 2.5, 0)
        sen.acceleration_y = triangular(-1.2, 1.4, 0)
        sen.acceleration_z = triangular(-1.4, .9, 0)
        sen.magnetic_field_accuracy = choose_weighted(
            (-1, 0, 1, 2),
            (8, 10, 52, 100))
        if sen.magnetic_field_accuracy == -1:
            sen.magnetic_field_x = 0
            sen.magnetic_field_y = 0
            sen.magnetic_field_z = 0
        else:
            sen.magnetic_field_x = self.state.magnetic_field_x
            sen.magnetic_field_y = self.state.magnetic_field_y
            sen.magnetic_field_z = self.state.magnetic_field_z

        sen.attitude_pitch = triangular(-1.56, 1.57, 0.475)
        sen.attitude_yaw = triangular(-1.56, 3.14, .1)
        sen.attitude_roll = triangular(-3.14, 3.14, 0)
        sen.rotation_rate_x = triangular(-3.2, 3.52, 0)
        sen.rotation_rate_y = triangular(-3.1, 4.88, 0)
        sen.rotation_rate_z = triangular(-6, 3.7, 0)
        sen.gravity_x = triangular(-1, 1, 0.01)
        sen.gravity_y = triangular(-1, 1, -.4)
        sen.gravity_z = triangular(-1, 1, -.4)
        sen.status = 3

        sig.version_hash = -960786418476827155

        try:
            for key, value in device_info.items():
                setattr(sig.device_info, key, value)
        except AttributeError:
            pass
        sig.ios_device_info.bool5 = True

        try:
            rtype = request.requests[0].request_type
        except (IndexError, AttributeError):
            pass
        else:
            randval = random()
            # GetMapObjects or GetPlayer: 50%
            # Encounter: 10%
            # Others: 3%
            if ((rtype in (2, 106) and randval > 0.5)
                    or (rtype == 102 and randval > 0.9)
                    or randval > 0.97):
                plat8 = PlatEightRequest()
                if self.state.message8:
                    plat8.field1 = self.state.message8
                plat = request.platform_requests.add()
                plat.type = 8
                plat.request_message = plat8.SerializeToString()

        sig.location_hash, sig.location_hash_by_token_seed, rh = await hashing
        sig.request_hashes.extend(rh)
        sig_request = SendEncryptedSignatureRequest()
        sig_request.encrypted_signature = pycrypt(
            sig.SerializeToString(), sig.timestamp_ms_since_start)

        plat = request.platform_requests.add()
        plat.type = 6
        plat.request_message = sig_request.SerializeToString()

        request.ms_since_last_locationfix = sig.timestamp_ms_since_start - loc.timestamp_ms

        self.log.debug('Generated protobuf request: \n\r%s', request)
        return request
Exemplo n.º 3
0
    async def _build_main_request(self,
                                  subrequests,
                                  subplatforms,
                                  player_position,
                                  device_info=None):
        self.log.debug('Generating main RPC request...')

        request = RequestEnvelope()
        request.status_code = 2

        request.request_id = self.request_id

        # 5: 43%, 10: 30%, 30: 5%, 50: 4%, 65: 10%, 200: 1%, float: 7%
        request.accuracy = choose_weighted((5, 10, 30, 50, 65, 200, -1),
                                           (43, 73, 78, 82, 92, 93, 100))
        if request.accuracy == -1:
            request.accuracy = uniform(65, 200)

        request.latitude, request.longitude, altitude = player_position

        # generate sub requests before SignalLog generation
        request = self._build_sub_requests(request, subrequests, subplatforms)

        if self._auth_provider.check_ticket():
            self.log.debug(
                'Found Session Ticket - using this instead of oauth token')
            request.auth_ticket.expire_timestamp_ms, request.auth_ticket.start, request.auth_ticket.end = self._auth_provider.get_ticket(
            )
            ticket_serialized = request.auth_ticket.SerializeToString()
        else:
            self.log.debug(
                'No Session Ticket found - using OAUTH Access Token')
            request.auth_info.provider = self._auth_provider.provider
            request.auth_info.token.contents = await self._auth_provider.get_access_token(
            )

            # 59: 50%, others: 5% each
            request.auth_info.token.unknown2 = choose_weighted(
                (4, 19, 22, 26, 30, 44, 45, 50, 57, 58, 59),
                (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20))
            # Sig uses this when no auth_ticket available
            ticket_serialized = request.auth_info.SerializeToString()

        sig = SignalLog()

        sig.field22 = self.state.session_hash
        sig.epoch_timestamp_ms = get_time_ms()
        if not self.state.start_time:
            self.state.start_time = sig.epoch_timestamp_ms - randint(
                6000, 10000)
        sig.timestamp_ms_since_start = sig.epoch_timestamp_ms - self.state.start_time

        hash_engine = HashServer()
        hashing = HashServer.loop.create_task(
            hash_engine.hash(sig.epoch_timestamp_ms, request.latitude,
                             request.longitude, request.accuracy,
                             ticket_serialized, sig.field22, request.requests))

        loc = sig.location_updates.add()
        sen = sig.sensor_updates.add()

        sen.timestamp = sig.timestamp_ms_since_start - triangular_int(
            93, 4900, 3000)
        loc.timestamp_ms = sig.timestamp_ms_since_start - triangular_int(
            320, 3000, 1000)

        loc.name = 'fused'
        loc.latitude = request.latitude
        loc.longitude = request.longitude

        loc.altitude = altitude or uniform(150, 250)

        if random() > .85:
            # no reading for roughly 1 in 7 updates
            loc.device_course = -1
            loc.device_speed = -1
        else:
            loc.device_course = self.state.course
            loc.device_speed = triangular(0.25, 9.7, 8.2)

        loc.provider_status = 3
        loc.location_type = 1
        if isinstance(request.accuracy, float):
            loc.horizontal_accuracy = choose_weighted(
                (request.accuracy, 65, 200), (50, 90, 100))
            loc.vertical_accuracy = choose_weighted(
                (-1, 10, 12, 16, 24, 32, 48, 96),
                (50, 84, 89, 92, 96, 98, 99, 100))
        else:
            loc.horizontal_accuracy = request.accuracy
            if request.accuracy >= 10:
                loc.vertical_accuracy = choose_weighted(
                    (6, 8, 10, 12, 16, 24, 32, 48),
                    (4, 38, 73, 84, 88, 96, 99, 100))
            else:
                loc.vertical_accuracy = choose_weighted(
                    (3, 4, 6, 8, 10, 12), (15, 54, 68, 81, 95, 100))

        if loc.vertical_accuracy == -1:
            loc.vertical_accuracy = uniform(10, 96)

        sen.acceleration_x = triangular(-1.5, 2.5, 0)
        sen.acceleration_y = triangular(-1.2, 1.4, 0)
        sen.acceleration_z = triangular(-1.4, .9, 0)
        sen.magnetic_field_accuracy = choose_weighted((-1, 0, 1, 2),
                                                      (8, 10, 52, 100))
        if sen.magnetic_field_accuracy == -1:
            sen.magnetic_field_x = 0
            sen.magnetic_field_y = 0
            sen.magnetic_field_z = 0
        else:
            sen.magnetic_field_x = self.state.magnetic_field_x
            sen.magnetic_field_y = self.state.magnetic_field_y
            sen.magnetic_field_z = self.state.magnetic_field_z

        sen.attitude_pitch = triangular(-1.56, 1.57, 0.475)
        sen.attitude_yaw = triangular(-1.56, 3.14, .1)
        sen.attitude_roll = triangular(-3.14, 3.14, 0)
        sen.rotation_rate_x = triangular(-3.2, 3.52, 0)
        sen.rotation_rate_y = triangular(-3.1, 4.88, 0)
        sen.rotation_rate_z = triangular(-6, 3.7, 0)
        sen.gravity_x = triangular(-1, 1, 0.01)
        sen.gravity_y = triangular(-1, 1, -.4)
        sen.gravity_z = triangular(-1, 1, -.4)
        sen.status = 3

        sig.version_hash = -782790124105039914

        try:
            for key, value in device_info.items():
                setattr(sig.device_info, key, value)
        except AttributeError:
            pass
        sig.ios_device_info.bool5 = True

        try:
            rtype = request.requests[0].request_type
        except (IndexError, AttributeError):
            pass
        else:
            randval = random()
            # GetMapObjects or GetPlayer: 50%
            # Encounter: 10%
            # Others: 3%
            if ((rtype in (2, 106) and randval > 0.5)
                    or (rtype == 102 and randval > 0.9) or randval > 0.97):
                plat8 = PlatEightRequest()
                if self.state.message8:
                    plat8.field1 = self.state.message8
                plat = request.platform_requests.add()
                plat.type = 8
                plat.request_message = plat8.SerializeToString()

        sig.location_hash, sig.location_hash_by_token_seed, rh = await hashing
        sig.request_hashes.extend(rh)
        sig_request = SendEncryptedSignatureRequest()
        sig_request.encrypted_signature = pycrypt(sig.SerializeToString(),
                                                  sig.timestamp_ms_since_start)

        plat = request.platform_requests.add()
        plat.type = 6
        plat.request_message = sig_request.SerializeToString()

        request.ms_since_last_locationfix = sig.timestamp_ms_since_start - loc.timestamp_ms

        self.log.debug('Generated protobuf request: \n\r%s', request)
        return request
Exemplo n.º 4
0
 def course(self):
     self._course = triangular(0, 359.99, self._course)
     return self._course