async def test_raid(notifier, options): """Generate a notification for a fake pokemon spawn. """ now_ms = int(time.time() * 1000) rawfort = FortData( id="ABCXYZ", latitude=options.latitude, longitude=options.longitude, owned_by_team=randint(0, 3), type=GYM, ) rawfort.gym_display.slots_available = randint(0, 5) rawfort.raid_info.raid_spawn_ms = now_ms rawfort.raid_info.raid_battle_ms = now_ms + options.remaining * 500 rawfort.raid_info.raid_end_ms = now_ms + options.remaining * 1000 rawfort.raid_info.raid_level = randint(1, 5) if options.event == 'raid': rawfort.raid_info.raid_pokemon.pokemon_id = options.dexno rawfort.raid_info.raid_pokemon.cp = randint(10, 2844) rawfort.raid_info.raid_pokemon.move_1 = choice(MOVE_NUMBERS) rawfort.raid_info.raid_pokemon.move_2 = choice(MOVE_NUMBERS) normalfort = dict( name="Some Random Gym", desc="A gym that does not actually exist.", url="https://upload.wikimedia.org/wikipedia/commons/a/a9/Example.jpg", ) return await notifier.raid_notify(normalfort, rawfort)
def parse_command_line(): """Parse command line options. """ loglevels = ['debug', 'info', 'warning', 'error', 'critical'] parser = argparse.ArgumentParser() parser.add_argument('-e', '--event', default='spawn', choices=('raid', 'raidegg', 'spawn'), help="event type to simulate") parser.add_argument('-d', '--dexno', type=int, help='pokédex number for fake event') parser.add_argument('-lat', '--latitude', type=float, help='latitude for fake event') parser.add_argument('-lon', '--longitude', type=float, help='longitude for fake event') parser.add_argument('-r', '--remaining', type=int, help='seconds remaining on fake spawn') parser.add_argument( '-u', '--unmodified', action='store_true', help="don't modify ALWAYS_NOTIFY_IDS / NEVER_NOTIFY_IDS") parser.add_argument( '-t', '--test', action='store_true', help="test senders before attempting to send a notification") parser.add_argument('--log-level', default='WARNING', choices=loglevels, help='set log level') options = parser.parse_args() if options.dexno is None: options.dexno = randint(1, 387) if options.latitude is None: options.latitude = uniform(conf.MAP_START[0], conf.MAP_END[0]) if options.longitude is None: options.longitude = uniform(conf.MAP_START[1], conf.MAP_END[1]) if options.remaining is None: options.remaining = randint(89, 3599) return options
def __init__(self): self.avatar = 0 self.avatar_hair = 'AVATAR_m_hair_default_{}'.format(randint(0, 5)) self.avatar_eyes = 'AVATAR_m_eyes_{}'.format(randint(0, 4)) self.skin = randint(0, 3) self.avatar_hat = choice(self.hats) self.avatar_shirt = choice(self.shirts) self.avatar_backpack = choice(self.bags) self.avatar_gloves = choice(self.gloves) self.avatar_pants = "AVATAR_m_pants_default_0" self.avatar_socks = choice(self.socks) self.avatar_shoes = choice(self.footwear) self.avatar_glasses = "AVATAR_m_glasses_empty"
def __init__(self): self.avatar = 1 self.avatar_hair = 'AVATAR_f_hair_default_{}'.format(randint(0, 5)) self.avatar_eyes = 'AVATAR_f_eyes_{}'.format(randint(0, 4)) self.skin = randint(0, 3) self.avatar_hat = choice(self.hats) self.avatar_necklace = choice(self.necklaces) self.avatar_shirt = 'AVATAR_f_shirt_default_{}'.format(randint(0,8)) self.avatar_backpack = choice(self.bags) self.avatar_gloves = choice(self.gloves) self.avatar_belt = choice(self.belts) self.avatar_pants = choice(self.bottoms) self.avatar_socks = choice(self.socks) self.avatar_shoes = choice(self.footwear) self.avatar_glasses = "AVATAR_f_glasses_empty"
async def test_spawn(notifier, options): """Generate a notification for a fake pokemon spawn. """ remain_ms = options.remaining * 1000 now_ms = int(time.time() * 1000) rawwild = WildPokemon( encounter_id=93253523, last_modified_timestamp_ms=now_ms, latitude=options.latitude, longitude=options.longitude, spawn_point_id='58eef93', time_till_hidden_ms=remain_ms, ) if conf.SPAWN_ID_INT: spawnpt_id = int(rawwild.spawn_point_id, 16) else: spawnpt_id = rawwild.spawn_point_id, normalmon = { 'encounter_id': rawwild.encounter_id, 'spawn_id': spawnpt_id, 'pokemon_id': options.dexno, 'time_till_hidden': remain_ms // 1000, 'lat': options.latitude, 'lon': options.longitude, 'individual_attack': randint(0, 15), 'individual_defense': randint(0, 15), 'individual_stamina': randint(0, 15), 'seen': now_ms // 1000, 'move_1': choice(MOVE_NUMBERS), 'move_2': choice(MOVE_NUMBERS), 'gender': randint(1, 3), 'height': uniform(0.3, 4.0), 'weight': uniform(1, 600), 'valid': True, 'expire_timestamp': (now_ms + remain_ms) // 1000 } return await notifier.spawn_notify(normalmon, rawwild, randint(1, 2))
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
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
parser.add_argument('-r', '--remaining', type=int, help='seconds remaining on fake spawn') parser.add_argument('-u', '--unmodified', action='store_true', help="don't add ID to ALWAYS_NOTIFY_IDS") args = parser.parse_args() if args.id is not None: pokemon_id = args.id if args.id == 0: names.POKEMON[0] = 'Test' else: pokemon_id = randint(1, 387) if not args.unmodified: conf.ALWAYS_NOTIFY_IDS = {pokemon_id} conf.HASHTAGS = {'test'} from monocle.notification import Notifier from monocle.shared import SessionManager from monocle.names import MOVES root = logging.getLogger() root.setLevel(logging.DEBUG) ch = logging.StreamHandler(sys.stdout) ch.setLevel(logging.DEBUG) root.addHandler(ch)
type=int, help='seconds remaining on fake spawn' ) parser.add_argument( '-u', '--unmodified', action='store_true', help="don't add ID to ALWAYS_NOTIFY_IDS" ) args = parser.parse_args() if args.id is not None: pokemon_id = args.id if args.id == 0: names.POKEMON[0] = 'Test' else: pokemon_id = randint(1, 252) if not args.unmodified: conf.ALWAYS_NOTIFY_IDS = {pokemon_id} conf.HASHTAGS = {'test'} from monocle.notification import Notifier from monocle.shared import SessionManager from monocle.names import MOVES root = logging.getLogger() root.setLevel(logging.DEBUG) ch = logging.StreamHandler(sys.stdout) ch.setLevel(logging.DEBUG) root.addHandler(ch)