Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raids [BACKEND ONLY] #306

Open
wants to merge 56 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
7792ae7
WIP
Noctem Apr 28, 2017
5321881
WIP2
Noctem Apr 28, 2017
b7d0ad1
WIP3
Noctem Apr 30, 2017
d2441b7
Use pogeo's AltitudeCache
Noctem May 2, 2017
ec1cc6f
Update solve_captchas
Noctem May 2, 2017
9861703
DB improvements
Noctem May 2, 2017
da68e70
Small Travis improvement
Noctem May 3, 2017
013d745
WIP4
Noctem May 10, 2017
b0cd60f
Update JS
Noctem May 10, 2017
b06b4fc
Update jquery to 3.2.1
Noctem May 11, 2017
88e5f2d
lint and clang-format main.js
Noctem May 11, 2017
e8d4f31
Update displaying scan area for new shape types
Noctem May 11, 2017
90ad98b
Speed up PokéStop responses
Noctem May 11, 2017
7784e98
Use AioSightingCache in web_sanic
Noctem May 12, 2017
6ca81f8
Update web.py for pogeo changes
Noctem May 13, 2017
9b72cb7
Skip tasks that are now done server-side
Noctem May 13, 2017
9075028
Add favicon and tidy up HTML
Noctem May 13, 2017
5ed1dcf
Merge branch 'develop' into WIP
Noctem May 17, 2017
8ff947c
Change requirements to use pogeo develop branch
Noctem May 17, 2017
98b9cab
Merge branch 'develop' into WIP
Noctem May 19, 2017
90441a1
Merge branch 'develop' into WIP
Noctem May 19, 2017
d291663
Use AioSpawnCache
Noctem May 19, 2017
e4baa9c
Use pogeo shapes instead of shapely for landmarks
Noctem May 23, 2017
b810e2b
Add a script for converting landmarks config
Noctem May 28, 2017
12d1a85
Bug fixes
Noctem May 30, 2017
0ea754e
Merge branch 'develop' into WIP
Noctem May 30, 2017
aa6770d
Merge remote-tracking branch 'upstream/develop' into develop
Jun 11, 2017
b2d9ecd
c
Jun 11, 2017
ff23ca3
Merge master
Jun 12, 2017
f687ebc
6304
Jun 12, 2017
f8e8190
adding cp
Jun 12, 2017
993ca61
adding cp
Jun 12, 2017
a1785e2
Correction CP
Jun 12, 2017
eb4c1e8
CP
Jun 12, 2017
af9171a
Merge remote-tracking branch 'upstream/develop' into develop
Jun 21, 2017
96d84c0
Adding lure on demand
Jun 21, 2017
4ffff07
LURE_ON_DEMAND default false
Jun 22, 2017
741363a
Define LURE_ON_DEMAND
Jun 22, 2017
8a2c5e1
Merge remote-tracking branch 'upstream/develop' into develop
Jun 25, 2017
a9f28f4
Adding raid infos to db and cache
Jun 25, 2017
147a86d
Remove personal field
Jun 25, 2017
9f7bfa2
Resetting error codes
sebast1219 Jun 26, 2017
1793fdb
Removing cp from this branch
sebast1219 Jun 26, 2017
599e32e
Reset branch to raid only
sebast1219 Jun 26, 2017
441a9bc
Clean branch
sebast1219 Jun 26, 2017
74c8967
Default values for raid to None
sebast1219 Jun 26, 2017
0ce0822
Correcting cp type
sebast1219 Jun 26, 2017
c843568
Adding seed and correcting cache
sebast1219 Jun 27, 2017
1aeba9a
Correcting update when pokemon spawns in raid
sebast1219 Jun 27, 2017
3d43101
raid_seed as varchar
sebast1219 Jun 27, 2017
77abfa5
Removed notifDiscord on update
sebast1219 Jun 27, 2017
1df901a
Changed complete to boolean
Jun 29, 2017
f166a67
Changing complete type
Jun 29, 2017
ead87e8
Testing boolean
Jun 29, 2017
5aaaba1
Correcting raid_seed update
Jun 29, 2017
b5f4d8e
Str of raid_seed
Jun 29, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'develop' into WIP
Noctem committed May 19, 2017

