예제 #1
0
 public void RemoveNick(Nick nick)
 {
     if (Nicks.Contains(nick))
     {
         Nicks.Remove(nick);
     }
 }
예제 #2
0
 public void Copy(Nick nick)
 {
     Username = nick.Username;
     Realname = nick.Realname;
     Host     = nick.Host;
     Nickname = nick.Nickname;
     Password = nick.Password;
     Modes    = new List <UserMode>();
     Modes.AddRange(nick.Modes);
     Privileges = new List <PrivilegeMode>();
     Privileges.AddRange(nick.Privileges);
 }
예제 #3
0
파일: IRC.cs 프로젝트: Rohanyadav028/Combot
 /// <summary>
 /// Logs in the specified nick using their Username and Realname.
 /// </summary>
 /// <param name="serverName">The server's name.</param>
 /// <param name="nick">The nick information for the login.</param>
 public void Login(string serverName, Nick nick)
 {
     try
     {
         Nickname = nick.Nickname;
         Command.SendNick(nick.Nickname);
         Command.SendUser(nick.Username, nick.Host, serverName, nick.Realname);
     }
     catch (Exception ex)
     {
         ThrowException(ex, "Login Exception.");
     }
 }
예제 #4
0
        public List <Nick> GetNicks(List <string> nicknames)
        {
            List <Nick> foundNicks = new List <Nick>();

            foreach (string nickname in nicknames)
            {
                Nick foundNick = GetNick(nickname);
                if (foundNick != null)
                {
                    foundNicks.Add(foundNick);
                }
            }
            return(foundNicks);
        }
예제 #5
0
파일: IRC.cs 프로젝트: Rohanyadav028/Combot
 /// <summary>
 /// Update a nick to use their new nickname.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void HandleNickChange(object sender, NickChangeInfo e)
 {
     ChannelRWLock.EnterWriteLock();
     for (int i = 0; i < Channels.Count; i++)
     {
         Nick newNick = Channels[i].GetNick(e.OldNick.Nickname);
         if (newNick != null)
         {
             if (e.OldNick.Nickname == Nickname)
             {
                 Nickname = e.NewNick.Nickname;
             }
             newNick.Nickname = e.NewNick.Nickname;
         }
     }
     ChannelRWLock.ExitWriteLock();
 }
예제 #6
0
파일: IRC.cs 프로젝트: Rohanyadav028/Combot
 /// <summary>
 /// Update a nick's mode.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void HandleUserModeChange(object sender, UserModeChangeInfo e)
 {
     ChannelRWLock.EnterWriteLock();
     for (int i = 0; i < Channels.Count; i++)
     {
         Nick changedNick = Channels[i].GetNick(e.Nick.Nickname);
         if (changedNick != null)
         {
             foreach (UserModeInfo mode in e.Modes)
             {
                 if (mode.Set)
                 {
                     changedNick.AddMode(mode.Mode);
                 }
                 else
                 {
                     changedNick.RemoveMode(mode.Mode);
                 }
             }
         }
     }
     ChannelRWLock.ExitWriteLock();
 }
예제 #7
0
        public Nick GetNick(string nickname)
        {
            Nick foundNick = Nicks.Find(nick => nick.Nickname == nickname);

            return(foundNick);
        }
예제 #8
0
 public void AddNick(Nick nick)
 {
     Nicks.Add(nick);
 }
