/* Channels names are strings (beginning with a '&' or '#' character) of length up to 200 characters. Apart from the the requirement that the first character being either '&' or '#'; the only restriction on a channel name is that it may not contain any spaces (' '), a control G (^G or ASCII 7), or a comma (',' which is used as a list item separator by the protocol). */ using System; using System.Collections; namespace TechBot.IRCLibrary { /// /// IRC channel type. /// public enum IrcChannelType { Public, Private, Secret } /// /// IRC channel. /// public class IrcChannel { #region Private fields private IrcClient owner; private string name; private IrcChannelType type = IrcChannelType.Public; private ArrayList users = new ArrayList(); #endregion #region Public properties /// /// Owner of this channel. /// public IrcClient Owner { get { return owner; } } /// /// Name of channel (no leading #). /// public string Name { get { return name; } } /// /// Type of channel. /// public IrcChannelType Type { get { return type; } } /// /// Users in this channel. /// public ArrayList Users { get { return users; } } #endregion /// /// Constructor. /// /// Owner of this channel. /// Name of channel. public IrcChannel(IrcClient owner, string name) { if (owner == null) { throw new ArgumentNullException("owner", "Owner cannot be null."); } if (name == null) { throw new ArgumentNullException("name", "Name cannot be null."); } this.owner = owner; this.name = name; } /// /// Locate a user. /// /// Nickname of user (no decorations). /// User or null if not found. public IrcUser LocateUser(string nickname) { foreach (IrcUser user in Users) { /* FIXME: There are special cases for nickname comparison */ if (nickname.ToLower().Equals(user.Nickname.ToLower())) { return user; } } return null; } /// /// Talk to the channel. /// /// Text to send to the channel. public void Talk(string text) { owner.SendMessage(new IrcMessage(IRC.PRIVMSG, String.Format("#{0} :{1}", name, text))); } } }