Beispiel #1
0
        /// <summary>
        /// Channel modes
        /// </summary>
        /// <param name="message"></param>
        public static void Parse324(BotMessage message)
        {
            int channelID = GetChannelID(message.MessageList[3]);

            ParseChannelModeString(message.MessageList[4], channelID);

            MBEvents.OnChannelListModified();
        }
Beispiel #2
0
        /// <summary>
        /// Channel topic
        /// </summary>
        /// <param name="message"></param>
        public static void Parse332(BotMessage message)
        {
            int channelID = GetChannelID(message.MessageList[3]);

            lock (channelSync)
                Channels[channelID].Topic = message.RawMessage.Substring(message.RawMessage.IndexOf(':', 1) + 1);

            MBEvents.OnChannelListModified();
        }
Beispiel #3
0
        public static void ParseTOPIC(BotMessage message)
        {
            int channelID = GetChannelID(message.ReplyTo);

            lock (channelSync)
                Channels[channelID].Topic = message.MessageString;

            MBEvents.OnChannelListModified();
        }
Beispiel #4
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();
        }
Beispiel #5
0
        void CwIRC_MessageReceived(object sender, string message)
        {
            BotMessage botMessage = new BotMessage(message, Nick);

            connectionTimer.Interval = 120000;

            MBEvents.OnNewRawIRC(this, botMessage.ToString());
            ProcessMessage(botMessage);
        }
Beispiel #6
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();
        }
Beispiel #7
0
        void Log(string data, string fileName)
        {
            DateTime date = DateTime.UtcNow;

            string time = date.ToString("[HH:mm]");

            MBEvents.OnNewFormattedIRC(this, string.Format("{0} {1} {2}", fileName, time, data));

            string filePath = Path.Combine(Settings.Instance.LogPath,
                                           string.Format("{0}{1}{2}{3}.txt", Settings.Instance.Server, Path.DirectorySeparatorChar, fileName, date.ToString(@"-yyyyMMdd")));

            Logger.Write(string.Format("{0} {1}", time, data), filePath.ToLowerInvariant());
        }
Beispiel #8
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();
            }
        }
Beispiel #9
0
        /*public static Thread cleaner = new Thread(CleanerExecution);
         *
         * public
         *
         * private static void CleanerExecution()
         * {
         *  while(true)
         *  {
         *      Thread.Sleep(100);
         *  }
         *
         * }*/

        public static void CallDestroyedObservers(this MonoBehaviour monoBehaviour)
        {
            lock (mbs)
            {
                if (mbs.ContainsKey(monoBehaviour))
                {
                    MBEvents mBEvents = mbs[monoBehaviour];
                    foreach (OnDestroyDelegate onDestroy in mBEvents.OnDestroys)
                    {
                        onDestroy.Invoke();
                    }

                    mBEvents.Clear();

                    mbs.Remove(monoBehaviour);
                }
            }
        }
Beispiel #10
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);
        }
Beispiel #11
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);
        }
Beispiel #12
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();
        }
Beispiel #13
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);
        }
Beispiel #14
0
        public static int GetChannelID(string channelName)
        {
            channelName = channelName.ToLowerInvariant();

            int channelID;

            lock (channelSync)
            {
                channelID = Channels.FindIndex(c => c.Name == channelName);

                if (channelID == -1)
                {
                    Channel channel = new Channel();
                    channel.Name = channelName;
                    Channels.Add(channel);
                    channelID = Channels.IndexOf(channel);

                    MBEvents.OnChannelListModified();
                }
            }

            return(channelID);
        }
Beispiel #15
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();
            }
        }