示例#1
0
 def lookupUserID(user):
     iter = []
     iter.append(userUtils.getID(user))
     iter.append(userUtils.getIDSafe(user))
     iter.append(userUtils.getIDSafe(user.lower()))
     iter.append(userUtils.getIDSafe(chat.fixUsernameForIRC(user).lower()))
     for result in iter:
         if result:
             return result
示例#2
0
    def banchoPartChannel(self, username, channel):
        """
		Let every IRC client connected to a specific client know that 'username' parted the channel from bancho

		:param username: username of bancho user
		:param channel: joined channel name
		:return:
		"""
        username = chat.fixUsernameForIRC(username)
        for _, value in self.clients.items():
            if channel in value.joinedChannels:
                value.message(":{} PART {}".format(username, channel))
示例#3
0
	def banchoMessage(self, sender, target, message):
		"""
		Send a message to IRC when someone sends it from bancho

		:param sender: sender username
		:param target: receiver username
		:param message: text of the message
		:return:
		"""
		sender = chat.fixUsernameForIRC(sender)
		target = chat.fixUsernameForIRC(target)
		if target.startswith("#"):
			# Public message
			for _, value in self.clients.items():
				if target in value.joinedChannels and value.IRCUsername != sender:
					value.message(":{} PRIVMSG {} :{}".format(sender, target, message))
		else:
			# Private message
			for _, value in self.clients.items():
				if value.IRCUsername == target and value.IRCUsername != sender:
					value.message(":{} PRIVMSG {} :{}".format(sender, target, message))
示例#4
0
    def banchoMessage(self, fro, to, message):
        """
		Send a message to IRC when someone sends it from bancho

		:param fro: sender username
		:param to: receiver username
		:param message: text of the message
		:return:
		"""
        fro = chat.fixUsernameForIRC(fro)
        to = chat.fixUsernameForIRC(to)
        if to.startswith("#"):
            # Public message
            for _, value in self.clients.items():
                if to in value.joinedChannels and value.IRCUsername != fro:
                    value.message(":{} PRIVMSG {} :{}".format(
                        fro, to, message))
        else:
            # Private message
            for _, value in self.clients.items():
                if value.IRCUsername == to and value.IRCUsername != fro:
                    value.message(":{} PRIVMSG {} :{}".format(
                        fro, to, message))
示例#5
0
	def passHandler(self, command, arguments):
		"""PASS command handler"""
		if command == "PASS":
			if len(arguments) == 0:
				self.reply461("PASS")
			else:
				# IRC token check
				m = hashlib.md5()
				m.update(arguments[0].encode("utf-8"))
				tokenHash = m.hexdigest()
				supposedUser = glob.db.fetch("SELECT users.username, users.id FROM users LEFT JOIN irc_tokens ON users.id = irc_tokens.userid WHERE irc_tokens.token = %s LIMIT 1", [tokenHash])
				if supposedUser:
					self.supposedUsername = chat.fixUsernameForIRC(supposedUser["username"])
					self.supposedUserID = supposedUser["id"]
					self.__handleCommand = self.registerHandler
				else:
					# Wrong IRC Token
					self.reply("464 :Password incorrect")
		elif command == "QUIT":
			self.disconnect()
示例#6
0
    def joinHandler(self, _, arguments):
        """JOIN command handler"""
        if len(arguments) < 1:
            self.reply461("JOIN")
            return

        # Get bancho token object
        token = glob.tokens.getTokenFromUsername(self.banchoUsername)
        if token is None:
            return

        # TODO: Part all channels
        if arguments[0] == "0":
            '''for (channelname, channel) in self.channels.items():
				self.message_channel(channel, "PART", channelname, True)
				self.channel_log(channel, "left", meta=True)
				server.remove_member_from_channel(self, channelname)
			self.channels = {}
			return'''
            return

        # Get channels to join list
        channels = arguments[0].split(",")

        for channel in channels:
            # Make sure we are not already in that channel
            # (we already check this bancho-side, but we need to do it
            # also here k maron)
            if channel.lower() in token.joinedChannels:
                continue

            # Attempt to join the channel
            response = chat.IRCJoinChannel(self.banchoUsername, channel)
            if response == 0:
                # Joined successfully
                self.joinedChannels.append(channel)

                # Let everyone in this channel know that we've joined
                self.messageChannel(channel,
                                    "{} JOIN".format(self.IRCUsername),
                                    channel, True)

                # Send channel description (topic)
                description = glob.channels.channels[channel].description
                if description == "":
                    self.replyCode(331, "No topic is set", channel=channel)
                else:
                    self.replyCode(332, description, channel=channel)

                # Build connected users list
                if "chat/{}".format(channel) not in glob.streams.streams:
                    self.reply403(channel)
                    continue
                users = glob.streams.streams["chat/{}".format(channel)].clients
                usernames = []
                for user in users:
                    if user not in glob.tokens.tokens:
                        continue
                    usernames.append(
                        chat.fixUsernameForIRC(
                            glob.tokens.tokens[user].username))
                usernames = " ".join(usernames)

                # Send IRC users list
                self.replyCode(353, usernames, channel="= {}".format(channel))
                self.replyCode(366, "End of NAMES list", channel=channel)
            elif response == 403:
                # Channel doesn't exist (or no read permissions)
                self.reply403(channel)
                continue