private void dataSent( Object sender, ConnectionDataEventArgs e ) { string data = e.Data; this.textBox1.Text += data + System.Environment.NewLine; this.textBox1.Select(this.textBox1.Text.Length - 1, 1); this.textBox1.ScrollToCaret(); }
private void logDisconnected( Object sender, ConnectionDataEventArgs e ) { }
private void ReceiveData() { try { chatClient = new TcpClient( Address, Port ); Stream dataStream = null; if ( this.Ssl ) { dataStream = new SslStream( chatClient.GetStream(), false, ValidateServerCertificate, null ); ((SslStream)dataStream).AuthenticateAsClient( this.Address ); } else { dataStream = chatClient.GetStream(); } chatReader = new StreamReader( dataStream, this.Encoding ); chatWriter = new StreamWriter( dataStream, this.Encoding ); chatWriter.AutoFlush = true; } catch ( AuthenticationException e ) { if ( chatClient != null ) { chatClient.Close(); } this.Status = ConnectionStatus.Disconnected; this.OnDisconnected( new ConnectionDataEventArgs( e.Message ) ); return; } catch ( Exception ex ) { this.Status = ConnectionStatus.Disconnected; this.OnDisconnected( new ConnectionDataEventArgs( ex.Message ) ); return; } this.Status = ConnectionStatus.Connected; this.OnConnected( EventArgs.Empty ); String disconnectReason = ""; try { String incomingMessageLine; while ( Status == ConnectionStatus.Connected && ( ( incomingMessageLine = chatReader.ReadLine() ) != null ) ) { try { incomingMessageLine = incomingMessageLine.Trim(); this.OnDataReceived( new ConnectionDataEventArgs( incomingMessageLine ) ); } catch ( ThreadAbortException ex ) { System.Diagnostics.Trace.WriteLine( ex.Message ); Thread.ResetAbort(); disconnectReason = "Thread Aborted"; break; } } } catch ( Exception ex ) { System.Diagnostics.Trace.WriteLine( ex.ToString() ); disconnectReason = ex.Message; } this.Status = ConnectionStatus.Disconnected; if ( chatClient != null ) { chatClient.Close(); chatClient = null; } ConnectionDataEventArgs disconnectArgs = new ConnectionDataEventArgs( disconnectReason ); this.OnDisconnected( disconnectArgs ); }
private void logDisconnected(Object sender, ConnectionDataEventArgs e) { if(m_spamDebug) { String data = "*** Disconnected: " + e.Data; m_log.Warn("[RegionIRC]: " + data); } }
private void dataSent( Object sender, ConnectionDataEventArgs e ) { if (isReady) { string data = "<" + textBox2.Text + "> :" + e.Data.Substring(17); this.textBox1.Text += data + System.Environment.NewLine; this.textBox1.Select(this.textBox1.Text.Length - 1, 1); this.textBox1.ScrollToCaret(); } }
/// <summary> /// Raises the <see cref="ServerConnection.DataReceived"/> event of the <see cref="ServerConnection"/> object. /// </summary> /// <param name="data">A <see cref="ConnectionDataEventArgs"/> that contains the data.</param> protected virtual void OnDataReceived( ConnectionDataEventArgs data ) { if ( DataReceived != null ) { DataReceived( this, data ); } }
/// <summary> /// Closes the current network connection. /// </summary> public virtual void Disconnect() { Status = ConnectionStatus.Disconnected; ConnectionDataEventArgs disconnectArgs = new ConnectionDataEventArgs( "Disconnect Called" ); OnDisconnected( disconnectArgs ); }
void logDisconnected(Object sender, ConnectionDataEventArgs e) { if(m_spamDebug) { String data = "*** Disconnected: " + e.Data; MainConsole.Instance.Warn("[RegionIRC]: " + data); } }
private void dataSent( Object sender, ConnectionDataEventArgs e ) { if ( this.DataSent != null ) { this.DataSent( this, e ); } }
private void ensureIdentEnds( Object sender, ConnectionDataEventArgs e ) { Ident.Service.Stop(); }
/// <summary> /// Transforms <see cref="ClientConnection"/> data into raised <see cref="IrcMessage"/> events /// </summary> private void dataReceived( Object sender, ConnectionDataEventArgs e ) { if ( this.DataReceived != null ) { this.DataReceived( this, e ); } RouteData( e.Data ); }
/// <summary> /// This method listens for data over the network until the Connection.State is Disconnected. /// </summary> /// <remarks> /// Run runs in its own thread. /// </remarks> private void Run() { ConnectionDataEventArgs disconnectArgs; String disconnectReason = ""; try { chatListener = new TcpListener( System.Net.IPAddress.Any, this.Port ); chatListener.Start(); Debug.WriteLine( "Starting AcceptTcpClient", "ServerConnection" ); TcpClient client = chatListener.AcceptTcpClient(); this.chatReader = new StreamReader( client.GetStream(), System.Text.Encoding.UTF8 ); this.chatWriter = new StreamWriter( client.GetStream(), System.Text.Encoding.UTF8 ); setStatus( ConnectionStatus.Connected ); if ( this.synchronizationObject != null && this.synchronizationObject.InvokeRequired ) { this.synchronizationObject.Invoke( this.onConnectedDelegate, new Object[] { EventArgs.Empty } ); } else { this.OnConnected( EventArgs.Empty ); } Debug.WriteLine( "TcpClient Accepted", "ServerConnection" ); } catch ( Exception ex ) { Debug.WriteLine( "Error Opening ServerConnection On Port " + port.ToString() + ", " + ex.ToString(), "ServerConnection" ); setStatus( ConnectionStatus.Disconnected ); disconnectArgs = new ConnectionDataEventArgs( disconnectReason ); if ( this.synchronizationObject != null && this.synchronizationObject.InvokeRequired ) { this.synchronizationObject.Invoke( this.onDisconnectedDelegate, new Object[] { disconnectArgs } ); } else { this.OnDisconnected( disconnectArgs ); } throw; } try { String incomingMessageLine; while ( Status == ConnectionStatus.Connected && ( ( incomingMessageLine = chatReader.ReadLine() ) != null ) ) { try { incomingMessageLine = incomingMessageLine.Trim(); if ( this.synchronizationObject != null && this.synchronizationObject.InvokeRequired ) { this.synchronizationObject.Invoke( this.onDataReceivedDelegate, new Object[] { new ConnectionDataEventArgs( incomingMessageLine ) } ); } else { this.OnDataReceived( new ConnectionDataEventArgs( incomingMessageLine ) ); } } catch ( ThreadAbortException ex ) { Debug.WriteLine( ex.Message ); Thread.ResetAbort(); disconnectReason = "Thread Aborted"; break; } } } catch ( Exception ex ) { Debug.WriteLine( ex.ToString() ); disconnectReason = ex.Message; } setStatus( ConnectionStatus.Disconnected ); if ( chatListener != null ) { chatListener.Stop(); chatListener = null; } disconnectArgs = new ConnectionDataEventArgs( disconnectReason ); if ( this.synchronizationObject != null && this.synchronizationObject.InvokeRequired ) { try { this.synchronizationObject.Invoke( this.onDisconnectedDelegate, new Object[] { disconnectArgs } ); } catch { this.OnDisconnected( disconnectArgs ); } } else { this.OnDisconnected( disconnectArgs ); } }
/// <summary> /// Raises the <see cref="ServerConnection.Disconnected"/> event of the <see cref="ServerConnection"/> object. /// </summary> protected virtual void OnDisconnected( ConnectionDataEventArgs e ) { if ( Disconnected != null ) { Disconnected( this, e ); } }
private void dataGot( Object sender, ConnectionDataEventArgs e ) { if (e.Data.Contains(" is now registered to ")) { this.textBox1.Text = ""; this.textBox1.Text += "Registration complete. Please check your e-mail for a registration code"; } else { String data = e.Data; this.textBox1.Text += data + System.Environment.NewLine; this.textBox1.Select(this.textBox1.Text.Length - 1, 1); this.textBox1.ScrollToCaret(); } }
void RunSend() { ConnectionDataEventArgs disconnectArgs; String disconnectReason = ""; try { chatListener = new TcpListener( System.Net.IPAddress.Any, Port ); chatListener.Start(); Socket socket = chatListener.AcceptSocket(); Status = ConnectionStatus.Connected; OnConnected( EventArgs.Empty ); Transfer.TransferSocket = socket; Transfer.Send(); } catch ( Exception ex ) { System.Diagnostics.Trace.WriteLine( "Error Opening DccServerConnection On Port " + port.ToString( CultureInfo.InvariantCulture ) + ", " + ex, "DccServerConnection" ); throw; } finally { Status = ConnectionStatus.Disconnected; if ( chatListener != null ) { chatListener.Stop(); chatListener = null; } disconnectArgs = new ConnectionDataEventArgs( disconnectReason ); OnDisconnected( disconnectArgs ); } }
private void dataSent(Object sender, ConnectionDataEventArgs e) { if(m_spamDebug) { String data = "*** Sent: " + e.Data; MainConsole.Instance.Warn("[RegionIRC]: " + data); } }
/// <summary> /// Raises the <see cref="ClientConnection.DataSent"/> event of the <see cref="ClientConnection"/> object. /// </summary> /// <param name="data">A <see cref="ConnectionDataEventArgs"/> that contains the data.</param> protected virtual void OnDataSent( ConnectionDataEventArgs data ) { if ( DataSent != null ) { DataSent( this, data ); } }
private void dataGot( Object sender, ConnectionDataEventArgs e ) { if (isReady) { if (e.Data.StartsWith("PING")) { textBox1.Text += "Ping request recieved!" + Environment.NewLine; } else if (e.Data.StartsWith("ERROR")) { break; } else if (e.Data.Contains("ACTION")) { int a = e.Data.IndexOf(''); string sub = e.Data.Substring(a + 8); char[] datachars = e.Data.ToCharArray(); string user = ""; for (int i = 0; i < datachars.Length; i++) { if (datachars[i] == '!') { break; } else { user += datachars[i]; } } user = user.Substring(1); textBox1.Text += user + " " + sub + Environment.NewLine; } else { String data = e.Data; char[] datachars = data.ToCharArray(); string user = ""; for (int i = 0; i < datachars.Length; i++) { if (datachars[i] == '!') { break; } else { user += datachars[i]; } } user = user.Substring(1); string message = ""; int start = 0; for (int i = 0; i < datachars.Length; i++) { if (datachars[i] == ':') { start++; } if (start >= 2) { message += datachars[i]; } } this.textBox1.Text += "<" + user + "> :" + message + System.Environment.NewLine; this.textBox1.Select(this.textBox1.Text.Length - 1, 1); this.textBox1.ScrollToCaret(); } } else if (e.Data.Contains("End of /NAMES list.")) { isReady = true; textBox1.Text += "Connected!" + Environment.NewLine; for (int i = 0; i < General.client.Channels[0].Users.Count; i++) { listBox1.Items.Add(General.client.Channels[0].Users[i].Nick); } } else if (e.Data.Contains("This nickname is registered. Please choose a different nickname, or identify via /msg NickServ identify <password>.")) { textBox1.Text += "Nickname registered. Please authorize through the log in button or disconnect and choose a different nickname" + Environment.NewLine; } }
/// <summary> /// Raises the <see cref="ClientConnection.Disconnected"/> event of the <see cref="ClientConnection"/> object. /// </summary> protected virtual void OnDisconnected( ConnectionDataEventArgs e ) { if ( this.synchronizationObject != null && this.synchronizationObject.InvokeRequired ) { SyncInvoke del = delegate { this.OnDisconnected( e ); }; this.synchronizationObject.Invoke( del, null ); return; } if ( Disconnected != null ) { Disconnected( this, e ); } }
private void logDisconnected( Object sender, ConnectionDataEventArgs e ) { String data = "*** Disconnected: " + e.Data; this.textBox1.Text += data + System.Environment.NewLine; this.textBox1.Select( this.textBox1.Text.Length - 1, 1 ); this.textBox1.ScrollToCaret(); }
/// <summary> /// Closes the current network connection. /// </summary> public virtual void Disconnect() { setStatus( ConnectionStatus.Disconnected ); ConnectionDataEventArgs disconnectArgs = new ConnectionDataEventArgs( "Disconnect Called" ); if ( this.synchronizationObject != null && this.synchronizationObject.InvokeRequired ) { this.synchronizationObject.Invoke( this.onDisconnectedDelegate, new Object[] { disconnectArgs } ); } else { this.OnDisconnected( disconnectArgs ); } }