예제 #1
0
    def who(self, sock, source, mask):
        if mask.startswith(u"#"):
            channel = models.Channel.objects.filter(name=mask).first()
            if channel is None:
                return ERR_NOSUCHCHANNEL(mask)

            replies = []
            for user in channel.users:
                userinfo = user.userinfo

                status = u("G") if user.away else u("H")
                status += (u("*") if user.oper else u(""))
                status += (u("@") if user in channel.operators else u(""))
                status += (u("+") if user in channel.voiced else u(""))

                replies.append(
                    RPL_WHOREPLY(channel.name, userinfo.user, userinfo.host,
                                 self.parent.server.host, user.nick, status, 0,
                                 userinfo.name or ""))
            replies.append(RPL_ENDOFWHO(mask))
            return replies
        else:
            user = models.User.objects.filter(nick=mask).first()
            if user is None:
                return ERR_NOSUCHNICK(mask)

            userinfo = user.userinfo

            status = u("G") if user.away else u("H")
            status += (u("*") if user.oper else u(""))

            return (RPL_WHOREPLY(mask, userinfo.user, userinfo.host,
                                 self.parent.server.host, user.nick, status, 0,
                                 userinfo.naem), RPL_ENDOFWHO(mask))
예제 #2
0
파일: message.py 프로젝트: spaceone/charla
    def on_privmsg_or_notice(self, event, sock, source, target, message):
        user = User.objects.filter(sock=sock).first()

        prefix = user.prefix or joinprefix(*source)

        if target.startswith(u"#"):
            channel = Channel.objects.filter(name=target).first()
            if channel is None:
                return ERR_NOSUCHCHANNEL(target)

            if "n" in channel.modes:
                if not user.oper and user not in channel.users:
                    return ERR_CANNOTSENDTOCHAN(channel.name)

            if "m" in channel.modes:
                if not user.oper and user not in chain(channel.operators,
                                                       channel.voiced):
                    return ERR_CANNOTSENDTOCHAN(channel.name)

            self.notify(channel.users,
                        _Message(u"PRIVMSG", target, message, prefix=prefix),
                        user)
        else:
            user = User.objects.filter(nick=target).first()
            if user is None:
                return ERR_NOSUCHNICK(target)

            return reply(
                user.sock,
                _Message(event.name.upper(), target, message, prefix=prefix))
예제 #3
0
파일: ircd.py 프로젝트: xmonader/circuits
 def mode(self, sock, source, mask, mode=None, params=None):
     if mask.startswith('#'):
         if mask not in self.channels:
             return self.fire(reply(sock, ERR_NOSUCHCHANNEL(mask)))
         channel = self.channels[mask]
         if not params:
             self.fire(reply(sock, RPL_CHANNELMODEIS(channel.name, channel.mode)))
     elif mask not in self.users:
         return self.fire(reply(sock, ERR_NOSUCHNICK(mask)))
예제 #4
0
    def who(self, sock, source, mask):
        if mask.startswith("#"):
            if mask not in self.channels:
                return self.fire(reply(sock, ERR_NOSUCHCHANNEL(mask)))

            channel = self.channels[mask]

            for user in channel.users:
                self.fire(reply(sock, RPL_WHOREPLY(user, mask, self.host)))
            self.fire(reply(sock, RPL_ENDOFWHO(mask)))
        else:
            if mask not in self.nicks:
                return self.fire(reply(sock, ERR_NOSUCHNICK(mask)))

            user = self.nicks[mask]

            self.fire(reply(sock, RPL_WHOREPLY(user, mask, self.host)))
            self.fire(reply(sock, RPL_ENDOFWHO(mask)))
예제 #5
0
파일: admin.py 프로젝트: MrSwiss/charla
    def kill(self, sock, source, target, reason=None):
        user = User.objects.filter(sock=sock).first()
        if not user.oper:
            return ERR_NOPRIVILEGES()

        nick = User.objects.filter(nick=target).first()
        if nick is None:
            return ERR_NOSUCHNICK(target)

        reason = u("Killed: {0}").format(reason) if reason else nick.nick

        self.fire(
            response.create("quit",
                            nick.sock,
                            nick.source,
                            reason,
                            disconnect=False))
        self.fire(reply(nick.sock, ERROR(reason)), "server")
        Timer(1, close(nick.sock), "server").register(self)
예제 #6
0
    def privmsg(self, sock, source, target, message):
        user = self.users[sock]

        if target.startswith("#"):
            if target not in self.channels:
                return self.fire(reply(sock, ERR_NOSUCHCHANNEL(target)))

            channel = self.channels[target]

            self._notify(
                channel.users,
                Message("PRIVMSG", target, message, prefix=user.prefix), user)
        else:
            if target not in self.nicks:
                return self.fire(reply(sock, ERR_NOSUCHNICK(target)))

            self.fire(
                reply(self.nicks[target].sock,
                      Message("PRIVMSG", target, message, prefix=user.prefix)))
예제 #7
0
    def whois(self, sock, source, *args):
        if not args:
            return ERR_NONICKNAMEGIVEN()

        args = iter(args)

        mask = next(args, None)

        user = models.User.objects.filter(nick=mask).first()
        if user is None:
            return ERR_NOSUCHNICK(mask)

        userinfo = user.userinfo
        server = self.parent.server

        channels = []
        for channel in user.channels:
            prefix = ""
            if user in channel.operators:
                prefix += "@"
            if user in channel.voiced:
                prefix += "+"
            channels.append(u"{0}{1}".format(prefix, channel.name))

        # Force :<channels>
        if len(channels) == 1:
            channels.append("")

        replies = []

        replies.append(
            RPL_WHOISUSER(user.nick, userinfo.user, userinfo.host,
                          userinfo.name))
        replies.append(RPL_WHOISCHANNELS(user.nick, channels))
        replies.append(RPL_WHOISSERVER(user.nick, server.host, server.info))

        if user.oper:
            replies.append(RPL_WHOISOPERATOR(user.nick))

        replies.append(RPL_ENDOFWHOIS(user.nick))

        return replies
예제 #8
0
파일: mode.py 프로젝트: spaceone/charla
    def mode(self, sock, source, *args):
        """MODE command

        This command allows the user to display modes of another user
        or channel and set modes of other users and channels.
        """

        if not args:
            return ERR_NEEDMOREPARAMS(u"MODE")

        user = User.objects.filter(sock=sock).first()

        args = iter(args)
        mask = next(args)

        if mask.startswith(u("#")):
            channel = Channel.objects.filter(name=mask).first()
            if channel is None:
                return ERR_NOSUCHCHANNEL(mask)

            mode = next(args, None)
            if mode is None:
                return RPL_CHANNELMODEIS(channel.name,
                                         u("+{0}").format(channel.modes))

            return self._process_channel_modes(user, channel,
                                               [mode] + list(args))
        else:
            nick = User.objects.filter(nick=mask).first()
            if nick is None:
                return ERR_NOSUCHNICK(mask)

            if user.nick != nick.nick:
                return ERR_USERSDONTMATCH()

            mode = next(args, None)
            if mode is None:
                return RPL_UMODEIS(u("+{0}").format(nick.modes))

            return process_user_modes(nick, [mode] + list(args))