protected virtual void OnRawNumeric(Int32 numeric, string line)
        {
            // TODO: Trigger a RawNumericReceivedEvent event
            //Console.WriteLine("{0} {1}", numeric.ToString("[000]"), line);
            string[] toks = line.Split(' ');

            Match m;
            switch (numeric)
            {
                case 001:
                    {
                        ConnectionEstablishedEvent.Raise(this, EventArgs.Empty);
                    } break;
                case 005:
                    {
                        if ((m = Patterns.rUserPrefix.Match(line)).Success)
                        {
                            m_AccessModes = m.Groups[1].Value;
                            m_AccessPrefixes = m.Groups[2].Value;
                            rRawNames = new Regex(String.Format(@"([{0}]?)(\S+)", m_AccessPrefixes));
            #if DEBUG
                            m_Logger.Debug("Regex Pattern: {0}", rRawNames.ToString());
                            m_Logger.Debug("Access Modes: {0} | Access Prefixes: {1}", m_AccessModes, m_AccessPrefixes);
            #endif
                        }

                        if ((m = Patterns.rChannelModes.Match(line)).Success)
                        {
                            m_ChannelModes = m.Groups[1].Value;
                        }

                    } break;
                case 353:
                    {
                        Channel c = GetChannel(toks[4]);                                                // Get the channel from the collection of channels

                        string sub = line.Substring(line.IndexOf(":", 1)).Remove(0, 1);                 // Get the list of nicks out of the line.
                        string[] names = sub.Split(' ');                                                // Split the list into an array.

                        foreach (var name in names)
                        {
                            if (String.IsNullOrEmpty(name) || String.IsNullOrEmpty(name))
                            {
                                continue;
                            }

                            if ((m = rRawNames.Match(name)).Success)
                            {                                                                           // Parse the nicks and match them via RegEx
                                var nick = m.Groups[2].Value;                                           // capture the nick
                                var prefix = (String.IsNullOrEmpty(m.Groups[1].Value) ? '\0' : m.Groups[1].Value[0]);       // and the prefix

                                if (c.Users.ContainsKey(nick))
                                {
                                    c.Users[nick].AddPrefix(prefix);                                             // Update the nick's prefix, or
                                }
                                else
                                {
                                    PrefixList l = new PrefixList(this);
                                    l.AddPrefix(prefix);
                                    c.Users.Add(nick, l);                                          // add it to the list if they don't exist.
                                }
            #if DEBUG
                                Send("PRIVMSG {0} :Name: {1} - Access: {2}", c.Name, nick, prefix);     // Debug output for reference.
            #endif
                            }

                        }
                    } break;

                case 367:               // +b
                case 348:               // +e
                case 346:               // +I
                    {
                        string setBy = toks[5];
                        DateTime setOn = (Double.Parse(toks[6]).ToDateTime());
                        string mask = toks[4];
            #if DEBUG
                        System.Diagnostics.Debug.WriteLine("debug: [ListMode:{0}] Set By: {1} | Mask: {2} | Channel: {3}", numeric, toks[5], toks[4], toks[3]);
                        System.Diagnostics.Debug.WriteLine("\t\t Set On: {0}", setOn);
            #endif

                        OnListMode(numeric, toks[3], toks[5], setOn, toks[4]);
                    } break;

                case 332:
                    {
                        // TODO: channel topic
                    } break;

            }
        }
예제 #2
0
        /*
        protected virtual void OnNoticeReceived(string input)
        {
            string[] toks = input.Split(' ');
            Match m, n;
            string sender = "", message = "";
            if ((m = Patterns.rUserHost.Match(toks[0])).Success)
            {
                Channel target;
                message = input.Substring(input.IndexOf(':', 2) + 1);
                sender = m.Groups[1].Value;
                // priv. notice
                if ((n = Patterns.rChannelRegex.Match(toks[2])).Success)
                {
                    // channel
                    target = GetChannel(n.Groups[1].Value);
                    ChannelNoticeReceivedEvent.Raise(this, new ChannelMessageReceivedEventArgs(target, message, sender, true));
                }
                else
                {
                    // private notice
                    PrivateNoticeReceivedEvent.Raise(this, new PrivateMessageReceivedEventArgs(sender, message, true));
                }
            }
            else
            {
                // Server Notice
                Console.WriteLine("(S)NOTICE: {0}", input.Substring(input.IndexOf(toks[2])));
            }
        }
         */
        /// <summary>
        /// Internally handles one specific mode change on a channel
        /// </summary>
        /// <param name="chan">The Channel on which the change happened.</param>
        /// <param name="mode">The mode the change happened with.</param>
        /// <param name="parameter">The parameter for this mode (or null)</param>
        /// <param name="type">The type of mode this is.</param>
        /// <param name="isSet">If this mode was set. (False if it was unset)</param>
        protected virtual void HandleChannelMode(Channel chan, char mode, string parameter, ChanmodeType type, bool isSet)
        {
            #if DEBUG
            System.Diagnostics.Debug.WriteLine("Mode '{0}' is being {1} with parameter: {2} (Type: {3})",mode, isSet ? "set" : "unset", parameter, type );
            #endif

            if (type == ChanmodeType.ACCESS)
            {
                PrefixList list = null;
                foreach (var kvp in chan.Users)
                {
                    if (kvp.Key.EqualsIgnoreCase(parameter))
                    {
                        list = kvp.Value;
                    }
                }
                if (list == null)
                {
            #if DEBUG
            //                    throw new Exception("HandleChannelMode Access mode was set on a user who was not in the channel's list (chan.Users).");
            #endif
                    list = new PrefixList(this);
                    chan.Users.Add(parameter, list);
                }

                if (isSet)
                {
                    list.AddPrefix(list.ModeToPrefix(mode));
                }
                else
                {
                    list.RemovePrefix(list.ModeToPrefix(mode));
                }

                if (StrictNames)
                {
                    Send("NAMES {0}", chan.Name);
                }

            }
            else if (type != ChanmodeType.LIST)
            {
                if (isSet)
                {
                    chan.Modes.Remove(mode);  // If it is already there, it needs to be updated most likely. Or the IRCD is broken and this is irrelevent.
                    chan.Modes.Add(mode, parameter);
                }
                else
                {
                    chan.Modes.Remove(mode);
                }
            }
            else // if type is LIST
            {
                List<ListMode> list = chan.ListModes;

                ListMode lMode;

                if ((lMode = list.Find(x => x.Mask.EqualsIgnoreCase(parameter))) == null)
                {
                    if (!isSet)
                    {
                        return;
                    }

                    lMode = new ListMode(DateTime.Now, parameter, "", mode);
                    list.Add(lMode);
                }

                if (StrictModes)
                {
                    Send("MODE {0} +{1}", chan.Name, mode);
                }

                /*List<string> list;
                if (!chan.ListModes.TryGetValue(mode, out list))
                {
                    if (!isSet) // If we are unsetting a value but had no list...then clearly we had no value already stored :)
                        return;
                    list = new List<string>();
                    chan.ListModes.Add(mode, list);
                }
                // If we are here, we should have the list of this mode
                list.RemoveAll(x => x.EqualsIgnoreCase(parameter));
                if (isSet)
                {
                    list.Add(parameter);
                }*/

            }
        }