Esempio n. 1
0
    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
Esempio n. 3
0
    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
Esempio n. 4
0
    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
Esempio n. 5
0
    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 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
Esempio n. 7
0
    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
Esempio n. 8
0
    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