Merge pull request #64 from anhr/master
Catching of "No such host is known" exception
This commit is contained in:
commit
9d13c6cb21
|
@ -1,30 +1,32 @@
|
|||
|
||||
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
|
||||
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
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
<Compile Include="Events\ChannelTopicEventArgs.cs" />
|
||||
<Compile Include="Events\ChannelEventArgs.cs" />
|
||||
<Compile Include="Events\ChannelUserEventArgs.cs" />
|
||||
<Compile Include="Events\ErrorEventArgs.cs" />
|
||||
<Compile Include="Events\ErrorReplieEventArgs.cs" />
|
||||
<Compile Include="Events\IrcNoticeEventArgs.cs" />
|
||||
<Compile Include="Events\ErronousNickEventArgs.cs" />
|
||||
<Compile Include="Events\ModeChangeEventArgs.cs" />
|
||||
|
@ -55,6 +57,7 @@
|
|||
<Compile Include="Events\SupportsEventArgs.cs" />
|
||||
<Compile Include="Events\WhoIsEventArgs.cs" />
|
||||
<Compile Include="Handlers\ChannelHandlers.cs" />
|
||||
<Compile Include="Handlers\ErrorHandlers.cs" />
|
||||
<Compile Include="Handlers\ListingHandlers.cs" />
|
||||
<Compile Include="Handlers\MessageHandlers.cs" />
|
||||
<Compile Include="Handlers\MOTDHandlers.cs" />
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace ChatSharp.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Raised when a Error occurs.
|
||||
/// </summary>
|
||||
public class ErrorEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The error that has occured.
|
||||
/// </summary>
|
||||
public Exception Error { get; set; }
|
||||
|
||||
internal ErrorEventArgs(Exception error)
|
||||
{
|
||||
Error = error;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace ChatSharp.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Raised when a IRC Error reply occurs. See rfc1459 6.1 for details.
|
||||
/// </summary>
|
||||
public class ErrorReplyEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The IRC error reply that has occured.
|
||||
/// </summary>
|
||||
public IrcMessage Message { get; set; }
|
||||
|
||||
internal ErrorReplyEventArgs(IrcMessage message)
|
||||
{
|
||||
Message = message;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
using ChatSharp.Events;
|
||||
using System.Linq;
|
||||
|
||||
namespace ChatSharp.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// IRC error replies handler. See rfc1459 6.1.
|
||||
/// </summary>
|
||||
internal static class ErrorHandlers
|
||||
{
|
||||
/// <summary>
|
||||
/// IRC Error replies handler. See rfc1459 6.1.
|
||||
/// </summary>
|
||||
public static void HandleError(IrcClient client, IrcMessage message)
|
||||
{
|
||||
client.OnErrorReply(new Events.ErrorReplyEventArgs(message));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 "<nickname> :No such nick/channel"
|
||||
client.SetHandler("402", ErrorHandlers.HandleError);//ERR_NOSUCHSERVER "<server name> :No such server"
|
||||
client.SetHandler("403", ErrorHandlers.HandleError);//ERR_NOSUCHCHANNEL "<channel name> :No such channel"
|
||||
client.SetHandler("404", ErrorHandlers.HandleError);//ERR_CANNOTSENDTOCHAN "<channel name> :Cannot send to channel"
|
||||
client.SetHandler("405", ErrorHandlers.HandleError);//ERR_TOOMANYCHANNELS "<channel name> :You have joined too many \ channels"
|
||||
client.SetHandler("406", ErrorHandlers.HandleError);//ERR_WASNOSUCHNICK "<nickname> :There was no such nickname"
|
||||
client.SetHandler("407", ErrorHandlers.HandleError);//ERR_TOOMANYTARGETS "<target> :Duplicate recipients. No message \
|
||||
}
|
||||
|
||||
public static void HandleNick(IrcClient client, IrcMessage message)
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
private void DataRecieved(IAsyncResult result)
|
||||
|
@ -356,6 +366,22 @@ namespace ChatSharp
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// IRC Error Replies. rfc1459 6.1.
|
||||
/// </summary>
|
||||
public event EventHandler<Events.ErrorReplyEventArgs> ErrorReply;
|
||||
internal void OnErrorReply(Events.ErrorReplyEventArgs e)
|
||||
{
|
||||
if (ErrorReply != null) ErrorReply(this, e);
|
||||
}
|
||||
/// <summary>
|
||||
/// Raised for errors.
|
||||
/// </summary>
|
||||
public event EventHandler<Events.ErrorEventArgs> Error;
|
||||
internal void OnError(Events.ErrorEventArgs e)
|
||||
{
|
||||
if (Error != null) Error(this, e);
|
||||
}
|
||||
/// <summary>
|
||||
/// Raised for socket errors. ChatSharp does not automatically reconnect.
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue