コード例 #1
0
    def pkt_part(self, event):
        """ Received a part packet.
            
            Similar to ``pkt_join``. This method determines whether or
            not the client is being kicked off the server.
        """
        if event.arguments['ns'] in self.channel.keys():
            del self.channel[event.arguments['ns']]

        if len(self.channel) > 0:
            return

        if 'r' in event.arguments:
            if event.arguments['r'] in ('bad data', 'bad msg', 'msg too big'
                                        ) or 'killed:' in event.arguments['r']:
                self.handle_pkt(
                    Packet('disconnect{0}e={1}{2}{3}'.format(
                        "\n", event.arguments['r'], "\n", "\n")), time.time())
                return

        if event.arguments['e'] != 'ok':
            return

        if self.channel or self.flag.disconnecting or self.flag.quitting:
            return

        self.handle_pkt(Packet('disconnect\ne=no joined channels\n\n'),
                        time.time())
コード例 #2
0
 def process_property(self, data):
     """ Called when receive a property packet for the channel.
         
         This method makes sure that the data is stored in the right
         places in the object.
     """
     if data.arguments['p'] == 'title':
         self.title.content = data.arguments['value']
         self.title.by = data.arguments['by']
         self.title.ts = data.arguments['ts']
     
     if data.arguments['p'] == 'topic':
         self.topic.content = data.arguments['value']
         self.topic.by = data.arguments['by']
         self.topic.ts = data.arguments['ts']
     
     if data.arguments['p'] == 'privclasses':
         self.pc = Packet(data.arguments['value'], ':').args
         self.pc_order = sorted(self.pc.keys(), key=int)
         self.pc_order.reverse()
     
     if data.arguments['p'] == 'members':
         member = Packet(data.arguments['value'])
         while member.cmd != None and len(member.args) > 0:
             self.register_user(member)
             member = Packet(member.body)
コード例 #3
0
    def dataReceived(self, data):
        """ Called by twisted when data is received.
            
            The data received is added to out buffer. If there are any full
            packets in the buffer, these packets are sent to the
            :py:class:`ChatClient <dAmnViper.base.ChatClient>` instance to be
            parsed properly.
            
            Any event handling relating to specific packets is done in the
            ``ChatClient`` instance.
        """

        # Tell the client some data has arrived. Woo...
        self.client.dataReceived(data)

        # Split on null.
        self.__buffer += data
        raw = self.__buffer.split('\0')
        self.__buffer = raw.pop()

        for chunk in raw:
            packet = Packet(chunk)

            # If it's a ping packet, send a pong straight away!
            if packet.cmd == 'ping':
                self.send_packet('pong\n')

            # Let the client do whatever it needs to with the packet.
            self.client.handle_pkt(packet, time.time())
コード例 #4
0
 def pkt_recv_join(self, event):
     """ Received a recv_join packet.
         
         This happens when a user joins a channel in which the client
         is also present.
         
         This method simply stores information about the user that
         just joined.
     """
     self.channel[event.arguments['ns']].register_user(
         Packet(event.arguments['info']), event.arguments['user'])
コード例 #5
0
    def pkt_kicked(self, event):
        """ Received a kicked packet.
            
            This happens when the client is kicked from a channel.
            
            Here we automatically rejoin the channel if we are permitted
            to do so.
        """
        del self.channel[event.arguments['ns']]
        if self.flag.disconnecting or self.flag.quitting:
            return

        if 'r' in event.arguments:
            if 'autokicked' in event.arguments['r'].lower(
            ) or 'not privileged' in event.arguments['r'].lower():
                if len(self.channel) > 0:
                    return
                self.handle_pkt(Packet('disconnect\ne=no joined channels\n\n'),
                                time.time())
                return

        if self.flag.autorejoin:
            self.join(event.arguments['ns'])
コード例 #6
0
    def pkt_join(self, event):
        """ Received a join packet.
            
            This is sent by the server when the client tries to join a
            channel on the server.
            
            If the join was successful, a :py:class:`Channel object
            <dAmnViper.data.Channel>` is created for the channel and
            stored in the ``channel`` attribute of the client.
            
            If the join failed, the client disconnects if there are no
            other joined channels. (``naive``)
        """
        if event.arguments['e'] == 'ok':
            ns = event.arguments['ns']
            self.channel[ns] = Channel(ns, self.deform_ns(ns))
            return

        if len(self.channel) > 0:
            return

        self.handle_pkt(Packet('disconnect\ne=no joined channels\n\n'),
                        time.time())