Ejemplo n.º 1
0
Archivo: irc.py Proyecto: BiohZn/sbncng
    def handle_connection_made(self):
        _BaseConnection.handle_connection_made(self)

        self.send_message('NOTICE', 'AUTH', '*** sbncng 0.1 - (c) 2011 Gunnar Beutner')
        self.send_message('NOTICE', 'AUTH', '*** Welcome to the brave new world.')

        try:
            self.send_message('NOTICE', 'AUTH', '*** Looking up your hostname')
            # TODO: need to figure out how to do IPv6 reverse lookups
            result = dns.resolve_reverse(socket.inet_aton(self.me.host))
            self.me.host = result[1]
            self.send_message('NOTICE', 'AUTH', '*** Found your hostname (%s)' % (self.me.host))
        except dns.DNSError:
            self.send_message('NOTICE', 'AUTH', '*** Couldn\'t look up your hostname, using ' + \
                             'your IP address instead (%s)' % (self.me.host))
Ejemplo n.º 2
0
	def accept(cls,network,sock,addr):
		logger.info('+client '+addr[0])
		connection = ClientConnection.spawn(sock)
		serveruid = network.local.uid
		sendraw = connection.send
		name = dname = None
		username = None
		hostname = addr[0]
		realname = None
		usermode = 0
		password = ''
		client = None
		try:
			ip = socket.inet_aton(hostname)
			try:	# rDNS [and identd]
				with Timeout(4,False):
					hostname = dns.resolve_reverse(ip)[1]
			except (dns.DNSError,IndexError):
				pass
			for line in connection:	# pre-registration loop
				try:
					arg,txt = line.split(':',1)
				except ValueError:
					arg = line.split()
				else:
					arg = arg.split()
					arg.append(txt)
				try:
					cmd = arg[0].lower()
				except IndexError:
					continue
				else:
					if cmd == 'pass':
						password = arg[1]
					elif cmd == 'nick':
						dname = arg[1]
						if cls.re_nick.match(dname) or dname[0] in '-0123456789':
							ex = IRCError.ErroneousNickname
							sendraw(':%s %s'%(serveruid,'%03d %s :%s'%(ex.code,dname,ex.message)))
						else:
							try:
								name = network.reserve_nick(dname[:cls.len_nick])
							except KeyError:
								ex = IRCError.NicknameInUse
								sendraw(':%s %s'%(serveruid,'%03d %s :%s'%(ex.code,dname,ex.message)))
					elif cmd == 'user':
						username = cls.re_user.sub('',arg[1])
						if username[0] in '-0123456789':
							username = '******'+username
						username = username[:cls.len_user]
						if len(username) < 1:
							username = ('~'+hexlify(ip).upper())[:cls.len_user-1]
						try:
							usermode = int(arg[2])
						except ValueError:
							usermode = 0
						realname = arg[3][:64]
					if None not in (name,username,realname):
						break
			else:
				connection.kill()
				logger.info('-client '+addr[0])
				return
		except GreenletExit:
			pass
		except:
			logger.exception('oops')
			connection.kill()
			logger.info('-client '+addr[0])
		else:
			client = cls(network,connection,name,username,hostname,realname,usermode,password)
			# FIXME: user mode
			client.start_later(0)
			network.client_add(client)
			logger.info('=client %s %s'%(addr[0],client.prefix))