def handle_data_received(self, data): data = self.decode(data) logger.debug('Received client data: %s', data) for line in data.rstrip().splitlines(): verb, message = line.split(" ", 1) if verb == "QUIT": pass elif verb == "PASS": access_token = message.split(" ")[0] self.network = yield from self.get_network(access_token) if self.network is None: logger.debug( 'Client authentiacation failed for token: {}'.format( access_token)) self.unregister_client(self.network.id, self) self.transport.write('Authentication failed') self.transport.close() else: client = yield from ClientStore.create({ 'socket': '{}:{}'.format(self.host, self.port), 'network_id': self.network.id, 'user_id': self.network.user_id }) self.client_id = client.id elif self.forward: self.forward(line) if self.forward is None: self.forward = yield from self.get_bot_handle(self.network, self)
def handle_data_received(self, data): data = self.decode(data) logger.debug('Received client data: %s', data) for line in data.rstrip().splitlines(): tokens = line.split(" ", 1) verb = tokens[0] if verb == "QUIT": pass elif verb == "PASS": message = tokens[1] access_token = message.split(" ")[0] self.network = yield from self.get_network(access_token) if self.network is None: logger.debug( 'Client authentiacation failed for token: {}'.format( access_token)) self.unregister_client(self.network.id, self) self.transport.write('Authentication failed') self.transport.close() else: client = yield from ClientStore.create({ 'socket': '{}:{}'.format(self.host, self.port), 'network_id': self.network.id, 'user_id': self.network.user_id }) self.client_id = client.id elif self.forward: self.forward(line) if self.forward is None: self.forward = yield from self.get_bot_handle( self.network, self)
def handle_data_received(self, data): data = self.decode(data) logger.debug('Received client data: %s', data) for line in data.rstrip().splitlines(): tokens = line.split(" ", 1) verb = tokens[0] if verb == "QUIT": pass elif verb == "PASS": message = tokens[1] access_token = message.split(" ")[0] self.network = yield from self.get_network(access_token) if self.network is None: logger.debug( 'Client authentiacation failed for token: {}'.format( access_token)) self.unregister_client(self.network.id, self) self.transport.write('Authentication failed') self.transport.close() return else: client = yield from ClientStore.create({ 'socket': '{}:{}'.format(self.host, self.port), 'network_id': self.network.id, 'user_id': self.network.user_id }) self.client_id = client.id elif self.bot: logger.debug( 'Forwarding {}\t {}'.format(self.bot, line)) self.bot.raw(line) if line.lstrip().startswith('PRIVMSG'): words = line.split() # Dispatch sent message to sibling clients for record if words[1].startswith('#'): mask = ':{nick}!~{realname}@* '.format( nick=self.bot.nick, realname=self.bot.config.get('realname', '') ) for client in self.get_sibling_clients(self): client.send(mask + line) if self.bot is None: self.bot = yield from self.get_bot_handle( self.network, self) if self.bot is None: self.transport.write('Bot not connected') self.transport.close() asyncio.Task(ClientStore.delete({'id': self.client_id}))