A really simple Win32 implementation of 'hostname'.
[reactos.git] / irc / TechBot / TechBot.IRCLibrary / IrcChannel.cs
1 /*
2 Channels names are strings (beginning with a '&' or '#' character) of
3 length up to 200 characters. Apart from the the requirement that the
4 first character being either '&' or '#'; the only restriction on a
5 channel name is that it may not contain any spaces (' '), a control G
6 (^G or ASCII 7), or a comma (',' which is used as a list item
7 separator by the protocol).
8 */
9 using System;
10 using System.Collections;
11
12 namespace TechBot.IRCLibrary
13 {
14 /// <summary>
15 /// IRC channel type.
16 /// </summary>
17 public enum IrcChannelType
18 {
19 Public,
20 Private,
21 Secret
22 }
23
24
25
26 /// <summary>
27 /// IRC channel.
28 /// </summary>
29 public class IrcChannel
30 {
31 #region Private fields
32
33 private IrcClient owner;
34 private string name;
35 private IrcChannelType type = IrcChannelType.Public;
36 private ArrayList users = new ArrayList();
37
38 #endregion
39
40 #region Public properties
41
42 /// <summary>
43 /// Owner of this channel.
44 /// </summary>
45 public IrcClient Owner
46 {
47 get
48 {
49 return owner;
50 }
51 }
52
53 /// <summary>
54 /// Name of channel (no leading #).
55 /// </summary>
56 public string Name
57 {
58 get
59 {
60 return name;
61 }
62 }
63
64 /// <summary>
65 /// Type of channel.
66 /// </summary>
67 public IrcChannelType Type
68 {
69 get
70 {
71 return type;
72 }
73 }
74
75 /// <summary>
76 /// Users in this channel.
77 /// </summary>
78 public ArrayList Users
79 {
80 get
81 {
82 return users;
83 }
84 }
85
86 #endregion
87
88 /// <summary>
89 /// Constructor.
90 /// </summary>
91 /// <param name="owner">Owner of this channel.</param>
92 /// <param name="name">Name of channel.</param>
93 public IrcChannel(IrcClient owner, string name)
94 {
95 if (owner == null)
96 {
97 throw new ArgumentNullException("owner", "Owner cannot be null.");
98 }
99 if (name == null)
100 {
101 throw new ArgumentNullException("name", "Name cannot be null.");
102 }
103 this.owner = owner;
104 this.name = name;
105 }
106
107 /// <summary>
108 /// Locate a user.
109 /// </summary>
110 /// <param name="nickname">Nickname of user (no decorations).</param>
111 /// <returns>User or null if not found.</returns>
112 public IrcUser LocateUser(string nickname)
113 {
114 foreach (IrcUser user in Users)
115 {
116 /* FIXME: There are special cases for nickname comparison */
117 if (nickname.ToLower().Equals(user.Nickname.ToLower()))
118 {
119 return user;
120 }
121 }
122 return null;
123 }
124
125 /// <summary>
126 /// Talk to the channel.
127 /// </summary>
128 /// <param name="text">Text to send to the channel.</param>
129 public void Talk(string text)
130 {
131 owner.SendMessage(new IrcMessage(IRC.PRIVMSG,
132 String.Format("#{0} :{1}",
133 name,
134 text)));
135 }
136 }
137 }