示例#1
0
        private void ParseChannelMode(IIrcUser sender, string mode)
        {
            bool setTrue = mode[0] == '+';

            if (!setTrue && mode[0] != '-')
            {
                return;
            }
            IrcChannelUserMode senderMode = sender.ChannelModes[Channel];
            string             newMode    = setTrue ? "+" : "-";

            foreach (char ch in mode)
            {
                if (ch == 'a' && senderMode.IsOperator)
                {
                    IsAnnonymous = setTrue;
                    newMode     += "a";
                }
                if (ch == 'i' && senderMode.IsOperator)
                {
                    IsInviteOnly = setTrue;
                    newMode     += "i";
                }
                if (ch == 'm' && senderMode.IsHalfOp)
                {
                    IsVoiceOnly = setTrue;
                    newMode    += "m";
                }
                if (ch == 'q' && senderMode.IsAdmin)
                {
                    IsQuiet  = setTrue;
                    newMode += "q";
                }
                // RFC 2811: The channel flags 'p' and 's' MUST NOT both be set at the same time.
                if (ch == 'p' && senderMode.IsAdmin && !IsSecret)
                {
                    IsPrivate = setTrue;
                    newMode  += "p";
                }
                if (ch == 's' && senderMode.IsAdmin && !IsPrivate)
                {
                    IsSecret = setTrue;
                    newMode += "s";
                }
                // End RFC 2811.

                if (ch == 't' && senderMode.IsHalfOp)
                {
                    OpSetTopic = setTrue;
                    newMode   += "t";
                }
            }
            UpdateChannelMode(sender, newMode);
        }
示例#2
0
        private void ParseMember(IIrcUser sender, IIrcUser user, string mode)
        {
            bool setTrue = mode[0] == '+';

            if (!setTrue && mode[0] != '-')
            {
                return;
            }
            IrcChannelUserMode senderMode = Channel.GetUserMode(sender);
            IrcChannelUserMode userMode   = Channel.GetUserMode(user);
            bool   isSelf  = (sender == user && !setTrue);
            string newMode = setTrue ? "+" : "-";

            foreach (char ch in mode)
            {
                if (ch == 'a' && (senderMode.IsAdmin || isSelf))
                {
                    userMode.IsAdmin = setTrue;
                    newMode         += 'a';
                }
                if (ch == 'o' && (senderMode.IsOperator || isSelf))
                {
                    userMode.IsOperator = setTrue;
                    newMode            += 'o';
                }
                if (ch == 'h' && (senderMode.IsHalfOp || isSelf))
                {
                    userMode.IsHalfOp = setTrue;
                    newMode          += 'h';
                }
                if (ch == 'v' && (senderMode.IsHalfOp || isSelf))
                {
                    userMode.IsVoiced = setTrue;
                    newMode          += 'v';
                }
            }
            UpdateChannelMode(sender, newMode + " " + user.Nick);
        }
示例#3
0
        private void ParseAccessMode(IIrcUser sender, string mode, string mask)
        {
            bool setTrue = mode[0] == '+';

            if (!setTrue && mode[0] != '-')
            {
                return;
            }

            if (string.IsNullOrEmpty(mask))
            {
                if (!setTrue)
                {
                    return;
                }
                List <string>        list = null;
                IrcNumericResponceId numeric;
                IrcNumericResponceId endNumeric;
                switch (mode[1])
                {
                case 'b':
                    list       = BanMask;
                    numeric    = IrcNumericResponceId.RPL_BANLIST;
                    endNumeric = IrcNumericResponceId.RPL_ENDOFBANLIST;
                    break;

                case 'I':
                    list       = InviteMask;
                    numeric    = IrcNumericResponceId.RPL_INVITELIST;
                    endNumeric = IrcNumericResponceId.RPL_ENDOFINVITELIST;
                    break;

                case 'e':
                    list       = ExceptionMask;
                    numeric    = IrcNumericResponceId.RPL_EXCEPTLIST;
                    endNumeric = IrcNumericResponceId.RPL_ENDOFEXCEPTLIST;
                    break;

                default:
                    return;
                }
                string items = string.Join(" ", list);
                sender.Write(new IrcNumericResponce
                {
                    NumericId = numeric,
                    To        = Channel.Name,
                    Extra     = items
                });
                sender.Write(new IrcNumericResponce
                {
                    NumericId = endNumeric,
                    To        = Channel.Name,
                    Message   = "End of list"
                });
                return;
            }

            IrcChannelUserMode senderMode = Channel.GetUserMode(sender);

            if (!senderMode.IsOperator)
            {
                return;
            }

            List <string> masks = mask.Split(' ').ToList();
            Action <IEnumerable <string> > action = null;

            if (mode[1] == 'b')
            {
                if (setTrue)
                {
                    masks.RemoveGroup(BanMask);
                }
                action = setTrue ? BanMask.AddRange : (Action <IEnumerable <string> >)BanMask.RemoveGroup;
            }
            if (mode[1] == 'I')
            {
                if (setTrue)
                {
                    masks.RemoveGroup(InviteMask);
                }
                action = setTrue ? InviteMask.AddRange : (Action <IEnumerable <string> >)InviteMask.RemoveGroup;
            }
            if (mode[1] == 'e')
            {
                if (setTrue)
                {
                    masks.RemoveGroup(ExceptionMask);
                }
                action = setTrue ? ExceptionMask.AddRange : (Action <IEnumerable <string> >)ExceptionMask.RemoveGroup;
            }
            if (action == null)
            {
                return;
            }
            if (masks.Count == 0)
            {
                return;
            }
            action(masks);
            UpdateChannelMode(sender, mode + " " + string.Join(" ", masks));
        }
示例#4
0
        /// <summary>
        /// Joins this IrcChannel, provided the key is correct.
        /// </summary>
        public void Join(IIrcUser client, string key = "")
        {
            if (Mode.Key != key)
            {
                return;
            }

            if (!client.ChannelModes.ContainsKey(this))
            {
                client.ChannelModes.Add(this, new IrcChannelUserMode());
            }
            IrcChannelUserMode mode = client.ChannelModes[this];

            if (Mode.IsInviteOnly && !mode.IsInvited)
            {
                if (Mode.InviteMask.Where(mask => mask.PatternMatch(client.UserString)).Count() == 0)
                {
                    client.Write(new IrcNumericResponce
                    {
                        NumericId = IrcNumericResponceId.ERR_INVITEONLYCHAN,
                        To        = Name,
                        Message   = "You are not invited."
                    });
                    return;
                }
            }
            if (Mode.BanMask.Where(mask => mask.PatternMatch(client.UserString)).Count() >= 1)
            {
                if (Mode.ExceptionMask.Where(mask => mask.PatternMatch(client.UserString)).Count() == 0)
                {
                    // TODO: deny access.
                    return;
                }
            }
            if (Users.Count == 0 && (Created - DateTime.Now).TotalSeconds < 5)
            {
                // Flag the first member as the channel's creator.
                mode.IsCreator = true;
            }
            Users.Add(client);

            Command(client, "JOIN", Name);
            if (string.IsNullOrEmpty(Mode.Topic))
            {
                client.Write(new IrcNumericResponce
                {
                    NumericId = IrcNumericResponceId.RPL_NOTOPIC,
                    To        = Name,
                    Message   = "No topic"
                });
            }
            else
            {
                client.Write(new IrcNumericResponce
                {
                    NumericId = IrcNumericResponceId.RPL_TOPIC,
                    To        = Name,
                    Message   = Mode.Topic
                });
            }
            IrcCommand.Find("names").Run(client, new IrcMessage {
                Params = new string[] { Name }
            });
        }