예제 #1
0
파일: load.py 프로젝트: glock2how/edr
def edr_submit_scan(scan, timestamp, source, witness):
    edt = EDTime()
    edt.from_journal_timestamp(timestamp)

    report = scan
    report["starSystem"] = witness.star_system
    report["place"] = witness.place
    report["timestamp"] = edt.as_js_epoch()
    report["source"] = source
    report["reportedBy"] = witness.name

    if not witness.in_open():
        EDRLOG.log(u"Scan not submitted due to unconfirmed Open mode", "INFO")
        EDR_CLIENT.status = _(u"not in Open? Start EDMC before Elite.")
        return

    if witness.has_partial_status():
        EDRLOG.log(u"Scan not submitted due to partial status", "INFO")
        return

    if not EDR_CLIENT.scanned(scan["cmdr"], report):
        EDR_CLIENT.status = _(u"failed to report scan.")
        EDR_CLIENT.evict_cmdr(scan["cmdr"])
    EDR_CLIENT.status = _(u"scan reported (cmdr {name}).").format(
        name=scan["cmdr"])
예제 #2
0
    def update_modules(self):
        reader = edmodulesinforeader.EDModulesInfoReader()
        modules_info = reader.process()
        stale = (self.slots_timestamp is
                 None) or (self.module_info_timestamp and
                           (self.slots_timestamp.as_py_epoch() <
                            self.module_info_timestamp.as_py_epoch()))
        if not stale:
            EDRLOG.log(u"Modules info: up-to-date", "DEBUG")
            return True

        if not modules_info or not modules_info.get("Modules", None):
            EDRLOG.log(u"No info on modules!", "DEBUG")
            return False

        timestamp = EDTime()
        timestamp.from_journal_timestamp(modules_info['timestamp'])
        if self.slots_timestamp and (
                timestamp.as_py_epoch() < self.slots_timestamp.as_py_epoch()
                or timestamp.as_py_epoch() <
                self.module_info_timestamp.as_py_epoch()):
            EDRLOG.log(
                u"Stale info in modulesinfo.json: {} vs. {})".format(
                    timestamp, self.slots_timestamp), "DEBUG")
            return False

        EDRLOG.log(
            u"Trying an update of modules: json@{}, slots@{}, panel looked@{}".
            format(timestamp, self.slots_timestamp,
                   self.module_info_timestamp), "DEBUG")
        updated = self.slots_timestamp is None
        EDRLOG.log(u"This will be our first time with actual info", "DEBUG")
        self.slots_timestamp = timestamp
        modules = modules_info.get("Modules", [])
        for module in modules:
            slot_name = module.get("Slot", None)
            if slot_name in self.slots:
                module_updated = self.slots[slot_name].update(module)
                if self.slots[slot_name].power_draw > 0:
                    if module_updated:
                        EDRLOG.log(
                            u"{} in {}: power_draw: {}, priority: {}".format(
                                self.slots[slot_name].cname, slot_name,
                                self.slots[slot_name].power_draw,
                                self.slots[slot_name].priority), "DEBUG")
                    updated |= module_updated
            else:
                the_module = edmodule.EDModule(module)
                self.slots[slot_name] = the_module
                if the_module.power_draw > 0 or the_module.power_generation > 0:
                    EDRLOG.log(
                        u"[New] {} in {}: power_draw: {}, priority: {}".format(
                            self.slots[slot_name].cname, slot_name,
                            self.slots[slot_name].power_draw,
                            self.slots[slot_name].priority), "DEBUG")
                updated |= the_module.power_draw > 0 or the_module.power_generation > 0
        return updated
예제 #3
0
    def update_from_loadout(self, event):
        other_id = event.get("ShipID", None)
        other_type = EDVehicleFactory.canonicalize(event.get(
            "Ship", "unknown"))

        if other_id != self.id or other_type != self.type:
            EDRLOG.log(
                u"Mismatch between ID ({} vs {}) and/or Type ({} vs. {}), can't update from loadout"
                .format(self.id, other_id, self.type, other_type), "WARNING")
            return

        self.identity = event.get('ShipIdent', None)
        self.name = event.get('ShipName', None)
        self.hull_health = event.get('HullHealth',
                                     None) * 100.0  # normalized to 0.0 ... 1.0
        if not 'Modules' in event:
            return
        self.modules = event['Modules']
        self.slots = {}
        timestamp = EDTime()
        self.slots_timestamp = timestamp.from_journal_timestamp(
            event['timestamp']) if 'timestamp' in event else timestamp
        self.module_info_timestamp = self.slots_timestamp  # To prevent reading stale data from modulesinfo.json
        for module in self.modules:
            ed_module = edmodule.EDModule(module)
            self.slots[module['Slot']] = ed_module
            if module.get("Slot", "").lower() == "powerplant":
                self.power_capacity = ed_module.power_generation
            health = module['Health'] * 100.0 if 'Health' in module else None
            self.subsystem_health(module.get('Item', None), health)
        self.cargo_capacity = event.get("CargoCapacity", 0)
        self.cargo.update(event)
