public NamesHandler( Server server, EventHandler<NamesCompleteEventArgs> completionHandler, MessageEventArgs ev ) { _messageFilters = new List<FilterAndHandler> { new FilterAndHandler( ( m ) => ( m.Verb == "353" ), HandleRplNamReply ), new FilterAndHandler( ( m ) => ( m.Verb == "366" ), HandleRplEndOfNames ), }; Complete += completionHandler; Server = server; HandleRplNamReply( null, ev ); }
public WhoHandler( Server server, EventHandler completionHandler, EventHandler<MessageEventArgs> responseHandler, MessageEventArgs ev ) { _messageFilters = new List<FilterAndHandler> { new FilterAndHandler( ( m ) => ( m.Verb == "352" ), HandleRplWhoReply ), new FilterAndHandler( ( m ) => ( m.Verb == "315" ), HandleRplEndOfWho ), }; Complete += completionHandler; Response += responseHandler; Server = server; HandleRplWhoReply( null, ev ); }
public WhoisHandler( Server server, EventHandler<WhoisCompleteEventArgs> completionHandler, MessageEventArgs ev ) { _messageFilters = new List<FilterAndHandler> { new FilterAndHandler( ( m ) => ( m.Verb == "311" ), HandleRplWhoisUser ), new FilterAndHandler( ( m ) => ( m.Verb == "318" ), HandleRplEndOfWhois ), new FilterAndHandler( ( m ) => ( true ), HandleDefault ), }; Complete += completionHandler; Server = server; HandleRplWhoisUser( null, ev ); }
public MotdHandler( Server server, MessageEventArgs ev, EventHandler<MotdCompleteEventArgs> completionHandler ) { _messageFilters = new List<FilterAndHandler> { new FilterAndHandler( ( m ) => ( m.Verb == "372" ), HandleRplMotd ), new FilterAndHandler( ( m ) => ( m.Verb == "375" ), HandleRplMotdStart ), new FilterAndHandler( ( m ) => ( m.Verb == "376" ), HandleRplEndOfMotd ), new FilterAndHandler( ( m ) => ( m.Verb == "422" ), HandleErrNoMotd ), }; Complete += completionHandler; Server = server; if ( ev.Message.Verb == "375" ) { HandleRplMotdStart( null, ev ); } else if ( ev.Message.Verb == "422" ) { HandleErrNoMotd( null, ev ); } else { Debug.Print( "MotdHandler.`ctor: don't know what to do with verb '{0}'!", ev.Message.Verb ); OnComplete( null ); } }
private void FinishConnection( Stream stream ) { Debug.Print( "ServerConnector.FinishConnection" ); try { _protocolHandler.ConnectionReady( stream ); _protocolHandler = null; TcpClient = null; var server = _server; _server = null; OnConnectionEstablished( server ); } catch ( Exception e ) { Debug.Print( "ServerConnector.FinishConnection: caught exception:\n{0}", e ); } }
private void ConnectCallback( IAsyncResult ar ) { bool retry = false; try { TcpClient.EndConnect( ar ); } catch ( SocketException e ) { Debug.Print( "ServerConnector.ConnectCallback: TcpClient.EndConnect: caught SocketException, error code {0}:\n{1}", e.ErrorCode, e ); OnConnectionAttemptFailed( CurrentEndPoint, e ); retry = true; } catch ( Exception e ) { Debug.Print( "ServerConnector.ConnectCallback: TcpClient.EndConnect: caught exception:\n{0}", e ); OnConnectionAttemptFailed( CurrentEndPoint, e ); retry = true; } if ( retry ) { TryEstablishConnection( ); return; } EndPointEnumerator.Dispose( ); EndPoints = null; Debug.Print( "ServerConnector.ConnectCallback: Connected!" ); SocketRegistry.Register( TcpClient.Client.LocalEndPoint as IPEndPoint, TcpClient.Client.RemoteEndPoint as IPEndPoint ); Debug.Print( "ServerConnector.ConnectCallback: Constructing objects." ); var selfUser = new SelfUser { NickName = Configuration.NickName, HostName = Configuration.LocalHostName, RealHostName = Configuration.LocalHostName, RealName = Configuration.RealName, UserName = Configuration.UserName, NickServUserName = Configuration.NickServUserName, NickServPassword = Configuration.NickServPassword, }; _server = new Server { ServerEndPoint = CurrentEndPoint, SelfUser = selfUser, ServerHostName = Configuration.ServerHostName, ServerPassword = Configuration.Password, }; _protocolHandler = new ProtocolHandler { TcpClient = TcpClient, SelfUser = selfUser, Server = _server, }; _server.ProtocolHandler = _protocolHandler; selfUser.Server = _server; if ( CurrentEndPoint.UseSsl ) { Debug.Print( "ServerConnector.ConnectCallback: Starting SSL." ); _sslStream = new SslStream( TcpClient.GetStream( ), true, ServerCertificateValidationCallback, LocalCertificateSelectionCallback, EncryptionPolicy.RequireEncryption ); try { _sslStream.BeginAuthenticateAsClient( Configuration.ServerHostName, CertificateCollection, SslProtocols.Default, true, AuthenticateAsClientCallback, null ); } catch ( Exception e ) { Debug.Print( "ServerConnector.ConnectCallback: Caught exception calling BeginAuthenticateAsClient:\n{0}", e ); throw; } } else { FinishConnection( TcpClient.GetStream( ) ); } }
protected virtual void OnConnectionEstablished( Server server ) { var handler = ConnectionEstablished; if ( null != handler ) { handler( this, new ConnectionEstablishedEventArgs( server ) ); } }
// Constructors public Message( Server server, string rawLine ) { _server = server; Parse( rawLine ); }
public ConnectionEstablishedEventArgs( Server server ) { Server = server; }
private void ConnectionEstablished( object sender, ConnectionEstablishedEventArgs ev ) { Console.WriteLine( "ConsoleHarness: ConnectionEstablished:" ); Console.WriteLine( "+ remote end point: {0}", ev.Server.ServerEndPoint ); Console.WriteLine( ); _serverConnector = null; _server = ev.Server; _protocolHandler = _server.ProtocolHandler; _selfUser = _server.SelfUser; _selfUser.Error += HandleError; _selfUser.Quit += HandleSelfQuit; _server.Registered += HandleRegistered; _server.MotdComplete += HandleMotdComplete; _connected = true; }
public Message( Server server, string rawLine ) : this() { Server = server; Parse( rawLine ); }