Пример #1
0
    def try_make_packet(self):
        logger.debug('try_make_packet')
        tag = 0
        tag |= c.IPMSG_SENDMSG
        tag |= c.IPMSG_SENDCHECKOPT
        tag |= c.IPMSG_RETRYOPT

        if status.is_invisible() or self.addr[0] in settings['block_list']:
            tag |= c.IPMSG_NOADDLISTOPT
        elif status.is_afk():
            tag |= c.IPMSG_ABSENCEOPT

        if self.options['autoret']:
            tag |= c.IPMSG_AUTORETOPT

        if self.options['seal']:
            tag |= c.IPMSG_SECRETOPT
            if self.options['read_check']:
                tag |= c.IPMSG_READCHECKOPT
            if self.options['password']:
                tag |= c.IPMSG_PASSWORDOPT

        if engine.supports_utf8(self.addr):
            tag |= c.IPMSG_UTF8OPT
            encode_func = util.uni_to_utf8
        else:
            encode_func = util.uni_to_sjis

        msg = self.msg

        if self.atts and self.options['webshare']:
            msg += '\n\n' + webshare_manager.start(self.atts)

        contact = engine.get_contact(self.addr) or Contact(name='', group='', host='', addr=self.addr)

        msg = unicode(msg, 'utf8')
        msg = encode_func(msg)

        if self.options['encrypt']:
            rslt = self.encrypt(msg, contact)
            if not rslt:
                logger.debug('encrypt failed')
                return
            else:
                logger.debug('encrypt success')
                is_enc, msg = rslt
                if is_enc:
                    tag |= c.IPMSG_ENCRYPTOPT

        if self.atts and not self.options['webshare']:
            tag |= c.IPMSG_FILEATTACHOPT
            msg += '\x00' + encode_func(upload_manager.append_files(self.addr, self.atts))

        logger.debug('ready to make msg')
        raw = engine.make_msg(self.addr, tag, msg)
        self.packet = Packet.parse(raw, self.addr) 
        self.status = Message.INIT

        self.write_log()
Пример #2
0
 def rsps_entry(self, p, contact):
     if not status.is_invisible() and not status.is_off() and contact.addr[0] not in engine.block_ips:
         tag = c.IPMSG_ANSENTRY
         if status.is_afk():
             tag |= c.IPMSG_ABSENCEOPT
         msg = engine.get_name_ext()
         if engine.supports_utf8(p.addr) or settings['always_use_utf8']:
             tag |= c.IPMSG_UTF8OPT
         else:
             msg = util.utf8_to_sjis(msg)
         engine.send(contact.addr, tag, msg)
     if not engine.is_self(contact.addr):
         self.events.add(contact)
     self.req_pubkey(contact.addr)
Пример #3
0
    def try_make_packet(self):
        logger.debug('try_make_packet')
        tag = 0
        tag |= c.IPMSG_SENDMSG
        tag |= c.IPMSG_SENDCHECKOPT
        tag |= c.IPMSG_RETRYOPT

        if status.is_invisible() or self.addr[0] in settings['block_list']:
            tag |= c.IPMSG_NOADDLISTOPT
        elif status.is_afk():
            tag |= c.IPMSG_ABSENCEOPT

        if self.options['autoret']:
            tag |= c.IPMSG_AUTORETOPT

        if self.options['seal']:
            tag |= c.IPMSG_SECRETOPT
            if self.options['read_check']:
                tag |= c.IPMSG_READCHECKOPT
            if self.options['password']:
                tag |= c.IPMSG_PASSWORDOPT

        if engine.supports_utf8(self.addr):
            tag |= c.IPMSG_UTF8OPT
            encode_func = util.uni_to_utf8
        else:
            encode_func = util.uni_to_sjis

        msg = self.msg

        if self.atts and self.options['webshare']:
            msg += '\n\n' + webshare_manager.start(self.atts)

        contact = engine.get_contact(self.addr) or Contact(
            name='', group='', host='', addr=self.addr)

        msg = unicode(msg, 'utf8')
        msg = encode_func(msg)

        if self.options['encrypt']:
            rslt = self.encrypt(msg, contact)
            if not rslt:
                logger.debug('encrypt failed')
                return
            else:
                logger.debug('encrypt success')
                is_enc, msg = rslt
                if is_enc:
                    tag |= c.IPMSG_ENCRYPTOPT

        if self.atts and not self.options['webshare']:
            tag |= c.IPMSG_FILEATTACHOPT
            msg += '\x00' + encode_func(
                upload_manager.append_files(self.addr, self.atts))

        logger.debug('ready to make msg')
        raw = engine.make_msg(self.addr, tag, msg)
        self.packet = Packet.parse(raw, self.addr)
        self.status = Message.INIT

        self.write_log()