예제 #4
0
 def __probably_previously_prospected(self, entry):
     b = entry.copy()
     b["timestamp"] = ""
     b["Remaining"] = ""
     matching_entry = None
     for previous in self.prospected_raw_history:
         a = previous.copy()
         a["timestamp"] = ""
         a["Remaining"] = ""
         if a == b and previous["Remaining"] >= entry["Remaining"]:
             matching_entry = previous
             break 
         
     if matching_entry:
         max_age = 60*5
         a_time = EDTime()
         a_time.from_journal_timestamp(matching_entry["timestamp"])
         b_time = EDTime()
         b_time.from_journal_timestamp(entry["timestamp"])
         return (b_time.as_py_epoch() - a_time.as_py_epoch()) <= max_age
     return False
예제 #5
0
파일: load.py 프로젝트: glock2how/edr
def edr_submit_contact(cmdr_name, ship, timestamp, source, witness):
    """
    Report a contact with a cmdr
    :param cmdr:
    :param timestamp:
    :param ship:
    :param source:
    :param witness:
    :return:
    """
    edt = EDTime()
    edt.from_journal_timestamp(timestamp)

    report = {
        "cmdr": cmdr_name,
        "starSystem": witness.star_system,
        "place": witness.place,
        "timestamp": edt.as_js_epoch(),
        "ship": ship if ship else u"Unknown",
        "source": source,
        "reportedBy": witness.name
    }

    if not witness.in_open():
        EDRLOG.log(u"Skipping submit contact due to unconfirmed Open mode",
                   "INFO")
        EDR_CLIENT.status = _(u"not in Open? Start EDMC before Elite.")
        return

    if witness.has_partial_status():
        EDRLOG.log(u"Skipping cmdr update due to partial status", "INFO")
        return

    if not EDR_CLIENT.blip(cmdr_name, report):
        EDR_CLIENT.status = _(u"failed to report contact.")
        EDR_CLIENT.evict_cmdr(cmdr_name)

    EDR_CLIENT.status = _(u"contact reported (cmdr {name}).").format(
        name=cmdr_name)
    edr_submit_traffic(cmdr_name, ship, timestamp, source, witness)
예제 #6
0
    def __process(self, fss_event):
        if fss_event.get("event", None) != "FSSSignalDiscovered":
            return False

        signal_name = fss_event.get("SignalName", None)
        if signal_name is None:
            return False

        if fss_event.get("SignalName_Localised", None) is None:
            self.__process_locations_fss(fss_event)
            self.noteworthy = True
            return True

        if signal_name in self.signals:
            self.signals[signal_name]["count"] += 1
            self.noteworthy = True
            return True
        elif signal_name in ["$USS;"]:
            uss_type = "misc"
            if  fss_event.get("USSType", None) in self.uss["variants"]:
                uss_type = fss_event["USSType"]
            self.uss["variants"][uss_type]["count"] += 1
            self.uss["available"] = True
            if "TimeRemaining" in fss_event:
                event_time = EDTime()
                event_time.from_journal_timestamp(fss_event["timestamp"])
                expires = event_time.as_py_epoch() + fss_event["TimeRemaining"]
                self.uss["variants"][uss_type]["expiring"].append(expires)
            self.noteworthy = True
            return True
        elif signal_name in self.combat_zones["variants"]:
            self.combat_zones["available"] = True
            self.combat_zones["variants"][signal_name]["count"] += 1
            return True
        elif signal_name in self.resource_extraction_sites["variants"]:
            self.resource_extraction_sites["available"] = True
            self.resource_extraction_sites["variants"][signal_name]["count"] += 1
            return True
        return False
