Identify TechBot to allow private messages
Modified: trunk/irc/TechBot/TechBot/App.config
Modified: trunk/irc/TechBot/TechBot/ServiceThread.cs
Modified: trunk/irc/TechBot/TechBot.Console/App.config
Modified: trunk/irc/TechBot/TechBot.Console/Main.cs
Modified: trunk/irc/TechBot/TechBot.IRCLibrary/IRC.cs
Modified: trunk/irc/TechBot/TechBot.IRCLibrary/IrcClient.cs
Modified: trunk/irc/TechBot/TechBot.Library/IrcService.cs

Modified: trunk/irc/TechBot/TechBot/App.config
--- trunk/irc/TechBot/TechBot/App.config	2006-01-05 15:17:54 UTC (rev 20577)
+++ trunk/irc/TechBot/TechBot/App.config	2006-01-05 15:29:08 UTC (rev 20578)
@@ -5,6 +5,7 @@
 		<add key="IRCServerHostPort" value="6667" />
 		<add key="IRCChannelNames" value="channel1;channel2" />
 		<add key="IRCBotName" value="MyBot" />
+		<add key="IRCBotPassword" value="MyPassword" />
 		<add key="ChmPath" value="C:\IRC\TechBot\CHM" />
 		<add key="MainChm" value="kmarch.chm" />
 		<add key="NtstatusXml" value="C:\IRC\TechBot\ntstatus.xml" />

Modified: trunk/irc/TechBot/TechBot/ServiceThread.cs
--- trunk/irc/TechBot/TechBot/ServiceThread.cs	2006-01-05 15:17:54 UTC (rev 20577)
+++ trunk/irc/TechBot/TechBot/ServiceThread.cs	2006-01-05 15:29:08 UTC (rev 20578)
@@ -11,6 +11,7 @@
 		private int IRCServerHostPort;
 		private string IRCChannelNames;
 		private string IRCBotName;
+		private string IRCBotPassword;
 		private string ChmPath;
 		private string MainChm;
 		private string NtstatusXml;
@@ -32,6 +33,7 @@
 			IRCServerHostPort = Int32.Parse(ConfigurationSettings.AppSettings["IRCServerHostPort"]);
 			IRCChannelNames = ConfigurationSettings.AppSettings["IRCChannelNames"];
 			IRCBotName = ConfigurationSettings.AppSettings["IRCBotName"];
+			IRCBotPassword = ConfigurationSettings.AppSettings["IRCBotPassword"];
 			ChmPath = ConfigurationSettings.AppSettings["ChmPath"];
 			MainChm = ConfigurationSettings.AppSettings["MainChm"];
 			NtstatusXml = ConfigurationSettings.AppSettings["NtstatusXml"];
@@ -51,6 +53,7 @@
 			                                       IRCServerHostPort,
 			                                       IRCChannelNames,
 			                                       IRCBotName,
+			                                       IRCBotPassword,
 			                                       ChmPath,
 			                                       MainChm,
 			                                       NtstatusXml,

Modified: trunk/irc/TechBot/TechBot.Console/App.config
--- trunk/irc/TechBot/TechBot.Console/App.config	2006-01-05 15:17:54 UTC (rev 20577)
+++ trunk/irc/TechBot/TechBot.Console/App.config	2006-01-05 15:29:08 UTC (rev 20578)
@@ -5,6 +5,7 @@
 		<add key="IRCServerHostPort" value="6667" />
 		<add key="IRCChannelNames" value="channel1;channel2" />
 		<add key="IRCBotName" value="MyBot" />
+		<add key="IRCBotPassword" value="MyPassword" />
 		<add key="ChmPath" value="C:\IRC\TechBot\CHM" />
 		<add key="MainChm" value="kmarch.chm" />
 		<add key="NtstatusXml" value="C:\IRC\TechBot\ntstatus.xml" />

Modified: trunk/irc/TechBot/TechBot.Console/Main.cs
--- trunk/irc/TechBot/TechBot.Console/Main.cs	2006-01-05 15:17:54 UTC (rev 20577)
+++ trunk/irc/TechBot/TechBot.Console/Main.cs	2006-01-05 15:29:08 UTC (rev 20578)
@@ -74,6 +74,18 @@
 			}
 		}
 