예제 #9
0
파일: IRC.cs 프로젝트: Rohanyadav028/Combot
        /// <summary>
        /// Update a channel's mode.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HandleChannelModeChange(object sender, ChannelModeChangeInfo e)
        {
            ChannelRWLock.EnterWriteLock();
            Channel channel = Channels.Find(chan => chan.Name == e.Channel);

            if (channel != null)
            {
                foreach (ChannelModeInfo mode in e.Modes)
                {
                    switch (mode.Mode)
                    {
                    case ChannelMode.v:
                    case ChannelMode.h:
                    case ChannelMode.o:
                    case ChannelMode.a:
                    case ChannelMode.q:
                        Nick changedNick = channel.GetNick(mode.Parameter);
                        if (changedNick != null)
                        {
                            PrivilegeMode priv;
                            Enum.TryParse(mode.Mode.ToString(), out priv);
                            if (mode.Set)
                            {
                                changedNick.AddPrivilege(priv);
                            }
                            else
                            {
                                changedNick.RemovePrivilege(priv);
                            }
                        }
                        break;

                    case ChannelMode.b:
                        if (mode.Set)
                        {
                            channel.AddBan(mode.Parameter);
                        }
                        else
                        {
                            channel.RemoveBan(mode.Parameter);
                        }
                        break;

                    case ChannelMode.k:
                        if (mode.Set)
                        {
                            channel.AddMode(mode.Mode);
                            channel.Key = mode.Parameter;
                        }
                        else
                        {
                            channel.RemoveMode(mode.Mode);
                            channel.Key = string.Empty;
                        }
                        break;

                    default:
                        if (mode.Set)
                        {
                            channel.AddMode(mode.Mode);
                        }
                        else
                        {
                            channel.RemoveMode(mode.Mode);
                        }
                        break;
                    }
                }
                Command.SendWho(channel.Name);
            }
            ChannelRWLock.ExitWriteLock();
        }
예제 #10
0
파일: IRC.cs 프로젝트: Rohanyadav028/Combot
        private void HandleReply(object sender, IReply e)
        {
            if (e.GetType() == typeof(ServerReplyMessage))
            {
                ServerReplyMessage msg = (ServerReplyMessage)e;
                switch (msg.ReplyCode)
                {
                // If we get a WHO response, we parse and add the nicks to the specified channel if they are not there already.
                case IRCReplyCode.RPL_WHOREPLY:
                    ChannelRWLock.EnterWriteLock();
                    string[] msgSplit = msg.Message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    if (msgSplit.GetUpperBound(0) > 0)
                    {
                        string target = msgSplit[0];
                        if (target.StartsWith("&") || target.StartsWith("#"))
                        {
                            if (msgSplit.GetUpperBound(0) >= 7)
                            {
                                string  nickname   = msgSplit[4];
                                string  realname   = msgSplit[7];
                                string  username   = msgSplit[1];
                                string  host       = msgSplit[2];
                                string  modeString = msgSplit[5];
                                Channel channel    = Channels.Find(chan => chan.Name == target);
                                if (channel != null)
                                {
                                    Nick nick      = channel.GetNick(nickname);
                                    bool nickFound = true;
                                    if (nick == null)
                                    {
                                        nickFound = false;
                                        nick      = new Nick();
                                    }
                                    nick.Nickname   = nickname;
                                    nick.Host       = host;
                                    nick.Realname   = realname;
                                    nick.Username   = username;
                                    nick.Modes      = new List <UserMode>();
                                    nick.Privileges = new List <PrivilegeMode>();
                                    char[] modeArr = modeString.ToCharArray();
                                    for (int i = 1; i <= modeArr.GetUpperBound(0); i++)
                                    {
                                        if (PrivilegeMapping.ContainsKey(modeArr[i].ToString()))
                                        {
                                            nick.Privileges.Add(PrivilegeMapping[modeArr[i].ToString()]);
                                        }
                                        else if (modeArr[i].ToString() == "*")
                                        {
                                            nick.Modes.Add(UserMode.o);
                                        }
                                        else
                                        {
                                            UserMode foundMode;
                                            bool     valid = Enum.TryParse(modeArr[i].ToString(), false, out foundMode);
                                            if (valid)
                                            {
                                                nick.Modes.Add(foundMode);
                                            }
                                        }
                                    }
                                    if (!nickFound)
                                    {
                                        channel.AddNick(nick);
                                    }
                                }
                            }
                        }
                    }
                    ChannelRWLock.ExitWriteLock();
                    break;

                // On a topic reply, update the channel's topic
                case IRCReplyCode.RPL_TOPIC:
                    ChannelRWLock.EnterWriteLock();
                    string[] topicSplit = msg.Message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    if (topicSplit.GetUpperBound(0) > 0)
                    {
                        string  topicChan    = topicSplit[0];
                        Channel topicChannel = Channels.Find(chan => chan.Name == topicChan);
                        if (topicChannel != null)
                        {
                            topicChannel.Topic = topicSplit[1].Remove(0, 1);
                        }
                    }
                    ChannelRWLock.ExitWriteLock();
                    break;

                default:
                    break;
                }
            }
            else
            {
                ServerErrorMessage msg = (ServerErrorMessage)e;
            }
        }