コード例 #1
0
        public static void ParseJOIN(BotMessage message)
        {
            int channelID, userID = GetUserID(message.User.Name, message.MessageList[2].TrimStart(':'), out channelID);

            lock (channelSync)
                Channels[channelID].Users[userID].Hostmask = message.User.Hostmask;

            MBEvents.OnUserListModified();
        }
コード例 #2
0
        /// <summary>
        /// WHO reply
        /// </summary>
        /// <param name="message"></param>
        public static void Parse352(BotMessage message)
        {
            int channelID = GetChannelID(message.MessageList[3]);

            int userID = GetUserID(message.MessageList[7], channelID);

            lock (channelSync)
                Channels[channelID].Users[userID].Hostmask = message.MessageList[5];
            //Channels[channelID].Users[userID].Symbols = Regex.Replace(message.MessageList[8], @"[a-zA-Z]+", "");

            MBEvents.OnUserListModified();
        }
コード例 #3
0
        public static void ParsePART(BotMessage message, bool parterIsMe)
        {
            int channelID, userID = GetUserID(message.User.Name, message.MessageList[2].TrimStart(':'), out channelID);

            lock (channelSync)
                Channels[channelID].Users.RemoveAt(userID);

            MBEvents.OnUserListModified();
            if (parterIsMe)
            {
                lock (channelSync)
                    Channels.RemoveAt(channelID);

                MBEvents.OnChannelListModified();
            }
        }
コード例 #4
0
        public static List <string> ParseQUIT(BotMessage message)
        {
            List <string> quittedChannels = new List <string>();

            lock (channelSync)
            {
                foreach (Channel c in Channels)
                {
                    int userID = c.Users.FindIndex(u => u.Nick == message.User.Name.ToLowerInvariant());
                    if (userID != -1)
                    {
                        c.Users.RemoveAt(userID);
                        quittedChannels.Add(c.Name);
                    }
                }
            }
            MBEvents.OnUserListModified();

            return(quittedChannels);
        }
コード例 #5
0
        public static List <string> ParseNICK(BotMessage message)
        {
            List <string> channels = new List <string>();

            lock (channelSync)
            {
                foreach (Channel c in Channels)
                {
                    int userID = c.Users.FindIndex(u => u.Nick == message.User.Name.ToLowerInvariant());
                    if (userID != -1)
                    {
                        c.Users[userID].Nick = message.MessageList[2].TrimStart(':').ToLowerInvariant();
                        channels.Add(c.Name);
                    }
                }
            }
            MBEvents.OnUserListModified();

            return(channels);
        }
コード例 #6
0
        /// <summary>
        /// NAMES reply
        /// </summary>
        /// <param name="message"></param>
        public static void Parse353(BotMessage message)
        {
            int channelID = GetChannelID(message.MessageList[4]);

            string        nameString = message.RawMessage.Substring(message.RawMessage.LastIndexOf(':') + 1);
            List <string> names      = nameString.Split(' ').ToList();

            foreach (string name in names)
            {
                if (name == "")
                {
                    continue;
                }

                string nick = "", symbols = "";

                Match match = Regex.Match(name, @"([~@%&+]+)?(.+)");
                if (match.Groups.Count > 2)
                {
                    symbols = match.Groups[1].Value;
                    nick    = match.Groups[2].Value.ToLowerInvariant();
                }
                else
                {
                    nick = match.Groups[1].Value.ToLowerInvariant();
                }

                lock (channelSync)
                {
                    if (Channels[channelID].Users.FindIndex(u => u.Nick == nick) == -1)
                    {
                        User user = new User();
                        user.Nick    = nick;
                        user.Symbols = symbols;

                        Channels[channelID].Users.Add(user);
                    }
                }
            }
            MBEvents.OnUserListModified();
        }
コード例 #7
0
        static int GetUserID(string nick, int channelID)
        {
            nick = nick.ToLowerInvariant();

            int userID;

            lock (channelSync)
            {
                userID = Channels[channelID].Users.FindIndex(u => u.Nick == nick);

                if (userID == -1)
                {
                    User user = new User();
                    user.Nick = nick;
                    Channels[channelID].Users.Add(user);
                    userID = Channels[channelID].Users.IndexOf(user);

                    MBEvents.OnUserListModified();
                }
            }

            return(userID);
        }
コード例 #8
0
        public static void ParseMODE(BotMessage message)
        {
            string modeString = message.MessageList[3];

            if (message.MessageList.Count > 4) // User mode change
            {
                int channelID, userID = GetUserID(message.MessageList[4], message.MessageList[2], out channelID);

                bool addModes = modeString.StartsWith("+");
                modeString = modeString.TrimStart('+', '-');

                if (modeString.Contains("b"))
                {
                    return;                           // Ban message, ignore
                }
                if (addModes)
                {
                    lock (channelSync)
                    {
                        foreach (char mode in modeString)
                        {
                            if (!Channels[channelID].Users[userID].Modes.Contains(mode))
                            {
                                Channels[channelID].Users[userID].Modes.Add(mode);
                            }

                            if (mode == 'q')
                            {
                                Channels[channelID].Users[userID].Symbols += "~";
                            }
                            if (mode == 'o')
                            {
                                Channels[channelID].Users[userID].Symbols += "@";
                            }
                            if (mode == 'h')
                            {
                                Channels[channelID].Users[userID].Symbols += "%";
                            }
                            if (mode == 'v')
                            {
                                Channels[channelID].Users[userID].Symbols += "+";
                            }
                        }
                    }
                }
                else
                {
                    lock (channelSync)
                    {
                        foreach (char mode in modeString)
                        {
                            if (Channels[channelID].Users[userID].Modes.Contains(mode))
                            {
                                Channels[channelID].Users[userID].Modes.Remove(mode);
                            }

                            if (mode == 'q')
                            {
                                Channels[channelID].Users[userID].Symbols.Replace("~", "");
                            }
                            if (mode == 'o')
                            {
                                Channels[channelID].Users[userID].Symbols.Replace("@", "");
                            }
                            if (mode == 'h')
                            {
                                Channels[channelID].Users[userID].Symbols.Replace("%", "");
                            }
                            if (mode == 'v')
                            {
                                Channels[channelID].Users[userID].Symbols.Replace("+", "");
                            }
                        }
                    }
                }
                MBEvents.OnUserListModified();
            }
            else // Channel mode change
            {
                if (message.MessageList[2].ToLowerInvariant() == message.User.Name.ToLowerInvariant())
                {
                    return;
                }

                int channelID = GetChannelID(message.MessageList[2]);

                ParseChannelModeString(modeString, channelID);

                MBEvents.OnChannelListModified();
            }
        }