From f881f51fdf6c71520cda99567864fe850c0d6101 Mon Sep 17 00:00:00 2001 From: Casper Hornstrup Date: Thu, 5 Jan 2006 15:29:08 +0000 Subject: [PATCH] Identify TechBot to allow private messages svn path=/trunk/; revision=20578 --- irc/TechBot/TechBot.Console/App.config | 1 + irc/TechBot/TechBot.Console/Main.cs | 13 +++++++++++ irc/TechBot/TechBot.IRCLibrary/IRC.cs | 1 + irc/TechBot/TechBot.IRCLibrary/IrcClient.cs | 24 ++++++++++++++++----- irc/TechBot/TechBot.Library/IrcService.cs | 8 ++++++- irc/TechBot/TechBot/App.config | 1 + irc/TechBot/TechBot/ServiceThread.cs | 3 +++ 7 files changed, 45 insertions(+), 6 deletions(-) diff --git a/irc/TechBot/TechBot.Console/App.config b/irc/TechBot/TechBot.Console/App.config index 28d804b75d6..310f6ee2f35 100644 --- a/irc/TechBot/TechBot.Console/App.config +++ b/irc/TechBot/TechBot.Console/App.config @@ -5,6 +5,7 @@ + diff --git a/irc/TechBot/TechBot.Console/Main.cs b/irc/TechBot/TechBot.Console/Main.cs index 7c41f5d073d..323f234746d 100644 --- a/irc/TechBot/TechBot.Console/Main.cs +++ b/irc/TechBot/TechBot.Console/Main.cs @@ -74,6 +74,18 @@ namespace TechBot.Console } } + 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 @@ namespace TechBot.Console IRCServerHostPort, IRCChannelNames, IRCBotName, + IRCBotPassword, ChmPath, MainChm, NtstatusXml, diff --git a/irc/TechBot/TechBot.IRCLibrary/IRC.cs b/irc/TechBot/TechBot.IRCLibrary/IRC.cs index 38cb448b6a5..488b6b28d08 100644 --- a/irc/TechBot/TechBot.IRCLibrary/IRC.cs +++ b/irc/TechBot/TechBot.IRCLibrary/IRC.cs @@ -16,6 +16,7 @@ namespace TechBot.IRCLibrary 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"; diff --git a/irc/TechBot/TechBot.IRCLibrary/IrcClient.cs b/irc/TechBot/TechBot.IRCLibrary/IrcClient.cs index 3590f57aa35..68c7aa24ab4 100644 --- a/irc/TechBot/TechBot.IRCLibrary/IrcClient.cs +++ b/irc/TechBot/TechBot.IRCLibrary/IrcClient.cs @@ -556,26 +556,40 @@ namespace TechBot.IRCLibrary public void ChangeNick(string nickname) { if (nickname == null) - { throw new ArgumentNullException("nickname", "Nickname cannot be null."); - } /* NICK [ ] */ SendMessage(new IrcMessage(IRC.NICK, nickname)); } + /// + /// Submit password to identify user. + /// + /// Password of registered nick. + private void SubmitPassword(string password) + { + if (password == null) + throw new ArgumentNullException("password", "Password cannot be null."); + + /* PASS */ + SendMessage(new IrcMessage(IRC.PASS, password)); + } + /// /// Register. /// /// New nickname. + /// Password. Can be null. /// Real name. Can be null. - 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 */ /* NEW: USER */ diff --git a/irc/TechBot/TechBot.Library/IrcService.cs b/irc/TechBot/TechBot.Library/IrcService.cs index a771f418de6..2bc382c3b06 100644 --- a/irc/TechBot/TechBot.Library/IrcService.cs +++ b/irc/TechBot/TechBot.Library/IrcService.cs @@ -11,6 +11,7 @@ namespace TechBot.Library 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 @@ namespace TechBot.Library int port, string channelnames, string botname, + string password, string chmPath, string mainChm, string ntstatusXml, @@ -41,6 +43,10 @@ namespace TechBot.Library 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 @@ namespace TechBot.Library 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(); diff --git a/irc/TechBot/TechBot/App.config b/irc/TechBot/TechBot/App.config index dc0bf349402..2a40c92b2f0 100644 --- a/irc/TechBot/TechBot/App.config +++ b/irc/TechBot/TechBot/App.config @@ -5,6 +5,7 @@ + diff --git a/irc/TechBot/TechBot/ServiceThread.cs b/irc/TechBot/TechBot/ServiceThread.cs index 0c9547878ba..f2595c94f9a 100644 --- a/irc/TechBot/TechBot/ServiceThread.cs +++ b/irc/TechBot/TechBot/ServiceThread.cs @@ -11,6 +11,7 @@ namespace TechBot 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 @@ namespace TechBot 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 @@ namespace TechBot IRCServerHostPort, IRCChannelNames, IRCBotName, + IRCBotPassword, ChmPath, MainChm, NtstatusXml,