Example #1
0
        public void AddPrefix(string nick, char prefix)
        {
            ChanUser cu = GetUserOnChannelByNick(nick);

            if (cu == null)
            {
                return;
            }
            RemoveUserFromChannel(cu);
            try
            {
                char[] stmp = Server.ISupport.PREFIX_Characters.ToCharArray();
                for (int i = 0; i < stmp.Length; i++)
                {
                    if (stmp[i] != prefix && cu.Prefixes.IndexOf(stmp[i]) < 0)
                    {
                        stmp[i] = ' ';
                    }
                }
                cu.Prefixes = (new string(stmp)).Replace(" ", "");
            }
            finally
            {
                // No matter what put cu back where it came from if possible.
                AddUserToChannel(cu);
                this.lstUsers.Refresh();
            }
        }
Example #2
0
 public void AddUserToChannel(ChanUser cu)
 {
     try
     {
         for (int i = 0; i < this.lstUsers.Items.Count; i++)
         {
             // For an ascending sort, we keep going until we find something we aren't >,
             // then insert ourselves there.
             // We then just return. The finally block will trip to refresh the listbox before the
             // return kicks us all the way out.
             if (cu.CompareTo(lstUsers.Items[i]) < 1)
             {
                 // cu is less than or equal to lstUsers.Items[i]. That's where we insert.
                 lstUsers.Items.Insert(i, cu);
                 return;                         // Now get the heck out of this proc.
             }
         }
         this.lstUsers.Items.Add(cu);
     }
     // A fun hack to get this Refresh to happen come hell or high water.
     // Hint: finally blocks run when code leaves a try or catch block in ANY WAY OR FORM.
     // Whether by hitting the }, throwing up, breaking, or even return.
     finally
     {
         this.lstUsers.Refresh();
     }
 }
Example #3
0
 public void RemoveUserFromChannel(ChanUser cu)
 {
     if (cu != null)
     {
         this.lstUsers.Items.Remove(cu);
         this.lstUsers.Refresh();
     }
 }
Example #4
0
        public void AddUserToChannel(string nick, string info)
        {
            if (this.GetUserOnChannelByNick(nick) != null)
            {
                return;
            }

            ChanUser cu = new ChanUser(nick, this);

            cu.Info = info;
            AddUserToChannel(cu);
        }
Example #5
0
        public void RemovePrefix(string nick, char prefix)
        {
            ChanUser cu = GetUserOnChannelByNick(nick);

            if (cu == null)
            {
                return;
            }
            RemoveUserFromChannel(cu);
            try
            {
                cu.Prefixes = cu.Prefixes.Replace(prefix.ToString(), "");
            }
            finally
            {
                AddUserToChannel(cu);
                this.lstUsers.Refresh();
            }
        }
Example #6
0
 public void RemoveUserFromChannel(ChanUser cu)
 {
     if (cu != null)
     {
         this.lstUsers.Items.Remove(cu);
         this.lstUsers.Refresh();
     }
 }
Example #7
0
        public void AddUserToChannel(string nick, string info)
        {
            if (this.GetUserOnChannelByNick(nick) != null)
                return;

            ChanUser cu = new ChanUser(nick, this);
            cu.Info = info;
            AddUserToChannel(cu);
        }
Example #8
0
 public void AddUserToChannel(ChanUser cu)
 {
     try
     {
         for (int i = 0; i < this.lstUsers.Items.Count; i++)
         {
             // For an ascending sort, we keep going until we find something we aren't >,
             // then insert ourselves there.
             // We then just return. The finally block will trip to refresh the listbox before the
             // return kicks us all the way out.
             if (cu.CompareTo(lstUsers.Items[i]) < 1)
             {
                 // cu is less than or equal to lstUsers.Items[i]. That's where we insert.
                 lstUsers.Items.Insert(i, cu);
                 return; // Now get the heck out of this proc.
             }
         }
         this.lstUsers.Items.Add(cu);
     }
         // A fun hack to get this Refresh to happen come hell or high water.
         // Hint: finally blocks run when code leaves a try or catch block in ANY WAY OR FORM.
         // Whether by hitting the }, throwing up, breaking, or even return.
     finally
     {
         this.lstUsers.Refresh();
     }
 }
Example #9
0
        public void RemoveUserFromChannel(string nick)
        {
            ChanUser cu = GetUserOnChannelByNick(nick);

            RemoveUserFromChannel(cu);
        }
Example #10
0
            public int CompareTo(object obj)
            {
                if (!(obj is ChanUser))
                {
                    throw new ArgumentException("Can only compare with other ChanUser objects.", "obj");
                }
                ChanUser cu = ((ChanUser)(obj));

                // Both have no prefixes. Do nick compare.
                if (this.Prefixes.Length == 0 && cu.Prefixes.Length == 0)
                {
                    return(Nick.CompareTo(cu.Nick));
                }
                // They have a prefix. We don't. Put us > them so that we come after in an ascending sort.
                if (this.Prefixes.Length == 0 && cu.Prefixes.Length > 0)
                {
                    return(1);
                }
                // We have a prefix. They don't. Us < them so we come before in an ascending sort.
                if (this.Prefixes.Length > 0 && cu.Prefixes.Length == 0)
                {
                    return(-1);
                }
                // Both have a prefix so we must compare the "highest" (first) prefix.
                char myhighprefix = Prefixes[0], hishighprefix = cu.Prefixes[0];

                // Highest prefixes are equal - compare nicks.
                if (myhighprefix == hishighprefix)
                {
                    return(Nick.CompareTo(cu.Nick));
                }
                // If for some reason an invalid first prefix is involved, put the invalid prefixes after
                // all valid prefixes.
                // Here we're invalid, they aren't. We come after. We > them.
                if (p.Server.ISupport.PREFIX_Characters.IndexOf(myhighprefix) < 0 && p.Server.ISupport.PREFIX_Characters.IndexOf(hishighprefix) >= 0)
                {
                    return(1);
                }
                // They're invalid, we aren't. We come before. We < them.
                if (p.Server.ISupport.PREFIX_Characters.IndexOf(myhighprefix) >= 0 && p.Server.ISupport.PREFIX_Characters.IndexOf(hishighprefix) < 0)
                {
                    return(-1);
                }
                // Both prefixes invalid, so do a flat ASCII compare.
                if (p.Server.ISupport.PREFIX_Characters.IndexOf(myhighprefix) < 0 && p.Server.ISupport.PREFIX_Characters.IndexOf(hishighprefix) < 0)
                {
                    return(myhighprefix.CompareTo(hishighprefix));
                }
                int compare;

                // Compare the index of the prefixes within the prefix part of CHANMODES which will be
                // ordered in "highest level" prefix to "lowest level" (eg owner/op first, voice last).
                compare = p.Server.ISupport.PREFIX_Characters.IndexOf(myhighprefix).CompareTo(p.Server.ISupport.PREFIX_Characters.IndexOf(hishighprefix));
                // If his index is higher, we actually have the higher prefix. (PREFIX= symbols are ordered
                // high-to-low.) However, when we have the higher prefix, we come first, so we < them.
                if (compare != 0)
                {
                    return(compare * 1);
                }
                // Indexes are equal - shouldn't happen unless the prefixes themselves are equal and
                // that's handled above. However, I'm paranoid, and therefore am leaving this here.
                else
                {
                    return(Nick.CompareTo(cu.Nick));
                }
            }