From bd14926b2cdc403250757a7ada89484e48f8b53e Mon Sep 17 00:00:00 2001 From: evenly-epic-mule Date: Wed, 14 Feb 2018 18:04:59 +0100 Subject: [PATCH] Add option to use extra proxies for PTC only requires https://github.com/ZeChrales/aiopogo/pull/4 --- config.example.py | 2 ++ monocle/sanitized.py | 6 ++++-- monocle/worker.py | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/config.example.py b/config.example.py index dca82d688..3997ed2a5 100644 --- a/config.example.py +++ b/config.example.py @@ -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. diff --git a/monocle/sanitized.py b/monocle/sanitized.py index 02cee9321..ff971b79b 100644 --- a/monocle/sanitized.py +++ b/monocle/sanitized.py @@ -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, @@ -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, diff --git a/monocle/worker.py b/monocle/worker.py index a166a7625..543ea8bd5 100644 --- a/monocle/worker.py +++ b/monocle/worker.py @@ -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() @@ -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) @@ -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') @@ -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'