Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions config.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@
# set of proxy addresses and ports
# SOCKS requires aiosocks to be installed
#PROXIES = {'http://127.0.0.1:8080', 'https://127.0.0.1:8443', 'socks5://127.0.0.1:1080'}
# proxy servers used for the ptc login
#PTC_PROXIES = {'http://127.0.0.1:8080', 'https://127.0.0.1:8443', 'socks5://127.0.0.1:1080'}

# convert spawn_id to integer for more efficient DB storage, set to False if
# using an old database since the data types are incompatible.
Expand Down
6 changes: 4 additions & 2 deletions monocle/sanitized.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
'PLAYER_LOCALE': dict,
'PROVIDER': str,
'PROXIES': set_sequence,
'RAIDS_FILTER': set_sequence_range,
'PTC_PROXIES': set_sequence,
'RAIDS_FILTER': set_sequence_range,
'RAIDS_LVL_MIN': int,
'RAIDS_IDS': set_sequence_range,
'RAIDS_DISCORD_URL': str,
Expand Down Expand Up @@ -210,7 +211,8 @@
'PLAYER_LOCALE': {'country': 'US', 'language': 'en', 'timezone': 'America/Denver'},
'PROVIDER': None,
'PROXIES': None,
'RAIDS_FILTER': (1, 2, 3, 4, 5),
'PTC_PROXIES': None,
'RAIDS_FILTER': (1, 2, 3, 4, 5),
'RAIDS_LVL_MIN': 4,
'RAIDS_IDS': (),
'RAIDS_DISCORD_URL': None,
Expand Down
24 changes: 24 additions & 0 deletions monocle/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ def get_cell_ids(cls, point):
else:
proxies = None

if conf.PTC_PROXIES:
ptc_proxies = cycle(conf.PTC_PROXIES)
else:
ptc_proxies = None


if conf.NOTIFY or conf.NOTIFY_RAIDS:
notifier = Notifier()

Expand Down Expand Up @@ -136,6 +142,8 @@ def initialize_api(self):
self.api.set_position(*self.location, self.altitude)
if self.proxies:
self.api.proxy = next(self.proxies)
if self.ptc_proxies:
self.api.ptc_proxy = next(self.ptc_proxies)
try:
if self.account['provider'] == 'ptc' and 'auth' in self.account:
self.api.auth_provider = AuthPtc(username=self.username, password=self.account['password'], timeout=conf.LOGIN_TIMEOUT)
Expand All @@ -151,6 +159,14 @@ def swap_proxy(self):
while proxy == self.api.proxy:
self.api.proxy = next(self.proxies)

def swap_ptc_proxy(self):
if len(conf.PTC_PROXIES) < 2:
return False
proxy = self.api.ptc_proxy
while proxy == self.api.ptc_proxy:
self.api.ptc_proxy = next(self.ptc_proxies)
return True

async def login(self, reauth=False):
"""Logs worker in and prepares for scanning"""
self.log.info('Trying to log in')
Expand Down Expand Up @@ -669,6 +685,14 @@ async def visit(self, point, spawn_id=None, bootstrap=False):
if not await self.login(reauth=True):
await self.swap_account(reason='reauth failed')
return await self.visit(point, spawn_id, bootstrap)
except ex.AuthConnectionException as e:
if self.swap_ptc_proxy():
self.log.error('{}, swapping proxy.', e)
await sleep(3, loop=LOOP)
else:
await sleep(120, loop=LOOP)
if not await self.login(reauth=True):
await self.swap_account(reason='reauth failed')
except ex.AuthException as e:
self.log.warning('Auth error on {}: {}', self.username, e)
self.error_code = 'NOT AUTHENTICATED'
Expand Down