def processCommand(self, schid, cmd): cmd = cmd.split(' ', 1) command = cmd[0].lower() if command == "ping": count = int(cmd[1]) if cmd[1] else 5 c = {} (err, clids) = ts3lib.getClientList(schid) for clid in clids: # if len(self.c) > 10: break if not clid in self.c: ts3lib.requestConnectionInfo(schid, clid) self.c.append(clid) (err, ping) = ts3lib.getConnectionVariableAsUInt64(schid, clid, ts3defines.ConnectionProperties.CONNECTION_PING) if err == ts3defines.ERROR_ok: c[clid] = ping print(c) s = sorted(c.items(), key=lambda x: int(x[1])) t = take(count, s) string = "" place = 1 for k,v in t: string += '{0}: {1} with [b]{2}[/b]ms\n'.format(place,clientURL(schid,k),v) place += 1 (err, ownid) = ts3lib.getClientID(schid) (err, ownchan) = ts3lib.getChannelOfClient(schid, ownid) message = [string[i:i + 900] for i in range(0, len(string), 900)] # message = re.findall('.{1,1024}(?:\n|$)', string) # message = (textwrap.wrap(string, 1024)) # message = (line.strip() for line in re.findall(r'.{1,80}(?:\s+|$)', string)) # message = textwrap.wrap(string, 1024, break_long_words=False) for msg in message: ts3lib.requestSendChannelTextMsg(schid, '\n{0}'.format(msg), ownchan) elif command == "clear": self.c = [] return 1
def onClientMoveEvent(self, schid, clid, oldChannelID, newChannelID, visibility, moveMessage): if not self.cfg.getboolean("general", "enabled"): return if oldChannelID != 0: return (error, _type) = ts3lib.getClientVariable( schid, clid, ts3defines.ClientPropertiesRare.CLIENT_TYPE) if _type == ts3defines.ClientType.ClientType_SERVERQUERY: return self.requested[schid] = [(schid, clid, "")] ts3lib.requestConnectionInfo(schid, clid)
def onServerErrorEvent(self, schid, errorMessage, error, returnCode, extraMessage): if not returnCode in self.retcodes: return self.retcodes.remove(returnCode) (err, ip) = ts3lib.getConnectionVariable( schid, self.clid, ts3defines.ConnectionProperties.CONNECTION_CLIENT_IP) if ip and ip != "None": retCode = ts3lib.createReturnCode() self.retcodes.append(retCode) ts3lib.requestConnectionInfo(schid, self.clid, retCode)
def infoData(self, schid, id, atype): if not self.cfg.getboolean('general', 'InfoData'): return if atype == PluginItemType.PLUGIN_SERVER: if not schid in self.requested: ts3.requestServerVariables(schid) return self.getServerInfo(schid) elif atype == PluginItemType.PLUGIN_CHANNEL: return self.getChannelInfo(schid, id) elif atype == PluginItemType.PLUGIN_CLIENT: if not id in self.requestedCLIDS: ts3.requestConnectionInfo(schid, id) return self.getClientInfo(schid, id) return None
def getInfoData(self, schid, id, atype): print("schid", schid, "id", id, "atype", atype) if atype == PluginItemType.PLUGIN_SERVER: if not schid in self.requested: ts3lib.requestServerVariables(schid) return self.getServerInfo(schid) elif atype == PluginItemType.PLUGIN_CHANNEL: return self.getChannelInfo(schid, id) elif atype == PluginItemType.PLUGIN_CLIENT: if not id in self.requestedCLIDS: ts3lib.requestConnectionInfo(schid, id) return self.getClientInfo(schid, id) return None
def banClient(self, schid, clid): (err, uid) = ts3lib.getClientVariable( schid, clid, ts3defines.ClientProperties.CLIENT_UNIQUE_IDENTIFIER) (err, ip) = ts3lib.getConnectionVariable( schid, clid, ts3defines.ConnectionProperties.CONNECTION_CLIENT_IP) if self.moveBeforeBan: ts3lib.requestClientMove(schid, clid, self.moveBeforeBan, "") if not ip: self.requestedIP = clid ts3lib.requestConnectionInfo(schid, clid) else: self.banIP(schid, ip) self.banUID(schid, uid)
def onMenuItemEvent(self, schid, atype, menuItemID, selectedItemID): if atype != ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_CLIENT or menuItemID != 0: return (err, uid) = ts3lib.getClientVariable(schid, selectedItemID, ts3defines.ClientProperties.CLIENT_UNIQUE_IDENTIFIER) if err != ts3defines.ERROR_ok: uid = "" (err, name) = ts3lib.getClientVariable(schid, selectedItemID, ts3defines.ClientProperties.CLIENT_NICKNAME) if err != ts3defines.ERROR_ok: name = "" (err, ip) = ts3lib.getConnectionVariable(schid, selectedItemID, ts3defines.ConnectionProperties.CONNECTION_CLIENT_IP) self.clid = selectedItemID if err or not ip: ip = "";ts3lib.requestConnectionInfo(schid, selectedItemID); print("requested for", selectedItemID, "on", schid) #TODO: Check if not self.dlg: self.dlg = BanDialog(self, schid, selectedItemID, uid, name, ip) else: self.dlg.setup(self, schid, selectedItemID, uid, name, ip) self.dlg.show() self.dlg.raise_() self.dlg.activateWindow()
def getScores(self, schid, flag, mode, count=10): c = {} (err, clids) = ts3lib.getClientList(schid) for clid in clids: # if len(self.c) > 10: break if not clid in self.c: ts3lib.requestConnectionInfo(schid, clid) self.c.append(clid) (err, ping) = ts3lib.getConnectionVariable(schid, clid, flag) if err == ts3defines.ERROR_ok: c[clid] = ping if mode == 0: s = sorted(c.items(), key=lambda x: int(x[1])) elif mode == 1: s = sorted(c.items(), key=lambda x: int(x[1]), reverse=True) return take(count, s)
def onConnectionInfoEvent(self, schid, clid): if PluginHost.cfg.getboolean("general", "verbose"): print(self.name, "> onConnectionInfoEvent", schid, clid) if not hasattr(self, "clid") or clid != self.clid: return (err, ip) = ts3lib.getConnectionVariable( schid, clid, ts3defines.ConnectionProperties.CONNECTION_CLIENT_IP) if ip: if ip == "None": retCode = ts3lib.createReturnCode() self.retcodes.append(retCode) ts3lib.requestConnectionInfo(schid, clid, retCode) return elif self.dlg: self.dlg.txt_ip.setText(ip) del self.clid
def onClientMoveEvent(self, serverConnectionHandlerID, clientID, oldChannelID, newChannelID, visibility, moveMessage): if not self.cfg.getboolean("events", "client connected"): return if oldChannelID == 0: (error, _type) = ts3.getClientVariableAsInt( serverConnectionHandlerID, clientID, ts3defines.ClientPropertiesRare.CLIENT_TYPE) if error == ts3defines.ERROR_ok and _type == 0: self.requested = clientID self.schid = serverConnectionHandlerID ts3.requestConnectionInfo(serverConnectionHandlerID, clientID) elif error == ts3defines.ERROR_ok and _type == 1: return else: ts3.printMessageToCurrentTab( "[[color=orange]WARNING[/color]] [color=red]ISPValidator could not resolve the client type of '%s'" % self.clientURL(serverConnectionHandlerID, clientID)) return
def onUpdateClientEvent(self, serverConnectionHandlerID, clientID, invokerID, invokerName, invokerUniqueIdentifier): if not self.cfg.getboolean("events", "client ip changed"): return if not invokerID == 0: return (error, _type) = ts3.getClientVariableAsInt( serverConnectionHandlerID, clientID, ts3defines.ClientPropertiesRare.CLIENT_TYPE) if error == ts3defines.ERROR_ok and _type == 0: self.requested = clientID self.schid = serverConnectionHandlerID ts3.requestConnectionInfo(serverConnectionHandlerID, clientID) elif error == ts3defines.ERROR_ok and _type == 1: return else: ts3.printMessageToCurrentTab( "[[color=orange]WARNING[/color]] [color=red]ISPValidator could not resolve the client type of '%s'" % self.clientURL(serverConnectionHandlerID, clientID)) return
def onConnectStatusChangeEvent(self, serverConnectionHandlerID, newStatus, errorNumber): if not self.cfg.getboolean("events", "own client connected"): return if newStatus == ts3defines.ConnectStatus.STATUS_CONNECTION_ESTABLISHED: (error, ids) = ts3.getClientList(serverConnectionHandlerID) if error == ts3defines.ERROR_ok: for _in in ids: (error, _type) = ts3.getClientVariableAsInt( serverConnectionHandlerID, clientID, ts3defines.ClientPropertiesRare.CLIENT_TYPE) if error == ts3defines.ERROR_ok and _type == 0: self.requested = clientID self.schid = serverConnectionHandlerID ts3.requestConnectionInfo(serverConnectionHandlerID, clientID) elif error == ts3defines.ERROR_ok and _type == 1: return else: ts3.printMessageToCurrentTab( "[[color=orange]WARNING[/color]] [color=red]ISPValidator could not resolve the client type of '%s'" % self.clientURL(serverConnectionHandlerID, clientID)) return
def onUpdateClientEvent(self, schid, clid, invokerID, invokerName, invokerUID): if schid != self.waiting_for[0]: return if clid != self.waiting_for[1]: return self.waiting_for = (0, 0) (err, uid) = ts3lib.getClientVariable( schid, clid, ts3defines.ClientProperties.CLIENT_UNIQUE_IDENTIFIER) if err != ts3defines.ERROR_ok: uid = "" (err, mytsid) = ts3lib.getClientVariable(schid, clid, 61) if err != ts3defines.ERROR_ok or not mytsid: if schid in self.mytsids and clid in self.mytsids[schid]: mytsid = self.mytsids[schid][clid] else: mytsid = "" (err, name) = ts3lib.getClientVariable( schid, clid, ts3defines.ClientProperties.CLIENT_NICKNAME) if err != ts3defines.ERROR_ok: name = "" self.clid = clid type = getServerType(schid) (err, ip) = ts3lib.getConnectionVariable( schid, clid, ts3defines.ConnectionProperties.CONNECTION_CLIENT_IP) if (err != ts3defines.ERROR_ok or not ip) or (ip and ip == "None"): retcode = ts3lib.createReturnCode() self.retcodes.append(retcode) ts3lib.requestConnectionInfo(schid, clid, retcode) (err, ip) = ts3lib.getConnectionVariable( schid, clid, ts3defines.ConnectionProperties.CONNECTION_CLIENT_IP) if not self.dlg: self.dlg = BanDialog(self, schid, clid, uid, name, ip, mytsid, "", type) else: self.dlg.setup(self, schid, clid, uid, name, ip, mytsid, ip, type) self.dlg.show() self.dlg.raise_() self.dlg.activateWindow()
def processCommand(self, schid, keyword): args = keyword.split() cmd = args.pop(0).lower() if cmd == "com": command = " ".join(args) self.retcode = ts3lib.createReturnCode(); self.schid = schid err = ts3lib.requestSendClientQueryCommand(schid, command, self.retcode) if err != ts3defines.ERROR_ok: (_err, msg) = ts3lib.getErrorMessage(err) ts3lib.printMessageToCurrentTab("(%s) %s: %s"%(schid, command, msg)) elif cmd == "req": clid = int(args.pop(0)) self.req = clid ts3lib.requestClientVariables(schid, clid) elif cmd == "reqcon": clid = int(args.pop(0)) self.req = clid ts3lib.requestConnectionInfo(schid, clid) elif cmd == "self": err, clid = ts3lib.getClientID(schid) ts3lib.printMessageToCurrentTab("[b]{}'s Self Variables:".format(clientURL(schid, clid))) open(self.filepath, 'w').close() min=0;max=64 if len(args): min = int(args.pop(0)) if len(args): max = int(args.pop(0)) for i in range(min, max): msg = "%s"%i values = set(item.value for item in ts3enums.ClientProperties) if i in values: msg += " ({})".format(ts3enums.ClientProperties(i)) msg += ": " (err, var) = ts3lib.getClientSelfVariableAsString(schid, i) if err != ts3defines.ERROR_ok: (_err, var) = ts3lib.getErrorMessage(err) msg += var with open(self.filepath, "a", encoding="utf-8") as myfile: myfile.write(msg+"\n") ts3lib.printMessageToCurrentTab(msg) elif cmd == "client": clid = int(args.pop(0)) ts3lib.printMessageToCurrentTab("[b]{}'s Client Variables:".format(clientURL(schid, clid))) open(self.filepath, 'w').close() min=0;max=64 if len(args): min = int(args.pop(0)) if len(args): max = int(args.pop(0)) for i in range(min, max): msg = "%s"%i values = set(item.value for item in ts3enums.ClientProperties) if i in values: msg += " ({})".format(ts3enums.ClientProperties(i)) msg += ": " (err, var) = ts3lib.getClientVariableAsString(schid, clid, i) if err != ts3defines.ERROR_ok: (_err, var) = ts3lib.getErrorMessage(err) msg += var with open(self.filepath, "a", encoding="utf-8") as myfile: myfile.write(msg+"\n") ts3lib.printMessageToCurrentTab(msg) elif cmd == "con": clid = int(args.pop(0)) ts3lib.printMessageToCurrentTab("[b]{}'s Connection Variables:".format(clientURL(schid, clid))) open(self.filepath, 'w').close() min=0;max=65 if len(args): min = int(args.pop(0)) if len(args): max = int(args.pop(0)) for i in range(min, max): msg = "%s"%i values = set(item.value for item in ts3enums.ConnectionProperties) if i in values: msg += " ({})".format(ts3enums.ConnectionProperties(i)) msg += ": " (err, var) = ts3lib.getConnectionVariableAsString(schid, clid, i) if err != ts3defines.ERROR_ok: (_err, var) = ts3lib.getErrorMessage(err) msg += var with open(self.filepath, "a", encoding="utf-8") as myfile: myfile.write(msg+"\n") ts3lib.printMessageToCurrentTab(msg) else: return False return True