def handle(self, msg: Message): if not IPMSG.IS_CMD_SET(msg.cmd, IPMSG.IPMSG_SENDMSG): return False if IPMSG.IS_OPT_SET(msg.cmd, IPMSG.IPMSG_ENCRYPTOPT): return False strExtra = msg.extra.decode(IPMSG.ENCODETYPE) try: begin = strExtra.index('{') end = strExtra.index('}') text = strExtra[:begin] format = strExtra[begin + 1:end] except ValueError: text = strExtra[:-1] format = '' content = TextContent(text, format, msg.friend.getId(), False) msg.contents.append(content) #测试代码 #self.engine.appendContent(content) return False
def handle(self, msg: Message): if IPMSG.IS_CMD_SET(msg.cmd, IPMSG.IPMSG_RECVMSG): packno = Util.RemoveLastZero(msg.extra).decode(IPMSG.ENCODETYPE) self.engine.EraseReleateTask(packno) return False
def handle(self, msg: Message): if not IPMSG.IS_CMD_SET(msg.cmd, IPMSG.IPMSG_SENDMSG): return False if not IPMSG.IS_OPT_SET(msg.cmd, IPMSG.IPMSG_ENCRYPTOPT): return False encryptData = msg.extra.decode(IPMSG.ENCODETYPE) try: found = encryptData.index('\0') encryptData = encryptData[:found] except: pass # 加密数据分三段, # 第一段为20002, # 第二段为通过RAS加密的内容, # 第三段通过第二段解密内容作为key进行解密 arrSplit = encryptData.split(':') if len(arrSplit)< 3 or arrSplit[0] != "20002": return False decryptData = SecurtInstance.decrypt(bytes.fromhex(arrSplit[1]), bytes.fromhex(arrSplit[2])) strExtra = decryptData.decode(IPMSG.ENCODETYPE) try: found = strExtra.index('\0') strExtra = strExtra[:found] except: pass try: begin = strExtra.rindex('{') end = strExtra.rindex('}') text = strExtra[:begin] format = strExtra[begin + 1 : end] except ValueError: text = strExtra[:-1] format = '' content = TextContent(text, format, msg.friend.getId(), False) msg.contents.append(content) # 测试代码 #self.engine.appendContent(content) return False
def handle(self, msg: Message): if IPMSG.IS_CMD_SET(msg.cmd, IPMSG.IPMSG_BR_EXIT): self.removeUser(msg.friend) logger.debug('好友下线:' + msg.friend.__str__()) return True return False
def handle(self, msg: Message): if not IPMSG.IS_CMD_SET(msg.cmd, IPMSG.IPMSG_SENDIMAGE): return False if not IPMSG.IS_OPT_SET(msg.cmd, IPMSG.IPMSG_FILEATTACHOPT): return False rawData = msg.extra bs = BmpSlice() # 如果解析成功 if bs.load(rawData): # 回应消息 sender = ResponseBmpRecvSender(bs.key, bs.slice) self.sendSender(sender, msg.friend.ip, msg.friend.port) logger.debug('接收到分片报文:%s %d : %d' % (bs.key, bs.slice, bs.totalSlice)) # 清除任务队列中的重传请求,用key_slice作为关键字 self.engine.EraseReleateTask(bs.key + '_' + str(bs.slice)) SMI.append(bs) # 设置报文重传请求 if SMI.count(bs.key) == 1 and bs.totalSlice != 1: # TODO 这里设置报文重传请求 pass # 如果容器中存储的数据还不满,那么不需要后续处理了 if SMI.count(bs.key) != bs.totalSlice: return True bmpData = SMI.getData(bs.key) if len(bmpData) == 0: return True lw = ImgLzw() lw.decodeImage(bmpData, RECV_IMAGE_PATH + bs.key) return True logger.error('加载bmp分片报文失败') # 如果解析失败,后续不需要再解析了 return True
def handle(self, msg: Message): if IPMSG.IS_CMD_SET(msg.cmd, IPMSG.IPMSG_ANSENTRY) and \ IPMSG.IS_OPT_SET(msg.cmd, IPMSG.FEIQ_EXTEND_CMD): strExtra = msg.extra.decode(IPMSG.ENCODETYPE) arrData = strExtra.split('\0') if len(arrData) >= 2: msg.friend.nickname = arrData[0] msg.friend.groupname = arrData[1] elif len(arrData) >= 1: msg.friend.nickname = arrData[0] #回应消息 #sender = GroupSender(IPMSG.IPMSG_ANSENTRY|IPMSG.FEIQ_EXTEND_CMD) #self.sendSender(sender, msg.friend.ip, msg.friend.port) self.updateUser(msg.friend) logger.debug('飞秋的分组信息:%s'%(msg.friend,)) return True return False
def handle(self, msg: Message): if IPMSG.IS_CMD_SET(msg.cmd, IPMSG.IPMSG_GETPUBKEY): strExtra = msg.extra.decode(IPMSG.ENCODETYPE) if strExtra.startswith('21003'): # 回应消息 sender = RepRsaSender() self.sendSender(sender, msg.friend.ip, msg.friend.port) logger.debug('对方请求RSA PUBLIC KEY:' + msg.friend.__str__()) return True return False
def handle(self, msg: Message): if IPMSG.IS_CMD_SET(msg.cmd, IPMSG.IPMSG_BR_ENTRY): strExtra = msg.extra.decode(IPMSG.ENCODETYPE) arrData = strExtra.split(' ') if len(arrData) > 2: msg.friend.nickname = arrData[0] msg.friend.groupname = arrData[1] # 回应消息 sender = CommandSender(IPMSG.IPMSG_ANSENTRY) self.sendSender(sender, msg.friend.ip, msg.friend.port) self.updateUser(msg.friend) logger.debug('好友上线:' + msg.friend.__str__()) return True return False
def handle(self, msg: Message): if IPMSG.IS_CMD_SET(msg.cmd, IPMSG.IPMSG_ANSPUBKEY): strExtra = Util.RemoveLastZero(msg.extra).decode(IPMSG.ENCODETYPE) if strExtra.startswith('21003:'): strE,strN = strExtra[6:].split('-') intE = int(strE, 16) intN = int(strN, 16) SecurtInstance.addPubKey(msg.friend.getId(), intE, intN) #对方发送密钥后需要通知任务队里的任务,设置用户ID类任务全部执行 self.engine.SetReleateTaskRun('PUBKEY_' + msg.friend.getId()) logger.debug('对方发送RSA PUBLIC KEY:' + msg.friend.__str__()) return True return False
def handle(self, msg: Message): if IPMSG.IS_OPT_SET(msg.cmd, IPMSG.IPMSG_SENDCHECKOPT): # 回应消息 sender = ResponseSender(IPMSG.IPMSG_RECVMSG, msg.packno) self.sendSender(sender, msg.friend.ip, msg.friend.port) return False