From 36b03fd4c20f67ca40b9f42de02b51a4b25014c0 Mon Sep 17 00:00:00 2001 From: Andrej Date: Wed, 4 Jan 2017 10:57:14 +0700 Subject: [PATCH 1/5] Catching of "No such host is known" exception I have added the catching of exception if server address is invalid or no internet connection. Also I have added the IRCClient console application for testing. --- ChatSharp.sln | 76 +++++++++++++++++----------- ChatSharp/ChatSharp.csproj | 1 + ChatSharp/Events/ErrorEventArgs.cs | 21 ++++++++ ChatSharp/IrcClient.cs | 54 +++++++++++++------- IRCClient/App.config | 6 +++ IRCClient/IRCClient.csproj | 66 ++++++++++++++++++++++++ IRCClient/Program.cs | 54 ++++++++++++++++++++ IRCClient/Properties/AssemblyInfo.cs | 36 +++++++++++++ 8 files changed, 266 insertions(+), 48 deletions(-) create mode 100644 ChatSharp/Events/ErrorEventArgs.cs create mode 100644 IRCClient/App.config create mode 100644 IRCClient/IRCClient.csproj create mode 100644 IRCClient/Program.cs create mode 100644 IRCClient/Properties/AssemblyInfo.cs diff --git a/ChatSharp.sln b/ChatSharp.sln index 9a920d8..43b464c 100644 --- a/ChatSharp.sln +++ b/ChatSharp.sln @@ -1,30 +1,46 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatSharp", "ChatSharp\ChatSharp.csproj", "{4033AFFA-BEA3-4BDF-84EA-59A23360FD36}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|Mixed Platforms = Debug|Mixed Platforms - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|Mixed Platforms = Release|Mixed Platforms - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Debug|x86.ActiveCfg = Debug|Any CPU - {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Release|Any CPU.Build.0 = Release|Any CPU - {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Release|x86.ActiveCfg = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatSharp", "ChatSharp\ChatSharp.csproj", "{4033AFFA-BEA3-4BDF-84EA-59A23360FD36}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IRCClient", "IRCClient\IRCClient.csproj", "{939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Debug|x86.ActiveCfg = Debug|Any CPU + {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Release|Any CPU.Build.0 = Release|Any CPU + {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Release|x86.ActiveCfg = Release|Any CPU + {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Debug|Any CPU.Build.0 = Debug|Any CPU + {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Debug|x86.ActiveCfg = Debug|Any CPU + {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Debug|x86.Build.0 = Debug|Any CPU + {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Release|Any CPU.ActiveCfg = Release|Any CPU + {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Release|Any CPU.Build.0 = Release|Any CPU + {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Release|x86.ActiveCfg = Release|Any CPU + {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/ChatSharp/ChatSharp.csproj b/ChatSharp/ChatSharp.csproj index db93c7e..53b81b2 100644 --- a/ChatSharp/ChatSharp.csproj +++ b/ChatSharp/ChatSharp.csproj @@ -45,6 +45,7 @@ + diff --git a/ChatSharp/Events/ErrorEventArgs.cs b/ChatSharp/Events/ErrorEventArgs.cs new file mode 100644 index 0000000..4feb42e --- /dev/null +++ b/ChatSharp/Events/ErrorEventArgs.cs @@ -0,0 +1,21 @@ +using System; +using System.Net.Sockets; + +namespace ChatSharp.Events +{ + /// + /// Raised when a Error occurs. + /// + public class ErrorEventArgs : EventArgs + { + /// + /// The error that has occured. + /// + public string Error { get; set; } + + internal ErrorEventArgs(string error) + { + Error = error; + } + } +} diff --git a/ChatSharp/IrcClient.cs b/ChatSharp/IrcClient.cs index 0e5a83d..86049eb 100644 --- a/ChatSharp/IrcClient.cs +++ b/ChatSharp/IrcClient.cs @@ -211,26 +211,36 @@ namespace ChatSharp private void ConnectComplete(IAsyncResult result) { - Socket.EndConnect(result); - - NetworkStream = new NetworkStream(Socket); - if (UseSSL) + try { - if (IgnoreInvalidSSL) - NetworkStream = new SslStream(NetworkStream, false, (sender, certificate, chain, policyErrors) => true); - else - NetworkStream = new SslStream(NetworkStream); - ((SslStream)NetworkStream).AuthenticateAsClient(ServerHostname); - } + Socket.EndConnect(result); + NetworkStream = new NetworkStream(Socket); + if (UseSSL) + { + if (IgnoreInvalidSSL) + NetworkStream = new SslStream(NetworkStream, false, (sender, certificate, chain, policyErrors) => true); + else + NetworkStream = new SslStream(NetworkStream); + ((SslStream)NetworkStream).AuthenticateAsClient(ServerHostname); + } - NetworkStream.BeginRead(ReadBuffer, ReadBufferIndex, ReadBuffer.Length, DataRecieved, null); - // Write login info - if (!string.IsNullOrEmpty(User.Password)) - SendRawMessage("PASS {0}", User.Password); - SendRawMessage("NICK {0}", User.Nick); - // hostname, servername are ignored by most IRC servers - SendRawMessage("USER {0} hostname servername :{1}", User.User, User.RealName); - PingTimer.Start(); + NetworkStream.BeginRead(ReadBuffer, ReadBufferIndex, ReadBuffer.Length, DataRecieved, null); + // Write login info + if (!string.IsNullOrEmpty(User.Password)) + SendRawMessage("PASS {0}", User.Password); + SendRawMessage("NICK {0}", User.Nick); + // hostname, servername are ignored by most IRC servers + SendRawMessage("USER {0} hostname servername :{1}", User.User, User.RealName); + PingTimer.Start(); + } + catch (SocketException e) + { + OnNetworkError(new SocketErrorEventArgs(e.SocketErrorCode)); + } + catch (Exception e) + { + OnError(new Events.ErrorEventArgs(e.Message)); + } } private void DataRecieved(IAsyncResult result) @@ -356,6 +366,14 @@ namespace ChatSharp } } + /// + /// Raised for errors. + /// + public event EventHandler Error; + internal void OnError(Events.ErrorEventArgs e) + { + if (Error != null) Error(this, e); + } /// /// Raised for socket errors. ChatSharp does not automatically reconnect. /// diff --git a/IRCClient/App.config b/IRCClient/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/IRCClient/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/IRCClient/IRCClient.csproj b/IRCClient/IRCClient.csproj new file mode 100644 index 0000000..3fc53e0 --- /dev/null +++ b/IRCClient/IRCClient.csproj @@ -0,0 +1,66 @@ + + + + + Debug + AnyCPU + {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561} + Exe + Properties + IRCClient + IRCClient + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {4033affa-bea3-4bdf-84ea-59a23360fd36} + ChatSharp + + + + + \ No newline at end of file diff --git a/IRCClient/Program.cs b/IRCClient/Program.cs new file mode 100644 index 0000000..bc75d1d --- /dev/null +++ b/IRCClient/Program.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Net.Sockets; +using System.Text; +using System.Threading.Tasks; +using ChatSharp; + +namespace IRCClient +{ + class Program + { + static void Main(string[] args) + { + //https://github.com/SirCmpwn/ChatSharp + var client = new IrcClient("InvalidAddress", new IrcUser("ChatSharp", "ChatSharp")); +// var client = new IrcClient("irc.freenode.net", new IrcUser("ChatSharp", "ChatSharp")); +// var client = new IrcClient("localhost", new IrcUser("ChatSharp", "ChatSharp")); + Console.WriteLine("IRC client. " + client.ServerAddress); + client.ConnectionComplete += (s, e) => { + Console.WriteLine("ConnectionComplete."); + client.JoinChannel("#botwar"); + }; + client.UserJoinedChannel += (s, e) => { + Console.WriteLine("The " + e.User.Nick + " user has joined to the " + e.Channel.Name + " channel."); + }; + client.NetworkError += (s, e) => Console.WriteLine("NetworkError: " + new Win32Exception((int)e.SocketError).Message); + client.Error += (s, e) => Console.WriteLine("Error: " + e.Error); + + client.ChannelMessageRecieved += (s, e) => + { + var channel = client.Channels[e.PrivateMessage.Source]; + + if (e.PrivateMessage.Message == ".list") + channel.SendMessage(string.Join(", ", channel.Users.Select(u => u.Nick))); + else if (e.PrivateMessage.Message.StartsWith(".ban ")) + { + if (!channel.UsersByMode['@'].Contains(client.User)) + { + channel.SendMessage("I'm not an op here!"); + return; + } + var target = e.PrivateMessage.Message.Substring(5); + client.WhoIs(target, whois => channel.ChangeMode("+b *!*@" + whois.User.Hostname)); + } + }; + + client.ConnectAsync(); + + while (true) ; // Waste CPU cycles + } + } +} diff --git a/IRCClient/Properties/AssemblyInfo.cs b/IRCClient/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2e24add --- /dev/null +++ b/IRCClient/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("IRCClient")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("IRCClient")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("939cc9ec-ee9f-47dc-bc5b-d016b6b6e561")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] From d11905962f4af4b92668a09d21a16c7daf4e4913 Mon Sep 17 00:00:00 2001 From: Andrej Date: Wed, 4 Jan 2017 11:38:00 +0700 Subject: [PATCH 2/5] actual Exception instead e.Message Also removed the IRCClient project from this PR --- ChatSharp.sln | 14 ------ ChatSharp/Events/ErrorEventArgs.cs | 4 +- ChatSharp/IrcClient.cs | 2 +- IRCClient/App.config | 6 --- IRCClient/IRCClient.csproj | 66 ---------------------------- IRCClient/Program.cs | 54 ----------------------- IRCClient/Properties/AssemblyInfo.cs | 36 --------------- 7 files changed, 3 insertions(+), 179 deletions(-) delete mode 100644 IRCClient/App.config delete mode 100644 IRCClient/IRCClient.csproj delete mode 100644 IRCClient/Program.cs delete mode 100644 IRCClient/Properties/AssemblyInfo.cs diff --git a/ChatSharp.sln b/ChatSharp.sln index 43b464c..7e4ca8a 100644 --- a/ChatSharp.sln +++ b/ChatSharp.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 14.0.23107.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatSharp", "ChatSharp\ChatSharp.csproj", "{4033AFFA-BEA3-4BDF-84EA-59A23360FD36}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IRCClient", "IRCClient\IRCClient.csproj", "{939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,18 +25,6 @@ Global {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Release|Mixed Platforms.Build.0 = Release|Any CPU {4033AFFA-BEA3-4BDF-84EA-59A23360FD36}.Release|x86.ActiveCfg = Release|Any CPU - {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Debug|Any CPU.Build.0 = Debug|Any CPU - {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Debug|x86.ActiveCfg = Debug|Any CPU - {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Debug|x86.Build.0 = Debug|Any CPU - {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Release|Any CPU.ActiveCfg = Release|Any CPU - {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Release|Any CPU.Build.0 = Release|Any CPU - {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Release|x86.ActiveCfg = Release|Any CPU - {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ChatSharp/Events/ErrorEventArgs.cs b/ChatSharp/Events/ErrorEventArgs.cs index 4feb42e..fccfd3f 100644 --- a/ChatSharp/Events/ErrorEventArgs.cs +++ b/ChatSharp/Events/ErrorEventArgs.cs @@ -11,9 +11,9 @@ namespace ChatSharp.Events /// /// The error that has occured. /// - public string Error { get; set; } + public Exception Error { get; set; } - internal ErrorEventArgs(string error) + internal ErrorEventArgs(Exception error) { Error = error; } diff --git a/ChatSharp/IrcClient.cs b/ChatSharp/IrcClient.cs index 86049eb..cdbcd35 100644 --- a/ChatSharp/IrcClient.cs +++ b/ChatSharp/IrcClient.cs @@ -239,7 +239,7 @@ namespace ChatSharp } catch (Exception e) { - OnError(new Events.ErrorEventArgs(e.Message)); + OnError(new Events.ErrorEventArgs(e)); } } diff --git a/IRCClient/App.config b/IRCClient/App.config deleted file mode 100644 index 88fa402..0000000 --- a/IRCClient/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/IRCClient/IRCClient.csproj b/IRCClient/IRCClient.csproj deleted file mode 100644 index 3fc53e0..0000000 --- a/IRCClient/IRCClient.csproj +++ /dev/null @@ -1,66 +0,0 @@ - - - - - Debug - AnyCPU - {939CC9EC-EE9F-47DC-BC5B-D016B6B6E561} - Exe - Properties - IRCClient - IRCClient - v4.5.2 - 512 - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - {4033affa-bea3-4bdf-84ea-59a23360fd36} - ChatSharp - - - - - \ No newline at end of file diff --git a/IRCClient/Program.cs b/IRCClient/Program.cs deleted file mode 100644 index bc75d1d..0000000 --- a/IRCClient/Program.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Net.Sockets; -using System.Text; -using System.Threading.Tasks; -using ChatSharp; - -namespace IRCClient -{ - class Program - { - static void Main(string[] args) - { - //https://github.com/SirCmpwn/ChatSharp - var client = new IrcClient("InvalidAddress", new IrcUser("ChatSharp", "ChatSharp")); -// var client = new IrcClient("irc.freenode.net", new IrcUser("ChatSharp", "ChatSharp")); -// var client = new IrcClient("localhost", new IrcUser("ChatSharp", "ChatSharp")); - Console.WriteLine("IRC client. " + client.ServerAddress); - client.ConnectionComplete += (s, e) => { - Console.WriteLine("ConnectionComplete."); - client.JoinChannel("#botwar"); - }; - client.UserJoinedChannel += (s, e) => { - Console.WriteLine("The " + e.User.Nick + " user has joined to the " + e.Channel.Name + " channel."); - }; - client.NetworkError += (s, e) => Console.WriteLine("NetworkError: " + new Win32Exception((int)e.SocketError).Message); - client.Error += (s, e) => Console.WriteLine("Error: " + e.Error); - - client.ChannelMessageRecieved += (s, e) => - { - var channel = client.Channels[e.PrivateMessage.Source]; - - if (e.PrivateMessage.Message == ".list") - channel.SendMessage(string.Join(", ", channel.Users.Select(u => u.Nick))); - else if (e.PrivateMessage.Message.StartsWith(".ban ")) - { - if (!channel.UsersByMode['@'].Contains(client.User)) - { - channel.SendMessage("I'm not an op here!"); - return; - } - var target = e.PrivateMessage.Message.Substring(5); - client.WhoIs(target, whois => channel.ChangeMode("+b *!*@" + whois.User.Hostname)); - } - }; - - client.ConnectAsync(); - - while (true) ; // Waste CPU cycles - } - } -} diff --git a/IRCClient/Properties/AssemblyInfo.cs b/IRCClient/Properties/AssemblyInfo.cs deleted file mode 100644 index 2e24add..0000000 --- a/IRCClient/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("IRCClient")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("IRCClient")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("939cc9ec-ee9f-47dc-bc5b-d016b6b6e561")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] From 4a498fc429a4ca7c85e1895f7829a03907a5a8ce Mon Sep 17 00:00:00 2001 From: Andrej Date: Thu, 5 Jan 2017 09:39:42 +0700 Subject: [PATCH 3/5] IRC server error replies handler Handler of the IRC server error replies. See rfc1459 6.1 for details. --- ChatSharp/ChatSharp.csproj | 2 ++ ChatSharp/Events/ErrorReplieEventArgs.cs | 21 +++++++++++++++++++++ ChatSharp/Handlers/ErrorHandlers.cs | 18 ++++++++++++++++++ ChatSharp/Handlers/MessageHandlers.cs | 9 +++++++++ ChatSharp/IrcClient.cs | 7 +++++++ 5 files changed, 57 insertions(+) create mode 100644 ChatSharp/Events/ErrorReplieEventArgs.cs create mode 100644 ChatSharp/Handlers/ErrorHandlers.cs diff --git a/ChatSharp/ChatSharp.csproj b/ChatSharp/ChatSharp.csproj index 53b81b2..8c58958 100644 --- a/ChatSharp/ChatSharp.csproj +++ b/ChatSharp/ChatSharp.csproj @@ -46,6 +46,7 @@ + @@ -56,6 +57,7 @@ + diff --git a/ChatSharp/Events/ErrorReplieEventArgs.cs b/ChatSharp/Events/ErrorReplieEventArgs.cs new file mode 100644 index 0000000..3e1e31d --- /dev/null +++ b/ChatSharp/Events/ErrorReplieEventArgs.cs @@ -0,0 +1,21 @@ +using System; +using System.Net.Sockets; + +namespace ChatSharp.Events +{ + /// + /// Raised when a IRC Error replie occurs. See rfc1459 6.1 for details. + /// + public class ErrorReplieEventArgs : EventArgs + { + /// + /// The IRC error replie that has occured. + /// + public IrcMessage Message { get; set; } + + internal ErrorReplieEventArgs(IrcMessage message) + { + Message = message; + } + } +} diff --git a/ChatSharp/Handlers/ErrorHandlers.cs b/ChatSharp/Handlers/ErrorHandlers.cs new file mode 100644 index 0000000..0fe348a --- /dev/null +++ b/ChatSharp/Handlers/ErrorHandlers.cs @@ -0,0 +1,18 @@ +using ChatSharp.Events; +using System.Linq; + +namespace ChatSharp.Handlers +{ + /// + /// + internal static class ErrorHandlers + { + /// + /// + public static void HandleError(IrcClient client, IrcMessage message) + { +// System.Diagnostics.Trace.WriteLine("HandleNoSuchNick"); + client.OnErrorReplie(new Events.ErrorReplieEventArgs(message)); + } + } +} diff --git a/ChatSharp/Handlers/MessageHandlers.cs b/ChatSharp/Handlers/MessageHandlers.cs index fd05ad3..afa0f5b 100644 --- a/ChatSharp/Handlers/MessageHandlers.cs +++ b/ChatSharp/Handlers/MessageHandlers.cs @@ -58,6 +58,15 @@ namespace ChatSharp.Handlers // Server handlers client.SetHandler("004", ServerHandlers.HandleMyInfo); client.SetHandler("005", ServerHandlers.HandleISupport); + + // Error replies rfc1459 6.1 + client.SetHandler("401", ErrorHandlers.HandleError);//ERR_NOSUCHNICK " :No such nick/channel" + client.SetHandler("402", ErrorHandlers.HandleError);//ERR_NOSUCHSERVER " :No such server" + client.SetHandler("403", ErrorHandlers.HandleError);//ERR_NOSUCHCHANNEL " :No such channel" + client.SetHandler("404", ErrorHandlers.HandleError);//ERR_CANNOTSENDTOCHAN " :Cannot send to channel" + client.SetHandler("405", ErrorHandlers.HandleError);//ERR_TOOMANYCHANNELS " :You have joined too many \ channels" + client.SetHandler("406", ErrorHandlers.HandleError);//ERR_WASNOSUCHNICK " :There was no such nickname" + client.SetHandler("407", ErrorHandlers.HandleError);//ERR_TOOMANYTARGETS " :Duplicate recipients. No message \ } public static void HandleNick(IrcClient client, IrcMessage message) diff --git a/ChatSharp/IrcClient.cs b/ChatSharp/IrcClient.cs index cdbcd35..fbbd06b 100644 --- a/ChatSharp/IrcClient.cs +++ b/ChatSharp/IrcClient.cs @@ -366,6 +366,13 @@ namespace ChatSharp } } + /// + /// + public event EventHandler ErrorReplie; + internal void OnErrorReplie(Events.ErrorReplieEventArgs e) + { + if (ErrorReplie != null) ErrorReplie(this, e); + } /// /// Raised for errors. /// From 3a587c6f595c0b6f06b11d74af6f79dd86ddf65a Mon Sep 17 00:00:00 2001 From: Andrej Date: Thu, 5 Jan 2017 09:50:57 +0700 Subject: [PATCH 4/5] Cosmetic changes --- ChatSharp/Handlers/ErrorHandlers.cs | 3 ++- ChatSharp/IrcClient.cs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChatSharp/Handlers/ErrorHandlers.cs b/ChatSharp/Handlers/ErrorHandlers.cs index 0fe348a..0f8ce0b 100644 --- a/ChatSharp/Handlers/ErrorHandlers.cs +++ b/ChatSharp/Handlers/ErrorHandlers.cs @@ -4,14 +4,15 @@ using System.Linq; namespace ChatSharp.Handlers { /// + /// IRC error replies handler. See rfc1459 6.1. /// internal static class ErrorHandlers { /// + /// IRC Error replies handler. See rfc1459 6.1. /// public static void HandleError(IrcClient client, IrcMessage message) { -// System.Diagnostics.Trace.WriteLine("HandleNoSuchNick"); client.OnErrorReplie(new Events.ErrorReplieEventArgs(message)); } } diff --git a/ChatSharp/IrcClient.cs b/ChatSharp/IrcClient.cs index fbbd06b..4156825 100644 --- a/ChatSharp/IrcClient.cs +++ b/ChatSharp/IrcClient.cs @@ -367,6 +367,7 @@ namespace ChatSharp } /// + /// IRC Error Replies. rfc1459 6.1. /// public event EventHandler ErrorReplie; internal void OnErrorReplie(Events.ErrorReplieEventArgs e) From 9e8e73c1a899cd19ad1cfb1dfdf74a515a439c1f Mon Sep 17 00:00:00 2001 From: Andrej Date: Thu, 5 Jan 2017 15:08:00 +0700 Subject: [PATCH 5/5] Change from replie to reply --- ChatSharp/Events/ErrorReplieEventArgs.cs | 8 ++++---- ChatSharp/Handlers/ErrorHandlers.cs | 2 +- ChatSharp/IrcClient.cs | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ChatSharp/Events/ErrorReplieEventArgs.cs b/ChatSharp/Events/ErrorReplieEventArgs.cs index 3e1e31d..c13520e 100644 --- a/ChatSharp/Events/ErrorReplieEventArgs.cs +++ b/ChatSharp/Events/ErrorReplieEventArgs.cs @@ -4,16 +4,16 @@ using System.Net.Sockets; namespace ChatSharp.Events { /// - /// Raised when a IRC Error replie occurs. See rfc1459 6.1 for details. + /// Raised when a IRC Error reply occurs. See rfc1459 6.1 for details. /// - public class ErrorReplieEventArgs : EventArgs + public class ErrorReplyEventArgs : EventArgs { /// - /// The IRC error replie that has occured. + /// The IRC error reply that has occured. /// public IrcMessage Message { get; set; } - internal ErrorReplieEventArgs(IrcMessage message) + internal ErrorReplyEventArgs(IrcMessage message) { Message = message; } diff --git a/ChatSharp/Handlers/ErrorHandlers.cs b/ChatSharp/Handlers/ErrorHandlers.cs index 0f8ce0b..a69ff1d 100644 --- a/ChatSharp/Handlers/ErrorHandlers.cs +++ b/ChatSharp/Handlers/ErrorHandlers.cs @@ -13,7 +13,7 @@ namespace ChatSharp.Handlers /// public static void HandleError(IrcClient client, IrcMessage message) { - client.OnErrorReplie(new Events.ErrorReplieEventArgs(message)); + client.OnErrorReply(new Events.ErrorReplyEventArgs(message)); } } } diff --git a/ChatSharp/IrcClient.cs b/ChatSharp/IrcClient.cs index 4156825..875746f 100644 --- a/ChatSharp/IrcClient.cs +++ b/ChatSharp/IrcClient.cs @@ -369,10 +369,10 @@ namespace ChatSharp /// /// IRC Error Replies. rfc1459 6.1. /// - public event EventHandler ErrorReplie; - internal void OnErrorReplie(Events.ErrorReplieEventArgs e) + public event EventHandler ErrorReply; + internal void OnErrorReply(Events.ErrorReplyEventArgs e) { - if (ErrorReplie != null) ErrorReplie(this, e); + if (ErrorReply != null) ErrorReply(this, e); } /// /// Raised for errors.