Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
feat(farmer): imp socf_thread: continue looping on zones
Browse files Browse the repository at this point in the history
Signed-off-by: hldh214 <[email protected]>
  • Loading branch information
hldh214 committed Jul 12, 2023
1 parent d0886de commit c8a09f0
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions lokbot/farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def __init__(self, token, captcha_solver_config):
self.research_queue_available = threading.Event()
self.train_queue_available = threading.Event()
self.kingdom_tasks = []
self.zones = []

@staticmethod
def calc_time_diff_in_seconds(expected_ended):
Expand Down Expand Up @@ -439,7 +440,6 @@ def _get_nearest_zone(self, x, y, radius=16):

return zones

@functools.lru_cache()
def _get_nearest_zone_ng(self, x, y, radius=8):
current_zone_id = lokbot.util.get_zone_id_by_coords(x, y)

Expand Down Expand Up @@ -707,7 +707,9 @@ def socf_thread(self, radius, object_code_list=(OBJECT_CODE_CRYSTAL_MINE, OBJECT
url = self.kingdom_enter.get('networks').get('fields')[0]
from_loc = self.kingdom_enter.get('kingdom').get('loc')

zones = self._get_nearest_zone_ng(from_loc[1], from_loc[2], radius)
if not self.zones:
logger.info('getting nearest zone')
self.zones = self._get_nearest_zone_ng(from_loc[1], from_loc[2], radius)

sio = socketio.Client(reconnection=False, logger=socf_logger, engineio_logger=socf_logger)

Expand Down Expand Up @@ -758,20 +760,32 @@ def on_field_enter(data):
self.socf_entered = True

sio.connect(f'{url}?token={self.token}', transports=["websocket"], headers=ws_headers)
logger.debug(f'entering field: {zones}')
logger.debug(f'entering field: {self.zones}')
sio.emit('/field/enter/v3', self.api.b64xor_enc({'token': self.token}))

while not self.socf_entered:
time.sleep(1)

step = 9
grace = 7 # 9 times enter-leave action will cause ban
for key, value in enumerate(range(0, len(zones), step)):
if key >= grace:
index = 0
while self.zones:
if index >= grace:
logger.info('socf_thread grace exceeded, break')
break

zone_ids = zones[value:value + step]
index += 1
zone_ids = []
for _ in range(step):
if not self.zones:
break

zone_ids.append(self.zones.pop(0))

if len(zone_ids) < step:
logger.info(f'len(zone_ids) < {step}, break')
self.zones = []
break

if not sio.connected:
logger.warning('socf_thread disconnected, reconnecting')
Expand Down

0 comments on commit c8a09f0

Please sign in to comment.