Verified

This commit was signed with the committer’s verified signature.
commit 98b9cab0ad37b0cb09579b4b5da28d21a5ac3a5b
170 changes: 83 additions & 87 deletions monocle/worker.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@

from aiopogo import PGoApi, HashServer, json_loads, exceptions as ex
from aiopogo.auth_ptc import AuthPtc
from cyrandom import choice, randint, uniform
from pogeo.utils import location_to_cellid, location_to_token

from .altitudes import load_alts, set_altitude
@@ -428,27 +429,23 @@ async def complete_tutorial(self, tutorial_state):

def update_inventory(self, inventory_items):
for thing in inventory_items:
try:
item_data = thing['inventory_item_data']
if 'item' in item_data:
item = item_data['item']
self.items[item['item_id']] = item.get('count', 0)
elif conf.INCUBATE_EGGS:
if ('pokemon_data' in item_data and
item_data['pokemon_data'].get('is_egg')):
egg = item_data['pokemon_data']
self.eggs[egg['id']] = egg
elif 'egg_incubators' in item_data:
self.unused_incubators = []
for item in item_data['egg_incubators']['egg_incubator']:
if 'pokemon_id' in item:
continue
if item.get('item_id') == 901:
self.unused_incubators.append(item)
else:
self.unused_incubators.insert(0, item)
except KeyError:
continue
obj = thing.inventory_item_data
if obj.HasField('item'):
item = obj.item
self.items[item.item_id] = item.count
elif conf.INCUBATE_EGGS:
if obj.HasField('pokemon_data') and obj.pokemon_data.is_egg:
egg = obj.pokemon_data
self.eggs[egg.id] = egg
elif obj.HasField('egg_incubators'):
self.unused_incubators.clear()
for item in obj.egg_incubators.egg_incubator:
if item.pokemon_id:
continue
if item.item_id == 901:
self.unused_incubators.append(item)
else:
self.unused_incubators.appendleft(item)

