コード例 #1
0
ファイル: geofenceHelper.py プロジェクト: Boby360/MAD
    def get_geofenced_coordinates(self, coordinates):

        # Import: We are working with n-tuples in some functions be carefull
        # and do not break compatibility
        logger.debug('Using matplotlib: {}.', self.use_matplotlib)
        logger.debug('Found {} coordinates to geofence.', len(coordinates))

        geofenced_coordinates = []
        for c in coordinates:
            # Coordinate is not valid if in one excluded area.
            if self._is_excluded(c):
                continue

            # Coordinate is geofenced if in one geofenced area.
            if self.geofenced_areas:
                for va in self.geofenced_areas:
                    if self._in_area(c, va):
                        geofenced_coordinates.append(c)
                        break
            else:
                geofenced_coordinates.append(c)

        logger.debug2("Geofenced to {} coordinates",
                      len(geofenced_coordinates))
        return geofenced_coordinates
コード例 #2
0
 def clean_up_user(self, worker_id, worker_instance):
     logger.debug2("Cleanup of {} called with ref {}".format(
         worker_id, str(worker_instance)))
     with self.__loop_mutex:
         future = asyncio.run_coroutine_threadsafe(
             self.__internal_clean_up_user(worker_id, worker_instance),
             self.__loop)
     future.result()
コード例 #3
0
ファイル: MITMBase.py プロジェクト: Boby360/MAD
    def _check_data_distance(self, data):
        max_radius = self._mapping_manager.routemanager_get_max_radius(
            self._routemanager_name)
        if not max_radius:
            return True
        max_radius: int = self._applicationArgs.maximum_valid_distance \
            if max_radius < self._applicationArgs.maximum_valid_distance else max_radius
        mode = self._mapping_manager.routemanager_get_mode(
            self._routemanager_name)
        if mode in ["mon_mitm", "iv_mitm"]:
            data_to_check = "wild_pokemon"
        else:
            data_to_check = "forts"
        lat_sum, lng_sum, counter = 0, 0, 0

        if data_to_check == "forts":
            for cell in data:
                if cell[data_to_check]:
                    cell_id = cell["id"]
                    if cell_id < 0:
                        cell_id = cell_id + 2**64
                    lat, lng, alt = S2Helper.get_position_from_cell(cell_id)
                    counter += 1
                    lat_sum += lat
                    lng_sum += lng
        else:
            for cell in data:
                for element in cell[data_to_check]:
                    counter += 1
                    lat_sum += element["latitude"]
                    lng_sum += element["longitude"]

        if counter == 0:
            return None
        avg_lat = lat_sum / counter
        avg_lng = lng_sum / counter
        distance = get_distance_of_two_points_in_meters(
            float(avg_lat), float(avg_lng), float(self.current_location.lat),
            float(self.current_location.lng))
        if distance > max_radius:
            logger.debug2(
                "Data is too far away!! avg location {}, {} from "
                "data with self.current_location location {}, {} - that's a "
                "{}m distance with max_radius {} for mode {}", avg_lat,
                avg_lng, self.current_location.lat, self.current_location.lng,
                distance, max_radius, mode)
            return False
        else:
            logger.debug(
                "Data distance is ok! found avg location {}, {} "
                "from data with self.current_location location {}, {} - that's "
                "a {}m distance with max_radius {} for mode {}", avg_lat,
                avg_lng, self.current_location.lat, self.current_location.lng,
                distance, max_radius, mode)
            return True
コード例 #4
0
ファイル: geofenceHelper.py プロジェクト: Boby360/MAD
 def __init__(self, include_geofence, exclude_geofence):
     self.geofenced_areas = []
     self.excluded_areas = []
     self.use_matplotlib = 'matplotlib' in sys.modules
     if include_geofence or exclude_geofence:
         self.geofenced_areas = self.parse_geofences_file(include_geofence,
                                                          excluded=False)
         self.excluded_areas = self.parse_geofences_file(exclude_geofence,
                                                         excluded=True)
         logger.debug2("Loaded {} geofenced and {} excluded areas.",
                       len(self.geofenced_areas), len(self.excluded_areas))
コード例 #5
0
ファイル: screenPath.py プロジェクト: Akhrameev/MAD
 def get_devicesettings_value(self, key: str, default_value: object = None):
     logger.debug2("Fetching devicemappings of {}".format(self._id))
     try:
         devicemappings: Optional[dict] = self._mapping_manager.get_devicemappings_of(self._id)
     except (EOFError, FileNotFoundError) as e:
         logger.warning("Failed fetching devicemappings in worker {} with description: {}. Stopping worker"
                        .format(str(self._id), str(e)))
         return None
     if devicemappings is None:
         return default_value
     return devicemappings.get("settings", {}).get(key, default_value)