예제 #7
0
파일: load.py 프로젝트: Niteship/edr
def edr_submit_traffic(cmdr_name, ship, timestamp, source, witness):
    """
    Report a contact with a cmdr
    :param cmdr:
    :param ship:
    :param timestamp:
    :param source:
    :param witness:
    :return:
    """
    edt = EDTime()
    edt.from_journal_timestamp(timestamp)

    report = {
        "cmdr" : cmdr_name,
        "starSystem": witness.star_system,
        "place": witness.place,
        "timestamp": edt.as_js_epoch(),
        "ship" : ship if ship else u"Unknown",
        "source": source,
        "reportedBy": witness.name,
        "byPledge": witness.powerplay.canonicalize() if witness.powerplay else ""
    }

    if not witness.in_open():
        EDRLOG.log(u"Skipping submit traffic due to unconfirmed Open mode", "INFO")
        EDR_CLIENT.status = _(u"not in Open? Start EDMC before Elite.")
        return

    if witness.has_partial_status():
        EDRLOG.log(u"Skipping traffic update due to partial status", "INFO")
        return

    if not EDR_CLIENT.traffic(witness.star_system, report):
        EDR_CLIENT.status = _(u"failed to report traffic.")
        EDR_CLIENT.evict_system(witness.star_system)
예제 #8
0
 def outfit_probably_changed(self, timestamp=None):
     edt = EDTime()
     if timestamp:
         edt.from_journal_timestamp(timestamp)
     self.module_info_timestamp = edt
예제 #9
0
파일: load.py 프로젝트: Niteship/edr
def handle_multicrew_events(ed_player, entry):
    if entry["event"] in ["CrewMemberJoins", "CrewMemberRoleChange", "CrewLaunchFighter"]:
        crew = plain_cmdr_name(entry["Crew"])
        success = ed_player.add_to_crew(crew)
        if success: # only show intel on the first add 
            EDR_CLIENT.status = _(u"added to crew: ").format(crew)
            EDRLOG.log(u"Addition to crew: {}".format(ed_player.crew.members), "INFO")
            EDR_CLIENT.who(crew, autocreate=True)

    if entry["event"] in ["CrewMemberQuits", "KickCrewMember"]:
        crew = plain_cmdr_name(entry["Crew"])
        duration = ed_player.crew_time_elapsed(crew)
        kicked = entry["event"] == "KickCrewMember"
        crimes = False if not "OnCrimes" in entry else entry["OnCrimes"]
        ed_player.remove_from_crew(crew)
        EDR_CLIENT.status = _(u"{} left the crew.".format(crew))
        EDRLOG.log(u"{} left the crew.".format(crew), "INFO")
        edt = EDTime()
        edt.from_journal_timestamp(entry["timestamp"])
        report = {
            "captain": ed_player.crew.captain,
            "timestamp": edt.as_js_epoch(),
            "crew" : crew,
            "duration": duration,
            "kicked": kicked,
            "crimes": crimes,
            "destroyed":  ed_player.destroyed if ed_player.is_captain() else False
        }
        edr_submit_multicrew_session(ed_player, report)

    if entry["event"] in ["JoinACrew"]:
        captain = plain_cmdr_name(entry["Captain"])
        ed_player.join_crew(captain)
        EDR_CLIENT.status = _(u"joined a crew.")
        EDRLOG.log(u"Joined captain {}'s crew".format(captain), "INFO")
        EDR_CLIENT.who(captain, autocreate=True)

    if entry["event"] in ["QuitACrew"] and ed_player.crew:
        for member in ed_player.crew.members:
            duration = ed_player.crew_time_elapsed(member)
            edt = EDTime()
            edt.from_journal_timestamp(entry["timestamp"])
            report = {
                "captain": ed_player.crew.captain,
                "timestamp": edt.as_js_epoch(),
                "crew" : member,
                "duration": duration,
                "kicked": False,
                "crimes": False,
                "destroyed": ed_player.destroyed if ed_player.is_captain() else False
            }    
            edr_submit_multicrew_session(ed_player, report)
        ed_player.leave_crew()
        EDR_CLIENT.status = _(u"left crew.")
        EDRLOG.log(u"Left the crew.", "INFO")

    if entry["event"] in ["EndCrewSession"] and ed_player.crew:
        crimes = False if not "OnCrimes" in entry else entry["OnCrimes"]
        for member in ed_player.crew.members:
            duration = ed_player.crew_time_elapsed(member)
            edt = EDTime()
            edt.from_journal_timestamp(entry["timestamp"])
            report = {
                "captain": ed_player.crew.captain,
                "timestamp": edt.as_js_epoch(),
                "crew" : member,
                "duration": duration,
                "kicked": False,
                "crimes": crimes,
                "destroyed": ed_player.destroyed if ed_player.is_captain() else False
            }    
            edr_submit_multicrew_session(ed_player, report)
        ed_player.disband_crew()
        EDR_CLIENT.status = _(u"crew disbanded.")
        EDRLOG.log(u"Crew disbanded.", "INFO")