If IRC port invalid then use default port

This commit is contained in:
Jaex 2015-09-05 12:06:10 +03:00
parent cb4000e18f
commit 2de259e696
3 changed files with 25 additions and 12 deletions

View file

@ -36,6 +36,9 @@ namespace ShareX.IRCLib
{
public class IRC : IDisposable
{
public const int DefaultPort = 6667;
public const int DefaultPortSSL = 6697;
public event Action<MessageInfo> Output;
public event Action Connected, Disconnected;
public delegate void MessageEventHandler(UserInfo user, string channel, string message);
@ -101,14 +104,30 @@ public void Connect()
IsConnected = false;
disconnecting = false;
tcp = new TcpClient(Info.Server, Info.Port);
tcp.NoDelay = true;
int port = Info.Port;
if (port <= 0)
{
if (Info.UseSSL)
{
port = DefaultPortSSL;
}
else
{
port = DefaultPort;
}
}
tcp = new TcpClient(Info.Server, port)
{
NoDelay = true
};
Stream networkStream = tcp.GetStream();
if (Info.UseSSL)
{
RemoteCertificateValidationCallback callback = (sender, certificate, chain, sslPolicyErrors) => true;
SslStream sslStream = new SslStream(networkStream, false, callback);
SslStream sslStream = new SslStream(networkStream, false, (sender, certificate, chain, sslPolicyErrors) => true);
sslStream.AuthenticateAsClient(Info.Server);
networkStream = sslStream;
}

View file

@ -172,12 +172,6 @@ private bool CheckInfo()
return false;
}
if (Info.Port <= 0)
{
MessageBox.Show("Invalid server port.", "ShareX - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (string.IsNullOrEmpty(Info.Nickname))
{
MessageBox.Show("Nickname field cannot be empty.", "ShareX - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

View file

@ -35,8 +35,8 @@ public class IRCInfo : SettingsBase<IRCInfo>
[Category("\t\tServer info"), Description("IRC server address. Example: chat.freenode.net"), DefaultValue("chat.freenode.net")]
public string Server { get; set; } = "chat.freenode.net";
[Category("\t\tServer info"), Description("IRC server port. Default: 6667. Default SSL: 6697"), DefaultValue(6667)]
public int Port { get; set; } = 6667;
[Category("\t\tServer info"), Description("IRC server port. Default: 6667. Default SSL: 6697"), DefaultValue(IRC.DefaultPort)]
public int Port { get; set; } = IRC.DefaultPort;
[Category("\t\tServer info"), Description("Will use SSL connection. You must use correct SSL port of the IRC server."), DefaultValue(false)]
public bool UseSSL { get; set; } = false;