Skip to content

Commit

Permalink
exit the bot if unable to login (#5386)
Browse files Browse the repository at this point in the history
  • Loading branch information
rawgni authored and solderzzc committed Sep 11, 2016
1 parent 5a4e484 commit cb9ebb3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 41 deletions.
58 changes: 23 additions & 35 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from inventory import init_inventory, player
from sys import platform as _platform
from pgoapi.protos.POGOProtos.Enums import BadgeType_pb2
from pgoapi.exceptions import AuthException
import struct


Expand Down Expand Up @@ -814,15 +815,12 @@ def find_close_cells(self, lat, lng):
return map_cells

def check_session(self, position):

# Check session expiry
if self.api._auth_provider and self.api._auth_provider._ticket_expire:

# prevent crash if return not numeric value
if not self.is_numeric(self.api._auth_provider._ticket_expire):
if not str(self.api._auth_provider._ticket_expire).isdigit():
self.logger.info("Ticket expired value is not numeric", 'yellow')
return

remaining_time = \
self.api._auth_provider._ticket_expire / 1000 - time.time()

Expand All @@ -838,14 +836,6 @@ def check_session(self, position):
self.login()
self.api.activate_signature(self.get_encryption_lib())

@staticmethod
def is_numeric(s):
try:
float(s)
return True
except ValueError:
return False

def login(self):
self.event_manager.emit(
'login_started',
Expand All @@ -856,37 +846,35 @@ def login(self):
lat, lng = self.position[0:2]
self.api.set_position(lat, lng, self.alt) # or should the alt kept to zero?

while not self.api.login(
self.config.auth_service,
str(self.config.username),
str(self.config.password)):

try:
self.api.login(
self.config.auth_service,
str(self.config.username),
str(self.config.password))
except AuthException as e:
self.event_manager.emit(
'login_failed',
sender=self,
level='info',
formatted="Login error, server busy. Waiting 10 seconds to try again."
)
time.sleep(10)
'login_failed',
sender=self,
level='info',
formatted='Login process failed: {}'.format(e));

sys.exit()

with self.database as conn:
c = conn.cursor()
c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='login'")

result = c.fetchone()

while True:
if result[0] == 1:
conn.execute('''INSERT INTO login (timestamp, message) VALUES (?, ?)''', (time.time(), 'LOGIN_SUCCESS'))
break
else:
self.event_manager.emit(
'login_failed',
sender=self,
level='info',
formatted="Login table not founded, skipping log"
)
break
if result[0] == 1:
conn.execute('''INSERT INTO login (timestamp, message) VALUES (?, ?)''', (time.time(), 'LOGIN_SUCCESS'))
else:
self.event_manager.emit(
'login_failed',
sender=self,
level='info',
formatted="Login table not founded, skipping log"
)

self.event_manager.emit(
'login_successful',
Expand Down
20 changes: 14 additions & 6 deletions pokemongo_bot/api_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,23 @@ def create_request(self):
self._position_alt
)

def login(self, *args):
def login(self, provider, username, password):
# login needs base class "create_request"
self.useVanillaRequest = True
try:
ret_value = PGoApi.login(self, *args)
finally:
# cleanup code
self.useVanillaRequest = False
return ret_value
PGoApi.set_authentication(
self,
provider,
username=username,
password=password
)
except:
raise

response = PGoApi.app_simulation_login(self)
# cleanup code
self.useVanillaRequest = False
return response

def set_position(self, lat, lng, alt=None, teleporting=False):
self.actual_lat = lat
Expand Down

0 comments on commit cb9ebb3

Please sign in to comment.