async def call(self, request, chain=True, stamp=True, buddy=True, settings=False, dl_hash=True, action=None):
if chain:
@@ -476,19 +473,10 @@ async def call(self, request, chain=True, stamp=True, buddy=True, settings=False
err = None
for attempt in range(-1, conf.MAX_RETRIES):
try:
response = await request.call()
try:
responses = response['responses']
except KeyError:
if chain:
raise ex.MalformedResponseException('no responses')
else:
self.location.update_time()
return response
else:
self.location.update_time()
err = None
break
responses = await request.call()
self.location.update_time()
err = None
break
except (ex.NotLoggedInException, ex.AuthException) as e:
self.log.info('Auth error on {}: {}', self.username, e)
err = e
@@ -562,34 +550,39 @@ async def call(self, request, chain=True, stamp=True, buddy=True, settings=False
self.last_action = self.location.time + action

try:
delta = responses['GET_INVENTORY']['inventory_delta']
self.inventory_timestamp = delta['new_timestamp_ms']
self.update_inventory(delta['inventory_items'])
delta = responses['GET_INVENTORY'].inventory_delta
self.inventory_timestamp = delta.new_timestamp_ms
self.update_inventory(delta.inventory_items)
except KeyError:
pass

if settings:
try:
dl_settings = responses['DOWNLOAD_SETTINGS']
Worker.download_hash = dl_settings.hash
except KeyError:
self.log.info('Missing DOWNLOAD_SETTINGS response.')
else:
try:
if (not dl_hash
and conf.FORCED_KILL
and dl_settings['settings']['minimum_client_version'] != '0.63.1'):
forced_version = StrictVersion(dl_settings['settings']['minimum_client_version'])
if forced_version > StrictVersion('0.63.1'):
err = '{} is being forced, exiting.'.format(forced_version)
self.log.error(err)
print(err)
exit()
except KeyError:
pass
if self.check_captcha(responses):
self.log.warning('{} has encountered a CAPTCHA, trying to solve', self.username)
if (not dl_hash
and conf.FORCED_KILL
and dl_settings.settings.minimum_client_version != '0.63.1'):
forced_version = StrictVersion(dl_settings.settings.minimum_client_version)
if forced_version > StrictVersion('0.63.1'):
err = '{} is being forced, exiting.'.format(forced_version)
self.log.error(err)
print(err)
exit()
try:
challenge_url = responses['CHECK_CHALLENGE'].challenge_url
if challenge_url != ' ':
Worker.captchas += 1
await self.handle_captcha(responses)
if conf.CAPTCHA_KEY:
self.log.warning('{} has encountered a CAPTCHA, trying to solve', self.username)
await self.handle_captcha(challenge_url)
else:
raise CaptchaException
except KeyError:
pass
return responses

async def bootstrap_visit(self, point):
@@ -693,7 +686,8 @@ async def visit_point(self, point, spawn_id=None, bootstrap=False):
self.error_code = 'EXCEPTION'
return False

async def visit(self, spawn_id, bootstrap, encounter_conf=conf.ENCOUNTER, notify_conf=conf.NOTIFY):
async def visit(self, spawn_id, bootstrap,
encounter_conf=conf.ENCOUNTER, notify_conf=conf.NOTIFY):
self.handle.cancel()
self.error_code = '∞' if bootstrap else '!'

@@ -715,9 +709,8 @@ async def visit(self, spawn_id, bootstrap, encounter_conf=conf.ENCOUNTER, notify
try:
map_objects = responses['GET_MAP_OBJECTS']

map_status = map_objects['status']
if map_status != 1:
error = 'GetMapObjects code {} for {}. Speed: {:.2f}m/s'.format(map_status, self.username, self.speed)
if map_objects.status != 1:
error = 'GetMapObjects code {} for {}. Speed: {:.2f}m/s'.format(map_objects.status, self.username, self.speed)
self.empty_visits += 1
if self.empty_visits > 3:
await self.swap_account('{} empty visits'.format(self.empty_visits))
@@ -734,9 +727,9 @@ async def visit(self, spawn_id, bootstrap, encounter_conf=conf.ENCOUNTER, notify
if conf.ITEM_LIMITS and self.bag_full():
await self.clean_bag()

for map_cell in map_objects['map_cells']:
request_time_ms = map_cell['current_timestamp_ms']
for pokemon in map_cell.get('wild_pokemons', ()):
for map_cell in map_objects.map_cells:
request_time_ms = map_cell.current_timestamp_ms
for pokemon in map_cell.wild_pokemons:
pokemon_seen += 1

normalized = self.normalize_pokemon(pokemon)
@@ -868,23 +861,26 @@ async def spin_pokestop(self, pokestop):
responses = await self.call(request, action=2)

try:
result = responses['FORT_SEARCH']['result']
if result == 1:
self.log.info('Spun {}.', name)
elif result == 2:
self.log.info('The server said {} was out of spinning range. {:.1f}m {:.1f}m/s',
name, distance, self.speed)
elif result == 3:
self.log.warning('{} was in the cooldown period.', name)
elif result == 4:
self.log.warning('Could not spin {} because inventory was full. {}',
name, sum(self.items.values()))
elif result == 5:
self.log.warning('Could not spin {} because the daily limit was reached.', name)
self.pokestops = False
else:
self.log.error('Unknown Pokestop spinning response code: {}', result)
result = responses['FORT_SEARCH'].result
except KeyError:
self.log.warning('Invalid Pokéstop spinning response.')
self.error_code = '!'
return

if result == 1:
self.log.info('Spun {}.', name)
elif result == 2:
self.log.info('The server said {} was out of spinning range. {:.1f}m {:.1f}{}',
name, distance, self.speed, UNIT_STRING)
elif result == 3:
self.log.warning('{} was in the cooldown period.', name)
elif result == 4:
self.log.warning('Could not spin {} because inventory was full. {}',
name, sum(self.items.values()))
elif result == 5:
self.log.warning('Could not spin {} because the daily limit was reached.', name)
self.pokestops = False
else:
self.log.warning('Failed spinning {}: {}', name, result)

self.next_spin = monotonic() + conf.SPIN_COOLDOWN
@@ -951,8 +947,7 @@ async def clean_bag(self):
responses = await self.call(request, action=2)

try:
result = responses['RECYCLE_INVENTORY_ITEM']['result']
if result == 1:
if responses['RECYCLE_INVENTORY_ITEM'].result == 1:
removed += count
else:
self.log.warning("Failed to remove item {}, code: {}", item, result)
@@ -1003,7 +998,7 @@ async def handle_captcha(self, challenge_url):
'key': conf.CAPTCHA_KEY,
'method': 'userrecaptcha',
'googlekey': '6LeeTScTAAAAADqvhqVMhPpr_vB9D364Ia-1dSgK',
'pageurl': responses['CHECK_CHALLENGE']['challenge_url'],
'pageurl': challenge_url,
'json': 1
}
async with session.post('http://2captcha.com/in.php', params=params) as resp:
@@ -1149,9 +1144,9 @@ def normalize_pokemon(raw, spawn_int=conf.SPAWN_ID_INT):
tth = raw.time_till_hidden_ms
norm = {
'type': 'pokemon',
'encounter_id': raw['encounter_id'],
'pokemon_id': raw['pokemon_data']['pokemon_id'],
'spawn_id': int(raw['spawn_point_id'], 16) if spawn_int else raw['spawn_point_id']
'encounter_id': raw.encounter_id,
'pokemon_id': raw.pokemon_data.pokemon_id,
'spawn_id': int(raw.spawn_point_id, 16) if spawn_int else raw.spawn_point_id,
'seen': tss
}
if tth > 0 and tth <= 90000:
@@ -1169,15 +1164,16 @@ def normalize_pokemon(raw, spawn_int=conf.SPAWN_ID_INT):
return norm

@staticmethod
def normalize_lured(raw, now, spawn_int=conf.SPAWN_ID_INT):
def normalize_lured(raw, now, sid=location_to_cellid if conf.SPAWN_ID_INT else location_to_token):
lure = raw.lure_info
loc = Location(raw['latitude'], raw['longitude'])
return {
'type': 'pokemon',
'encounter_id': raw['lure_info']['encounter_id'],
'pokemon_id': raw['lure_info']['active_pokemon_id'],
'expire_timestamp': raw['lure_info']['lure_expires_timestamp_ms'] // 1000,
'spawn_id': location_to_cellid(loc, 30) if spawn_int else location_to_token(loc, 30),
'time_till_hidden': (raw['lure_info']['lure_expires_timestamp_ms'] - now) // 1000,
'encounter_id': lure.encounter_id,
'pokemon_id': lure.active_pokemon_id,
'expire_timestamp': lure.lure_expires_timestamp_ms // 1000,
'spawn_id': sid(loc, 30),
'time_till_hidden': (lure.lure_expires_timestamp_ms - now) / 1000,
'inferred': 'pokestop'
}

4 changes: 1 addition & 3 deletions optional-requirements.txt
Original file line number Diff line number Diff line change
@@ -9,10 +9,8 @@ aiodns>=1.1.0
aiosocks>=0.2.2
ujson>=1.35
sanic>=0.3
asyncpg>=0.8
ujson>=1.35
gpsoauth>=0.4.0
flask>=0.11.1
geopy>=1.11.0
asyncpg>=0.8
psycopg2>=2.6
mysqlclient>=1.3
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protobuf>=3.0.0
sqlalchemy>=1.1.0
aiopogo>=1.9.1
aiopogo>=2.0.0
aiohttp>=2.0.7,<2.1
https://github.com/Noctem/pogeo/archive/develop.zip
cyrandom>=0.3.0
You are viewing a condensed version of this merge commit. You can view the full changes here.