def _extract_mod_version(self, addon_dir): log.DEBUG("Found mod %s, detecting version..." % (addon_dir)) file_path = join(self._d2mp_path(), join(addon_dir, "addoninfo.txt")) if not isfile(file_path): log.DEBUG("no addoninfo file found: %s" % (file_path)) return "0.0.1" regex = "(addonversion\s+)(\d+\.\d+\.\d+)" res = re.search(regex, get_file_content(file_path)) if res is not None: return res.group(2) else: log.CRITICAL("could not extract version number with regex: %s" % (regex)) return "0.0.1"
def _on_message(self, ws, message): cont = json.loads(message) log.DEBUG(cont) self.dispatchEvent(cont["event"], cont["data"]) if cont["event"] == XSockets.Events.onError: if self.onerror: self.onerror(message) self.dispatchEvent(cont["event"], cont["data"])
def _start_file_watcher(self): self.watcher = QFileSystemWatcher() self.watcher_file_path = join(abspath("."), self._watcher_file_name) log.DEBUG("creating watcher file: %s" %(self.watcher_file_path)) write_to_file(self.watcher_file_path, "Delete this file to shutdown D2MP\n") self.watcher.addPath(abspath(".")) self.watcher.directoryChanged.connect(self._watcher_changed_callback)
def trigger(self, event, json={}, callback=None): if isinstance(event, Message): message = event else: event = event.lower() message = Message(event, json) log.DEBUG(message.to_json()) self.webSocket.send(message.to_json()) if callback is not None: callback() return self
def __new__(cls, clear_cache = False): if not cls._instance: cls._instance = super(Settings, cls).__new__(cls) cls._instance.signals = Settings.signals() QSettings.setDefaultFormat(QSettings.IniFormat) log.DEBUG("saving settings in file %s" %(QSettings().fileName())); cls._instance._settings = QSettings() cls._defaults = { Settings.DOTA_PATH_KEY: dota_path_default, Settings.STEAM_PATH_KEY: steam_path_default, } if clear_cache: cls._instance._cache = {} return cls._instance
def delete_mod(self, mod_name, version=None): mod_path = join(self._d2mp_path(), mod_name) if not exists(mod_path): log.ERROR("wanted to delete not existing mod: %s" % (mod_name)) return log.DEBUG("deleting mod %s" % (mod_name)) rmtree(mod_path) self._remove_mod(mod_name, version) self.signals.contact_server.emit({ "msg": "ondeleted", "Mod": Mod(mod_name, version or "0.0.1").as_dict() })
def set_mod(self, mod_name): active_mod = self.get_active_mod() if not (active_mod is None or active_mod != mod_name): return log.DEBUG("Setting active mod to %s." % mod_name) assert exists(self._d2mp_path()) from_dir = join(self._d2mp_path(), mod_name.split("=")[0]) to_dir = self._mod_path() assert exists(from_dir) rmtree(self._addons_path()) copytree(from_dir, to_dir) f = open(self._mod_name_file(), "w") f.write(mod_name) f.close()
def _open_event_handler(self, data): log.DEBUG(data) data[u"clientType"] = u"RFC6455" self.connection = data self.XSocketsClientStorageGuid = data["StorageGuid"] for sub in self.subscriptions.getAll(): for callback in sub.callbacks: if sub.name and callback.state.get("options", {}).get( "skip", False): continue self.trigger( Message(XSockets.Events.pubSub.subscribe, { "Event": sub.name, "Confim": False })) self.dispatchEvent(XSockets.Events.bindings.completed, self.subscriptions.getAll()) if self.onopen: self.onopen()
def bind(self, event, fn, opts={}, callback=None): state = { "options": opts, "ready": self.webSocket is not None and self.webSocket.sock is not None, "confim": callback is not None } log.DEBUG("%s - %s" % (event, fn)) if state["ready"]: self.trigger( Message(XSockets.Events.pubSub.subscribe, { "Event": event, "Confim": state["confim"] })) if isinstance(fn, list): for f in fn: self.subscriptions.add(event, f, state) else: self.subscriptions.add(event, fn, state) return self
def delete_mods(self): rmtree(self._d2mp_path()) rmtree(self._mod_path()) log.DEBUG("deleted all present mods") self._cache["mods"] = []
def get_active_mod(self): info_file = self._mod_name_file() if not isfile(info_file): return None name = open(info_file).read() log.DEBUG("Current active mod: %s" % name) return name
def spectate(ip): kill_dota() log.DEBUG("Told Steam to spectate at %s." % (ip)) command("rungameid/570//+connect_hltv %s" % (ip))
def connect_dota(ip): log.DEBUG("Told Steam to connect to %s." % (ip)) command("connect/%s" % (ip))
def launch_dota(): if is_dota_running(): return log.DEBUG("Launching dota") return command("run/570")
self.show_message("Server message", message) def show_error_from_socket(self, message): self.show_message("Server error", message, QSystemTrayIcon.Critical) def show_message_from_mod_manager(self, message): self.show_message("ModManager message", message) def show_error_from_mod_manager(self, message): self.show_message("ModManager error", message, QSystemTrayIcon.Critical) def show_message(self, title, message, icon = QSystemTrayIcon.Information): self.tray.showMessage(title, message, icon) if __name__ == '__main__': app = SingleApplication(sys.argv) app.setQuitOnLastWindowClosed(False); if app.is_running(): log.DEBUG("[main] d2mp is already running!") else: QCoreApplication.setOrganizationName("D2Modd"); QCoreApplication.setOrganizationDomain("d2modd.in"); QCoreApplication.setApplicationName("D2ModdInClient"); log.DEBUG("[main] ready to close") r = app.exec_() log.DEBUG("[main] exiting with status %d" %r)
def handle_error(self, message): log.DEBUG(message) self.error.emit(str(message))
def send(self, data, event): mes = Message(event, data) log.DEBUG(mes.to_json()) self.webSocket.send(mes.to_json())