def PANIC(description=None): "Handle failure." if is2: sys.stderr.write("ERROR: {}\r\n".format(description or '')) traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stderr) else: logger.error("ERROR: {}".format(description or '')) logger.error("{}".format("\n".join( traceback.format_exception(exc_type, exc_value, exc_traceback)))) errorreport = {} errorreport['cmdr'] = news.commander errorreport['huttonappversion'] = HH_VERSION errorreport['edmcversion'] = str(appversion) errorreport['modulecall'] = description or '' errorreport['traceback'] = traceback.format_exception( exc_type, exc_value, exc_traceback) compress_json = json.dumps(errorreport) error_data = zlib.compress(compress_json.encode('utf-8')) #sys.stderr.write("Posting it...{}\r\n".format(compress_json.encode('utf-8'))) xmit.post('/errorreport', error_data, headers=xmit.COMPRESSED_OCTET_STREAM)
def journal_entry(self, cmdr, is_beta, system, station, entry, state): "Called when Elite Dangerous writes to the commander's journal." event = entry['event'] event_path = self.event_paths.get(event) compress_json = json.dumps(entry) transmit_json = zlib.compress(compress_json) if event_path: xmit.post(event_path, data=transmit_json, parse=False, headers=xmit.COMPRESSED_OCTET_STREAM)
def cmdr_data(data, is_beta): "Called shortly after startup with a dump of information from Frontier." if not is_beta: transmit_json = zlib.compress(json.dumps(data)) xmit.post('/docked', parse=False, data=transmit_json, headers=xmit.COMPRESSED_OCTET_STREAM) for plugin in this.plugins: try: plugin.cmdr_data(data, is_beta) except: PANIC("{}.cmdr_data".format(plugin))
def journal_entry(self, cmdr, _is_beta, _system, _station, entry, _state): "Act like a tiny EDMC plugin." if entry['event'] == 'SendText' and 'reset exploration data' in entry['Message']: self.credits = 0 reset_path = '/exploreset' compress_json_reset = json.dumps(entry) transmit_json_reset = zlib.compress(compress_json_reset) xmit.post(reset_path, data=transmit_json, parse=False, headers=xmit.COMPRESSED_OCTET_STREAM) if self.__reset(cmdr=cmdr) or entry['event'] == 'Scan' or not self.ready: self.__check_again()
def journal_entry(self, cmdr, is_beta, system, station, entry, state): "Called when Elite Dangerous writes to the commander's journal." if entry['event'] != 'Market': # requires accessing the commodity market in station return dump_path = data.get_journal_path('Market.json') # sys.stderr.write("Reading market data from: {}\r\n".format(dump_path)) with open(dump_path, 'rb') as dump: market_data = zlib.compress(dump.read()) # sys.stderr.write("Posting it...\r\n") xmit.post('/market', market_data, headers=xmit.COMPRESSED_OCTET_STREAM)
def _cargo_refresh(cmdr): dump_path = data.get_journal_path('Cargo.json') # sys.stderr.write("Reading cargo data from: {}\r\n".format(dump_path)) with open(dump_path, 'r') as dump: dump = dump.read() dump = json.loads(dump) this.cargodump = dump dump['commandername'] = cmdr compress_json = json.dumps(dump) cargo_data = zlib.compress(compress_json.encode('utf-8')) # sys.stderr.write("Posting it...\r\n") xmit.post('/missioncargo', cargo_data, headers=xmit.COMPRESSED_OCTET_STREAM)
def journal_entry(self, cmdr, is_beta, system, station, entry, state): "Called when Elite Dangerous writes to the commander's journal." if entry['event'] == 'CommunityGoal': for goal in entry['CurrentGoals']: if not goal['IsComplete']: # v0.2Collect Active CG only data = { 'entry.1465819909': goal['CGID'], 'entry.2023048714': goal['Title'], 'entry.617265888': goal['CurrentTotal'], 'entry.1469183421': goal['NumContributors'], 'entry.2011125544': goal['PlayerContribution'], 'entry.1759162752': goal['PlayerPercentileBand'] } xmit.post(CGT_TARGET_URL, data=data)
def xmit_event(path, transmit_json=transmit_json, cmdr=cmdr, system=system): "Transmit the event to our server at ``path.format(cmdr=cmdr, system=system)``." path = path.format(cmdr=cmdr, system=system) return xmit.post(path, data=transmit_json, headers=xmit.COMPRESSED_OCTET_STREAM)
def journal_entry(self, cmdr, is_beta, system, station, entry, state): "Called when Elite Dangerous writes to the commander's journal." if entry['event'] == 'Cargo': dump_path = data.get_journal_path('Cargo.json') # sys.stderr.write("Reading cargo data from: {}\r\n".format(dump_path)) with open(dump_path, 'r') as dump: dump = dump.read() if dump == "": return dump = json.loads(dump) dump['commandername'] = cmdr compress_json = json.dumps(dump) cargo_data = zlib.compress(compress_json.encode('utf-8')) # sys.stderr.write("Posting it...\r\n") xmit.post('/missioncargo', cargo_data, headers=xmit.COMPRESSED_OCTET_STREAM) # self.helper.status("Market data posted.") else: return
def journal_entry(self, cmdr, is_beta, system, station, entry, state): "Called when Elite Dangerous writes to the commander's journal." if entry['event'] != 'SendText': return compress_json = json.dumps(entry) transmit_json = zlib.compress(compress_json.encode('utf-8')) for command in self.commands: if command in entry['Message']: # Get the status format: command_status_format = self.status_formats.get(command) if not command_status_format: command_status_format = 'Sent {command} Command' # Send the event if required, getting json_data back: json_data = None command_xmit_path_format = self.xmit_paths.get(command) if command_xmit_path_format: command_xmit_path = command_xmit_path_format.format(cmdr=cmdr, system=system) if '{cmdr}' in command_xmit_path_format: # FILTHY hack to figure out if it's a 'get' json_data = xmit.get(command_xmit_path) else: json_data = xmit.post(command_xmit_path, data=transmit_json, headers=xmit.COMPRESSED_OCTET_STREAM) if xmit.FAILED: # naughty global command_status_format = 'Failed to Send {command} Command' # Format and display the status text: self.helper.status(command_status_format.format( # Add variables here that you'd like to use in your status text: command=command, system=system, # We also supply the server's reply: **(json_data or {}) )) # VERY special handling, with NONE of the automatic stuff above: if "my hutton run" in entry['Message']: json_data = xmit.get('/myhuttonrun.json/{}'.format(cmdr)) if not json_data: self.helper.status("Failed to get Hutton Run data.") elif json_data['SecondCount'] == "0": self.helper.status("You have not completed a Hutton Run") else: self.helper.status("Your best Hutton Run is {}".format(json_data['TravelTime']))