コード例 #6
0
ファイル: webhookworker.py プロジェクト: nepixl/MAD
    def __create_payload(self):
        logger.debug("Fetching data changed since {}", self.__last_check)

        # the payload that is about to be sent
        full_payload = []

        try:
            # raids
            raids = self.__prepare_raid_data(
                self._db_reader.get_raids_changed_since(self.__last_check))
            full_payload += raids

            # quests
            if self.__args.quest_webhook:
                quest = self.__prepare_quest_data(
                    self._db_reader.get_quests_changed_since(
                        self.__last_check))
                full_payload += quest

            # weather
            if self.__args.weather_webhook:
                weather = self.__prepare_weather_data(
                    self._db_reader.get_weather_changed_since(
                        self.__last_check))
                full_payload += weather

            # gyms
            if self.__args.gym_webhook:
                gyms = self.__prepare_gyms_data(
                    self._db_reader.get_gyms_changed_since(self.__last_check))
                full_payload += gyms

            # stops
            if self.__args.pokestop_webhook:
                pokestops = self.__prepare_stops_data(
                    self._db_reader.get_stops_changed_since(self.__last_check))
                full_payload += pokestops

            # mon
            if self.__args.pokemon_webhook:
                mon = self.__prepare_mon_data(
                    self._db_reader.get_mon_changed_since(self.__last_check))
                full_payload += mon
        except Exception:
            logger.exception("Error while creating webhook payload")

        logger.debug2("Done fetching data + building payload")

        return full_payload
コード例 #7
0
    def stats_collector(self):
        logger.debug2("Creating stats_collector task for {}".format(self._id))
        with self.__mapping_mutex:
            if not self._stats_collector_start:
                if time.time() - self._last_processed_timestamp > 300 or \
                        self.compare_hour(self._last_processed_timestamp):
                    self._last_processed_timestamp = time.time()

                    self.__mitm_mapper_parent.add_stats_to_process(
                        self._id, self.__stats_collected.copy(),
                        self._last_processed_timestamp)
                    self.__stats_collected.clear()
            else:
                self._stats_collector_start = False
                self._last_processed_timestamp = time.time()
コード例 #8
0
 def proto_endpoint(self, origin, data):
     logger.debug2("Receiving proto from {}".format(origin))
     logger.debug4("Proto data received from {}: {}".format(
         origin, str(data)))
     type = data.get("type", None)
     if type is None or type == 0:
         logger.warning(
             "Could not read method ID. Stopping processing of proto")
         return None
     if not self.__mitm_mapper.get_injection_status(origin):
         logger.info("Worker {} is injected now", str(origin))
         self.__mitm_mapper.set_injection_status(origin)
     # extract timestamp from data
     timestamp: float = data.get("timestamp", int(time.time()))
     self.__mitm_mapper.update_latest(
         origin,
         timestamp_received_raw=timestamp,
         timestamp_received_receiver=time.time(),
         key=type,
         values_dict=data)
     logger.debug3(
         "Placing data received by {} to data_queue".format(origin))
     self._data_queue.put((timestamp, data, origin))
     return None
コード例 #9
0
    def proto_endpoint(self, origin: str, data: Union[dict, list]):
        logger.debug2("Receiving proto from {}".format(origin))
        logger.debug4("Proto data received from {}: {}".format(origin, str(data)))
        if isinstance(data, list):
            # list of protos... we hope so at least....
            logger.debug2("Receiving list of protos")
            for proto in data:
                self.__handle_proto_data_dict(origin, proto)
        elif isinstance(data, dict):
            logger.debug2("Receiving single proto")
            # single proto, parse it...
            self.__handle_proto_data_dict(origin, data)

        self.__mitm_mapper.set_injection_status(origin)
