diff --git a/Combot.csproj b/Combot.csproj index c043f67..9109a78 100755 --- a/Combot.csproj +++ b/Combot.csproj @@ -40,7 +40,7 @@ - + diff --git a/IRCService.cs b/IRCService.cs index 84bba68..33e182b 100755 --- a/IRCService.cs +++ b/IRCService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Net; namespace Combot { @@ -15,6 +16,22 @@ namespace Combot _tcp = new TCPInterface(); } - + internal bool Connect(IPAddress IP, int port, int readTimeout, int allowedFailedCount = 0) + { + bool result = false; + if (!_tcp.Connected) + { + result = _tcp.Connect(IP, port, readTimeout, allowedFailedCount); + } + + return result; + } + + internal bool Disconnect() + { + bool result = false; + + return result; + } } } diff --git a/Interface.cs b/Methods.cs similarity index 85% rename from Interface.cs rename to Methods.cs index 8127f28..dda7b09 100755 --- a/Interface.cs +++ b/Methods.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Combot { - public class Interface + public class Methods { } } diff --git a/TCP/TCPInterface.cs b/TCP/TCPInterface.cs index e5ecc68..5fd3c05 100755 --- a/TCP/TCPInterface.cs +++ b/TCP/TCPInterface.cs @@ -13,6 +13,7 @@ namespace Combot { internal event Action TCPErrorEvent; internal event Action TCPConnectionEvent; + internal bool Connected = false; private IPEndPoint _serverIP = null; private int _readTimeout = 250; @@ -39,6 +40,7 @@ namespace Combot _tcpClient.ReceiveTimeout = _readTimeout; _tcpStream = new NetworkStream(_tcpClient); + Connected = true; return true; } catch @@ -55,6 +57,7 @@ namespace Combot internal void Disconnect() { + Connected = false; if (_tcpStream != null) { _tcpStream.Close(); @@ -67,7 +70,7 @@ namespace Combot internal void Write(string data) { - if (_tcpStream.CanWrite) + if (_tcpStream.CanWrite && Connected) { byte[] message = System.Text.Encoding.UTF8.GetBytes(data + Environment.NewLine); _tcpStream.Write(message, 0, message.Length); @@ -78,7 +81,7 @@ namespace Combot { try { - if (_tcpStream.CanRead) + if (_tcpStream.CanRead && Connected) { byte[] readBytes = new byte[100000]; _tcpStream.Read(readBytes, 0, readBytes.Length);