diff --git a/ShareX.IRCLib/IRC.cs b/ShareX.IRCLib/IRC.cs index 8398add4c..ff820e64a 100644 --- a/ShareX.IRCLib/IRC.cs +++ b/ShareX.IRCLib/IRC.cs @@ -36,6 +36,9 @@ namespace ShareX.IRCLib { public class IRC : IDisposable { + public const int DefaultPort = 6667; + public const int DefaultPortSSL = 6697; + public event Action 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; } diff --git a/ShareX.IRCLib/IRCClient/IRCClientForm.cs b/ShareX.IRCLib/IRCClient/IRCClientForm.cs index 023980ed0..7b8f8afec 100644 --- a/ShareX.IRCLib/IRCClient/IRCClientForm.cs +++ b/ShareX.IRCLib/IRCClient/IRCClientForm.cs @@ -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); diff --git a/ShareX.IRCLib/IRCInfo.cs b/ShareX.IRCLib/IRCInfo.cs index 0bf1c79ae..aab8b456b 100644 --- a/ShareX.IRCLib/IRCInfo.cs +++ b/ShareX.IRCLib/IRCInfo.cs @@ -35,8 +35,8 @@ public class IRCInfo : SettingsBase [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;