+		private static string IRCBotPassword
+		{
+			get
+			{
+				string optionName = "IRCBotPassword";
+				string s = ConfigurationSettings.AppSettings[optionName];
+				VerifyRequiredOption(optionName,
+				                     s);
+				return s;
+			}
+		}
+
 		private static string ChmPath
 		{
 			get
@@ -176,6 +188,7 @@
 			                                       IRCServerHostPort,
 			                                       IRCChannelNames,
 			                                       IRCBotName,
+			                                       IRCBotPassword,
 			                                       ChmPath,
 			                                       MainChm,
 			                                       NtstatusXml,

Modified: trunk/irc/TechBot/TechBot.IRCLibrary/IRC.cs
--- trunk/irc/TechBot/TechBot.IRCLibrary/IRC.cs	2006-01-05 15:17:54 UTC (rev 20577)
+++ trunk/irc/TechBot/TechBot.IRCLibrary/IRC.cs	2006-01-05 15:29:08 UTC (rev 20578)
@@ -16,6 +16,7 @@
 		public const string PONG = "PONG";
 		public const string PRIVMSG = "PRIVMSG";
 		public const string USER = "USER";
+		public const string PASS = "PASS";
 
 		public const string RPL_NAMREPLY = "353";
 		public const string RPL_ENDOFNAMES = "366";

Modified: trunk/irc/TechBot/TechBot.IRCLibrary/IrcClient.cs
--- trunk/irc/TechBot/TechBot.IRCLibrary/IrcClient.cs	2006-01-05 15:17:54 UTC (rev 20577)
+++ trunk/irc/TechBot/TechBot.IRCLibrary/IrcClient.cs	2006-01-05 15:29:08 UTC (rev 20578)
@@ -556,26 +556,40 @@
 		public void ChangeNick(string nickname)
 		{
 			if (nickname == null)
-			{
 				throw new ArgumentNullException("nickname", "Nickname cannot be null.");
-			}
 
 			/* NICK <nickname> [ <hopcount> ] */
 			SendMessage(new IrcMessage(IRC.NICK, nickname));
 		}
 
 		/// <summary>
+		/// Submit password to identify user.
+		/// </summary>
+		/// <param name="password">Password of registered nick.</param>
+		private void SubmitPassword(string password)
+		{
+			if (password == null)
+				throw new ArgumentNullException("password", "Password cannot be null.");
+
+			/* PASS <password> */
+			SendMessage(new IrcMessage(IRC.PASS, password));
+		}
+
+		/// <summary>
 		/// Register.
 		/// </summary>
 		/// <param name="nickname">New nickname.</param>
+		/// <param name="password">Password. Can be null.</param>
 		/// <param name="realname">Real name. Can be null.</param>
-		public void Register(string nickname, string realname)
+		public void Register(string nickname,
+		                     string password,
+		                     string realname)
 		{
 			if (nickname == null)
-			{
 				throw new ArgumentNullException("nickname", "Nickname cannot be null.");
-			}
 			firstPingReceived = false;
+			if (password != null)
+				SubmitPassword(password);
 			ChangeNick(nickname);
 			/* OLD: USER <username> <hostname> <servername> <realname> */
 			/* NEW: USER <user> <mode> <unused> <realname> */

Modified: trunk/irc/TechBot/TechBot.Library/IrcService.cs
--- trunk/irc/TechBot/TechBot.Library/IrcService.cs	2006-01-05 15:17:54 UTC (rev 20577)
+++ trunk/irc/TechBot/TechBot.Library/IrcService.cs	2006-01-05 15:29:08 UTC (rev 20578)
@@ -11,6 +11,7 @@
 		private int port;
 		private string channelnames;
 		private string botname;
+		private string password;
 		private string chmPath;
 		private string mainChm;
 		private string ntstatusXml;
@@ -28,6 +29,7 @@
 		                  int port,
 		                  string channelnames,
 		                  string botname,
+		                  string password,
 		                  string chmPath,
 		                  string mainChm,
 		                  string ntstatusXml,
@@ -41,6 +43,10 @@
 			this.port = port;
 			this.channelnames = channelnames;
 			this.botname = botname;
+			if (password == null || password.Trim() == "")
+				this.password = null;
+			else
+				this.password = password;
 			this.chmPath = chmPath;
 			this.mainChm = mainChm;
 			this.ntstatusXml = ntstatusXml;
@@ -72,7 +78,7 @@
 			                                       hostname, port));
 			client.Connect(hostname, port);
 			System.Console.WriteLine("Connected...");
-			client.Register(botname, null);
+			client.Register(botname, password, null);
 			System.Console.WriteLine(String.Format("Registered as {0}...", botname));
 			JoinChannels();