コード例 #10
0
ファイル: WorkerMITM.py プロジェクト: sairon/MAD
    def _move_to_location(self):
        if not self._mapping_manager.routemanager_present(self._routemanager_name) \
                or self._stop_worker_event.is_set():
            raise InternalStopWorkerException
        routemanager_settings = self._mapping_manager.routemanager_get_settings(
            self._routemanager_name)
        # get the distance from our current position (last) to the next gym (cur)
        distance = get_distance_of_two_points_in_meters(
            float(self.last_location.lat), float(self.last_location.lng),
            float(self.current_location.lat), float(self.current_location.lng))
        logger.debug('Moving {} meters to the next position',
                     round(distance, 2))
        if not self._mapping_manager.routemanager_get_init(
                self._routemanager_name):
            speed = routemanager_settings.get("speed", 0)
            max_distance = routemanager_settings.get("max_distance", None)
        else:
            speed = int(25)
            max_distance = int(200)

        if (speed == 0 or (max_distance and 0 < max_distance < distance) or
            (self.last_location.lat == 0.0 and self.last_location.lng == 0.0)):
            logger.debug("main: Teleporting...")
            self._transporttype = 0
            self._communicator.set_location(
                Location(self.current_location.lat, self.current_location.lng),
                0)
            # the time we will take as a starting point to wait for data...
            cur_time = math.floor(time.time())

            delay_used = self.get_devicesettings_value('post_teleport_delay',
                                                       7)
            # Test for cooldown / teleported distance TODO: check this block...
            if self.get_devicesettings_value('cool_down_sleep', False):
                if distance > 10000:
                    delay_used = 15
                elif distance > 5000:
                    delay_used = 10
                elif distance > 2500:
                    delay_used = 8
                logger.debug("Need more sleep after Teleport: {} seconds!",
                             str(delay_used))
                # curTime = math.floor(time.time())  # the time we will take as a starting point to wait for data...
            walk_distance_post_teleport = self.get_devicesettings_value(
                'walk_after_teleport_distance', 0)
            if 0 < walk_distance_post_teleport < distance:
                # TODO: actually use to_walk for distance
                lat_offset, lng_offset = get_lat_lng_offsets_by_distance(
                    walk_distance_post_teleport)

                to_walk = get_distance_of_two_points_in_meters(
                    float(self.current_location.lat),
                    float(self.current_location.lng),
                    float(self.current_location.lat) + lat_offset,
                    float(self.current_location.lng) + lng_offset)
                logger.info("Walking roughly: {}", str(to_walk))
                time.sleep(0.3)
                self._communicator.walk_from_to(
                    self.current_location,
                    Location(self.current_location.lat + lat_offset,
                             self.current_location.lng + lng_offset), 11)
                logger.debug("Walking back")
                time.sleep(0.3)
                self._communicator.walk_from_to(
                    Location(self.current_location.lat + lat_offset,
                             self.current_location.lng + lng_offset),
                    self.current_location, 11)
                logger.debug("Done walking")
                time.sleep(1)
        else:
            logger.info("main: Walking...")
            self._transporttype = 1
            self._communicator.walk_from_to(self.last_location,
                                            self.current_location, speed)
            # the time we will take as a starting point to wait for data...
            cur_time = math.floor(time.time())
            logger.debug2("Done walking, fetching time to sleep")
            delay_used = self.get_devicesettings_value('post_walk_delay', 7)
        logger.debug2("Sleeping for {}s".format(str(delay_used)))
        time.sleep(float(delay_used))
        self.set_devicesettings_value("last_location", self.current_location)
        self.last_location = self.current_location
        self._waittime_without_delays = time.time()
        return cur_time, True
コード例 #11
0
    def process_data(self, received_timestamp, data, origin):
        data_type = data.get("type", None)
        raw = data.get("raw", False)
        logger.debug2("Processing data of {}".format(origin))
        if raw:
            logger.debug5("Received raw payload: {}", data["payload"])

        if data_type and not raw:
            logger.debug2("Running stats collector of {}".format(origin))
            if self.__application_args.game_stats:
                self.__mitm_mapper.run_stats_collector(origin)

            logger.debug4("Received data of {}: {}", origin, data)
            if data_type == 106:
                # process GetMapObject
                logger.success("Processing GMO received from {}. Received at {}", str(
                    origin), str(datetime.fromtimestamp(received_timestamp)))

                if self.__application_args.weather:
                    self.__db_submit.weather(origin, data["payload"], received_timestamp)

                self.__db_submit.stops(origin, data["payload"])
                self.__db_submit.gyms(origin, data["payload"])
                self.__db_submit.raids(origin, data["payload"], self.__mitm_mapper)

                self.__db_submit.spawnpoints(origin, data["payload"])
                mon_ids_iv = self.__mitm_mapper.get_mon_ids_iv(origin)
                self.__db_submit.mons(origin, data["payload"], mon_ids_iv, self.__mitm_mapper)
                self.__db_submit.cells(origin, data["payload"])
                self.__mitm_mapper.submit_gmo_for_location(origin, data["payload"])
                logger.debug2("Done processing GMO of {}".format(origin))
            elif data_type == 102:
                playerlevel = self.__mitm_mapper.get_playerlevel(origin)
                if playerlevel >= 30:
                    logger.info("Processing Encounter received from {} at {}", str(origin),
                                str(received_timestamp))
                    self.__db_submit.mon_iv(origin, received_timestamp, data["payload"], self.__mitm_mapper)
                    logger.debug2("Done processing encounter of {}".format(origin))
                else:
                    logger.debug('Playerlevel lower than 30 - not processing encounter Data')
            elif data_type == 101:
                logger.debug2("Processing proto 101 of {}".format(origin))
                self.__db_submit.quest(origin, data["payload"], self.__mitm_mapper)
                logger.debug2("Done processing proto 101 of {}".format(origin))
            elif data_type == 104:
                logger.debug2("Processing proto 104 of {}".format(origin))
                self.__db_submit.stop_details(data["payload"])
                logger.debug2("Done processing proto 104 of {}".format(origin))
            elif data_type == 4:
                logger.debug2("Processing proto 4 of {}".format(origin))
                self.__mitm_mapper.generate_player_stats(origin, data["payload"])
                logger.debug2("Done processing proto 4 of {}".format(origin))
            elif data_type == 156:
                logger.debug2("Processing proto 156 of {}".format(origin))
                self.__db_submit.gym(origin, data["payload"])
                logger.debug2("Done processing proto 156 of {}".format(origin))