Skip to content

Commit

Permalink
Add check whether injection has taken place whilst handle_screen is r…
Browse files Browse the repository at this point in the history
…unning
  • Loading branch information
Grennith committed Sep 20, 2024
1 parent fd76cb9 commit c4b3181
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
8 changes: 4 additions & 4 deletions mapadroid/mitm_receiver/endpoints/ReceiveProtosEndpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import time
from typing import List, Optional

import orjson
from aiohttp import web
from loguru import logger
import orjson

import mapadroid.mitm_receiver.protos.Rpc_pb2 as pogoprotos
from mapadroid.db.helper.SettingsDeviceHelper import SettingsDeviceHelper
from mapadroid.db.helper.TrsVisitedHelper import TrsVisitedHelper
from mapadroid.db.model import SettingsDevice
Expand All @@ -15,7 +16,6 @@
from mapadroid.utils.collections import Location
from mapadroid.utils.DatetimeWrapper import DatetimeWrapper
from mapadroid.utils.ProtoIdentifier import ProtoIdentifier
import mapadroid.mitm_receiver.protos.Rpc_pb2 as pogoprotos


class ReceiveProtosEndpoint(AbstractMitmReceiverRootEndpoint):
Expand Down Expand Up @@ -96,8 +96,8 @@ async def __handle_proto_data_dict(self, origin: str, data: dict) -> None:
if proto_type == ProtoIdentifier.GMO.value:
# TODO: Offload transformation
gmo: pogoprotos.GetMapObjectsOutProto = ProtoHelper.parse(ProtoIdentifier.GMO, decoded_raw_proto)
if not gmo.map_cell:
logger.debug("Ignoring apparently empty GMO")
if gmo.status != 1 or not gmo.map_cell:
logger.debug("Ignoring apparently empty GMO or unsuccessful status {}", gmo.status)
return
elif proto_type == ProtoIdentifier.FORT_SEARCH.value:
logger.debug("Checking fort search proto type 101")
Expand Down
3 changes: 3 additions & 0 deletions mapadroid/route/routecalc/calculate_route_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def format_solution(manager, routing, solution):

def _run_in_process_executor(method, less_coordinates, route_name):
# Utility method to init logging in process executor...

if not MadGlobals.application_args:
MadGlobals.load_args()
init_logging(MadGlobals.application_args, print_info=False)
try:
return method(less_coordinates, route_name)
Expand Down
8 changes: 6 additions & 2 deletions mapadroid/worker/strategy/AbstractMitmBaseStrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,15 @@ async def start_pogo(self) -> bool:
else:
return started_pogo

async def _is_injected(self) -> bool:
return await self._mitm_mapper.get_injection_status(self._worker_state.origin)

async def _wait_for_injection(self):
not_injected_count = 0
injection_thresh_reboot = int(
await self.get_devicesettings_value(MappingManagerDevicemappingKey.INJECTION_THRESH_REBOOT, 20))
window_check_frequency = 3
while not await self._mitm_mapper.get_injection_status(self._worker_state.origin):
while not await self._is_injected():
await self._check_for_mad_job()
if not_injected_count >= injection_thresh_reboot:
logger.warning("Not injected in time - reboot")
Expand All @@ -445,7 +448,8 @@ async def _wait_for_injection(self):
and not self._worker_state.stop_worker_event.is_set():
logger.info("Retry check_windows while waiting for injection at count {}",
not_injected_count)
await self._handle_screen()

await self._handle_screen(additional_eval=self._is_injected)
not_injected_count += 1
wait_time = 0
while wait_time < 20:
Expand Down
7 changes: 4 additions & 3 deletions mapadroid/worker/strategy/AbstractWorkerStrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import os
import time
from abc import ABC, abstractmethod
from typing import Any, List, Optional
from asyncio import Task
from typing import Any, Awaitable, Callable, Coroutine, List, Optional

from loguru import logger

Expand Down Expand Up @@ -319,9 +320,9 @@ async def _ensure_pogo_topmost(self):
else:
return False

async def _handle_screen(self) -> ScreenType:
async def _handle_screen(self, additional_eval: Optional[Callable[[], Awaitable[bool]]] = None) -> ScreenType:
screen_type: ScreenType = ScreenType.UNDEFINED
while not self._worker_state.stop_worker_event.is_set():
while not self._worker_state.stop_worker_event.is_set() and (additional_eval is None or not await additional_eval()):
if self._worker_state.login_error_count > 2:
logger.warning('Could not login again - clearing game data and restarting device')
await self.stop_pogo()
Expand Down

0 comments on commit c4b3181

Please sign in to comment.