Skip to content

Commit

Permalink
Version Checking & Minor Fixes (#5936)
Browse files Browse the repository at this point in the history
* Version Checking & Minor Fixes

Version checking is now fully automatic between PGoAPI and Niantic's API, using hashing endpoint provided by bossland

The check will pass even if PGoAPI is ahead of Niantic's force API

Minor Fixes:
- Corrected error throw when facing captcha during login
- Removed version checking against POGOProtos

* Extra '}' removed

* API Check Pass with more infor

Let user know what API version the bot is currently using instead of just "Niantic API Check pass"
  • Loading branch information
MerlionRock authored and solderzzc committed Mar 2, 2017
1 parent 7a556fd commit 8aca210
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 28 deletions.
79 changes: 75 additions & 4 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import threading
import shelve
import uuid
import urllib

from geopy.geocoders import GoogleV3
from pgoapi import PGoApi
Expand Down Expand Up @@ -41,7 +42,8 @@
from .inventory import init_inventory, player
from sys import platform as _platform
from pgoapi.protos.pogoprotos.enums import badge_type_pb2
from pgoapi.exceptions import AuthException
from pgoapi.exceptions import AuthException, NotLoggedInException, ServerSideRequestThrottlingException, ServerBusyOrOfflineException, NoPlayerPositionSetException
from pgoapi.hash_server import HashServer


class FileIOException(Exception):
Expand Down Expand Up @@ -260,6 +262,8 @@ def _register_events(self):
)

self.event_manager.register_event('location_cache_error')

self.event_manager.register_event('security_check')

self.event_manager.register_event('bot_start')
self.event_manager.register_event('bot_exit')
Expand Down Expand Up @@ -956,7 +960,8 @@ def login(self):
'login_failed',
sender=self,
level='info',
formatted='Login process failed: {}'.format(e));
formatted='Login process failed: {}'.format(e)
)

sys.exit()

Expand All @@ -983,17 +988,83 @@ def login(self):
formatted="Login successful."
)

# Start of security, to get various API Versions from different sources
# Get Official API
link = "https://pgorelease.nianticlabs.com/plfe/version"
f = urllib.urlopen(link)
myfile = f.read()
officalAPI = myfile[2:8]
self.event_manager.emit(
'security_check',
sender=self,
level='info',
formatted="Niantic Official API Version: {}".format(officalAPI)
)

link = "https://pokehash.buddyauth.com/api/hash/versions"
f = urllib.urlopen(link)
myfile = f.read()
bossland_hash_endpoint = myfile.split(",")
total_entry = int(len(bossland_hash_endpoint))
last_bossland_entry = bossland_hash_endpoint[total_entry-1]
bossland_lastestAPI = last_bossland_entry.split(":")[0].replace('\"','')
self.event_manager.emit(
'security_check',
sender=self,
level='info',
formatted="Latest Bossland Hashing API Version: {}".format(bossland_lastestAPI)
)

if self.config.check_niantic_api is True:
if HashServer.endpoint == "":
self.event_manager.emit(
'security_check',
sender=self,
level='info',
formatted="Warning: Bot is running on legacy API"
)
else:
PGoAPI_hash_endpoint = HashServer.endpoint.split("com/",1)[1]
PGoAPI_hash_version = []
# Check if PGoAPI hashing is in Bossland versioning
bossland_hash_data = json.loads(myfile)

for version, endpoint in bossland_hash_data.iteritems():
if endpoint == PGoAPI_hash_endpoint:
PGoAPI_hash_version.append(version)
# assuming andorid versioning is always last entry
PGoAPI_hash_version.reverse()

# covert official api version & hashing api version to numbers
officialAPI_int = int(officalAPI.replace('.',''))
hashingAPI_int = int(PGoAPI_hash_version[0].replace('.',''))

if hashingAPI_int < officialAPI_int:
self.event_manager.emit(
'security_check',
sender=self,
level='info',
formatted="We have detected a Pokemon API Change. Latest Niantic Version is: {}. Program Exiting...".format(officalAPI)
)
sys.exit(1)
else:
self.event_manager.emit(
'security_check',
sender=self,
level='info',
formatted="Current PGoAPI is using API Version: {}. Niantic API Check Pass".format(PGoAPI_hash_version[0])
)

# When successful login, do a captcha check
#Basic Captcha detection, more to come
response_dict = self.api.check_challenge()
captcha_url = response_dict['responses']['CHECK_CHALLENGE']['challenge_url']
if len(captcha_url) > 1:
status['message'] = 'Captcha Encountered, URL: {captcha_url}'
self.event_manager.emit(
'captcha',
sender=self,
level='critical',
formatted=status['message']
formatted='Captcha Encountered, URL: {}'.format(captcha_url)
)
sys.exit(1)

Expand Down
24 changes: 0 additions & 24 deletions pokemongo_bot/api_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@ class ApiWrapper(PGoApi, object):
def __init__(self, config=None):
self.config = config
self.gen_device_id()
self.capi = float(0.57)
self.POGOProtos = float(2.7)
# Check if bot is using lastest POGOProtos, only do so if check_niantic_api is set to true
# If a new Protos is availible, it mean there's a possibility of a new API
latestProtos = float(0.0)
if self.config.check_niantic_api is True:
if latestProtos > self.POGOProtos:
link = "https://raw.githubusercontent.com/AeonLucid/POGOProtos/master/.current-version"
f = urllib.urlopen(link)
myfile = f.read()
latestProtos = float(myfile[0:3])
print("\033[1;31;40m We have detected a possibility of a new pogo API. Try upgarding it by using ./setup.sh -u command")
print("\033[1;31;40m This message might still be shown after updating unless a new commit is done in Github\n")

device_info = {
"device_id": ApiWrapper.DEVICE_ID,
Expand Down Expand Up @@ -106,18 +93,7 @@ def create_request(self):

def login(self, provider, username, password):
# login needs base class "create_request"
officalAPI = float(0.0)
self.useVanillaRequest = True
if self.config.check_niantic_api is True:
link = "https://pgorelease.nianticlabs.com/plfe/version"
f = urllib.urlopen(link)
myfile = f.read()
self.config.check_niantic_api
print "Niantic Official API Version:" + myfile.strip()
officalAPI = float(myfile[2:6])
if officalAPI > self.capi:
print("\033[1;31;40m We have detected a Pokemon API Change. The current API version" + str(self.capi) + ".x is no longer supported. Exiting...")
sys.exit(1)

try:
PGoApi.set_authentication(
Expand Down

0 comments on commit 8aca210

Please sign in to comment.