Exemplo n.º 1
0
    def get_network_handle(self, username, password, client):
        network_data = network_store.get('{}:{}'.format(username, password))
        if network_data is None:
            return
        key = '{}:{}'.format(username, network_data['name'])
        network = self.networks.get(key)
        if network is None:
            logger.debug(
                'New network connection: %s, %s, %s', username,
                network_data['name'], network_data
            )
            loop = asyncio.get_event_loop()
            coro = loop.create_connection(
                lambda: Network(
                    username, network_data['name'], network_data['nickname'],
                    network_data['username'], network_data['password'],
                    register=self.register_network),
                network_data['hostname'], network_data['port'])
            asyncio.async(coro)
        else:
            logger.debug('Reusing network connection: %s, %s, %s',
                         username, network_data['name'], network_data)
            network.send('USER', username, network_data['usermode'], '*',
                         ':{}'.format(network_data['realname']))
            if network_data.get('password'):
                network.send('PASS', network_data['password'])

        def forward(line):
            network = self.networks.get(key)
            logger.debug('Forwarding {}->{}\n %s'.format(username, network),
                         line.decode())
            network.send(*[line])

        self.register_client(username, password, client)
        return forward
Exemplo n.º 2
0
 def register_client(self, username, password, client):
     network_data = network_store.get(
         '{}:{}'.format(username, password))
     if network_data is None:
         return
     key = '{}:{}'.format(username, network_data['name'])
     clients = self.clients.get(key)
     if clients is None:
         clients = set()
         self.clients[key] = clients
     clients.add(client)
     logger.debug('Registered new client: %s, %s', key, clients)