Пример #1
0
        // Numeric 311
        public void HandleRplWhoisUser( object sender, MessageEventArgs ev )
        {
            _responses.Clear( );
            _responses.Add( ev.Message );

            OnResponse( ev.Message );
        }
Пример #2
0
        // Numeric 318
        private void HandleRplEndOfWhois( object sender, MessageEventArgs ev )
        {
            _responses.Add( ev.Message );

            OnResponse( ev.Message );
            OnComplete( new NickUserHost( ev.Message.Target ) );
        }
Пример #3
0
        // Numeric 353
        //    ( '=' / '*' / '@' ) <channel> ' ' : [ '@' / '+' ] <nick> *( ' ' [ '@' / '+' ] <nick> )
        public void HandleRplNamReply( object sender, MessageEventArgs ev )
        {
            Target = ev.Message.Args[ 1 ];
            switch ( ev.Message.Args[ 0 ] ) {
                case "=":
                    ChannelVisibility = ChannelVisibility.Public;
                    break;

                case "@":
                    ChannelVisibility = ChannelVisibility.Secret;
                    break;

                case "*":
                    ChannelVisibility = ChannelVisibility.Other;
                    break;

                default:
                    Debug.Print( "NamesHandler.HandleRplNamReply: unknown channel type '{0}'", ev.Message.Args[ 0 ] );
                    break;
            }

            foreach ( var nickName in ev.Message.Args[2].Split( CommonDelimiters.Space, StringSplitOptions.RemoveEmptyEntries ) ) {
                _nickNames.Add( nickName );
            }
        }
Пример #4
0
 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 );
 }
Пример #5
0
 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 );
 }
Пример #6
0
 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 );
 }
Пример #7
0
        // Numeric 353
        //    ( '=' / '*' / '@' ) <channel> ' ' : [ '@' / '+' ] <nick> *( ' ' [ '@' / '+' ] <nick> )
        private void HandleRplNamReply( object sender, MessageEventArgs ev )
        {
            if ( !ChannelVisibilityStringMap.ContainsKey( ev.Message.Args[0] ) ) {
                Debug.Print( "NamesHandler.HandleRplNamReply: warning: unknown channel type '{0}'", ev.Message.Args[0] );
            } else {
                ChannelVisibility = ChannelVisibilityStringMap[ev.Message.Args[0]];
            }
            Target = ev.Message.Args[1];

            foreach ( var nickName in ev.Message.Args[2].Split( CommonDelimiters.Space, StringSplitOptions.RemoveEmptyEntries ) ) {
                _nickNames.Add( nickName );
            }
        }
Пример #8
0
        private void HandleDefault( object sender, MessageEventArgs ev )
        {
            int numeric = -1;
            if ( int.TryParse( ev.Message.Verb, NumberStyles.None, CultureInfo.InvariantCulture, out numeric ) ) {
                if ( 3 == ev.Message.Verb.Length && numeric >= 400 && numeric < 600 ) {
                    Debug.Print( "WhoisHandler.HandleDefault: Received numeric '{0}', aborting", ev.Message.Verb );
                    OnComplete( null );
                }
            }
            _responses.Add( ev.Message );

            OnResponse( ev.Message );
        }
Пример #9
0
 protected virtual void HandleNotice( object sender, MessageEventArgs ev )
 {
     Debug.Print( "SelfUser.HandleNotice: origin='{0}' target='{1}' args='{2}'", ev.Message.Origin, ev.Message.Target, string.Join( "','", ev.Message.Args ) );
     if ( !_nickUserHost.NickName.Equals( ev.Message.Target, StringComparison.OrdinalIgnoreCase ) ) {
         Debug.Print( "+ Not for us: '{0}' vs '{1}'", ev.Message.Target, _nickUserHost.NickName );
         return;
     }
     if ( ev.Message.Origin.NickName.Equals( "NickServ", StringComparison.OrdinalIgnoreCase) ) {
         HandleNickServNotice( sender, ev );
         return;
     }
     OnNoticeReceived( sender, new NoticeReceivedEventArgs( _server.LookUpUser( ev.Message.Origin.NickName ), _server.LookUpTarget( ev.Message.Target ), ev.Message.Args[0] ) );
 }
Пример #10
0
        // Numeric 352
        public void HandleRplWhoReply( object sender, MessageEventArgs ev )
        {
            if ( null == Target ) {
                var targetName = ev.Message.Args[ 0 ];
                Debug.Print( "WhoHandler.HandleRplWhoReply: Setting target to {0}", targetName );
                if ( Server.Channels.ContainsKey( targetName ) ) {
                    Target = Server.Channels[ targetName ];
                } else if ( Server.Users.ContainsKey( targetName ) ) {
                    Target = Server.Users[ targetName ];
                } else {
                    Target = null;
                }
            }

            _responses.Add( ev.Message );
            OnResponse( ev.Message );
        }
Пример #11
0
 protected override void HandleNotice( object sender, MessageEventArgs ev )
 {
     Debug.Print( "SelfUser.HandleNotice: origin='{0}' target='{1}' args='{2}'", ev.Message.Origin, ev.Message.Target, string.Join( "','", ev.Message.Args ) );
     if ( ev.Message.Origin.NickName.Equals( "NickServ", StringComparison.OrdinalIgnoreCase ) ) {
         if ( ev.Message.Args[ 0 ].StartsWith( "This nickname is registered.", StringComparison.OrdinalIgnoreCase ) ) {
             if ( string.IsNullOrWhiteSpace( NickServUserName ) && string.IsNullOrWhiteSpace( NickServPassword ) ) {
                 Debug.Print( "SelfUser.HandleNotice: NickServ has requested authentication, but we don't have any to give it. skipping." );
                 return;
             }
             Debug.Print( "SelfUser.HandleNotice: authenticating to NickServ. username='******' password='******'", NickServUserName ?? "", NickServPassword ?? "" );
             if ( string.IsNullOrWhiteSpace( NickServUserName ) ) {
                 ProtocolHandler.SendToServer( "PRIVMSG NickServ :identify {0}", NickServPassword );
             } else {
                 ProtocolHandler.SendToServer( "PRIVMSG NickServ :identify {0} {1}", NickServUserName, NickServPassword );
             }
         }
     }
 }
Пример #12
0
        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 );
            }
        }
Пример #13
0
 private void HandlePing( object sender, MessageEventArgs ev )
 {
     _protocolHandler.SendToServer( "PONG :{0}", string.Join( " ", ev.Message.Args ) );
 }
Пример #14
0
        private void HandleRawWhoMessage( object sender, MessageEventArgs ev )
        {
            if ( null == _whoResponseParser ) {
                _whoResponseParser = new WhoResponseParser {
                    ProtocolHandler = _protocolHandler,
                    Server = this,
                };
            }
            if ( null == _whoResponses ) {
                _whoResponses = new Collection<WhoResponse>( );
            }

            if ( ev.Message.Verb.Equals( "352" ) ) {
                try {
                    _whoResponses.Add( _whoResponseParser.ParseResponse( ev.Message ) );
                }
                catch ( Exception e ) {
                    Debug.Print( "Server.HandleRawWhoMessage: caught exception trying to parse 352 message:\n{0}", e );
                }
            }
        }
Пример #15
0
 //
 // Verb event handlers
 //
 private void HandleError( object sender, MessageEventArgs ev )
 {
     DebugDumpEvent( ev );
     // TODO
 }
Пример #16
0
 private void HandleJoin( object sender, MessageEventArgs ev )
 {
     var target = ev.Message.Args[0];
     var channel = LookUpChannel( target );
     if ( null == channel ) {
         channel = new Channel {
             Name     = target,
             Server   = this,
             SelfUser = SelfUser,
         };
         _channels.Add( channel.Name, channel );
     }
 }
Пример #17
0
 protected override void HandleQuit(object sender, MessageEventArgs ev)
 {
     OnQuit(ev.Message);
 }
Пример #18
0
 //
 // Methods
 //
 private void DebugDumpEvent( MessageEventArgs ev )
 {
     if ( DebugDumpEventEnable.Enabled ) {
         Debug.Print( "{0}|{1} => {2}|'{3}'", ev.Message.Verb, ev.Message.Origin, ev.Message.Target, string.Join( "','", ev.Message.Args ) );
     }
 }
Пример #19
0
 protected override void HandlePrivMsg(object sender, MessageEventArgs ev)
 {
     Debug.Print("SelfUser.HandlePrivMsg: origin='{0}' target='{1}' args='{2}'", ev.Message.Origin, ev.Message.Target, string.Join("','", ev.Message.Args));
 }
Пример #20
0
 // Numeric 005
 private void HandleRplISupport( object sender, MessageEventArgs ev )
 {
     _supportedFeatures.ParseFeatureList( ev.Message.Args );
 }
Пример #21
0
 // Numeric 352
 private void HandleRplWhoReply( object sender, MessageEventArgs ev )
 {
     _protocolHandler.StartCapture( "Server.HandleRplWhoReply running WhoHandler" );
     var whoHandler = new WhoHandler( this, HandleRawWhoComplete, HandleRawWhoMessage, ev );
 }
Пример #22
0
        //
        // Numeric event handlers
        //
        // Numeric 001
        private void HandleRplWelcome( object sender, MessageEventArgs ev )
        {
            _isRegistered = true;
            SelfUser.NickName = ev.Message.Target;

            var s = ev.Message.Args[ev.Message.Args.Count - 1];
            var index = s.LastIndexOf( ' ' );
            if ( index > -1 ) {
                SelfUser.NickUserHost = new NickUserHost( s.Substring( index + 1 ) );
            }

            OnRegistered( SelfUser.NickName );
        }
Пример #23
0
 // Numeric 004
 private void HandleRplMyInfo( object sender, MessageEventArgs ev )
 {
     DebugDumpEvent( ev );
     _serverName = ev.Message.Args[0];
     _serverInformation.ServerSoftware = ev.Message.Args[1];
     _serverInformation.UserModes.All = ev.Message.Args[2];
 }
Пример #24
0
 // Numeric 375
 private void HandleRplMotdStart( object sender, MessageEventArgs ev )
 {
     _protocolHandler.StartCapture( "Server.HandleRplMotdStart/HandleErrNoMotd running MotdHandler" );
     var motdHandler = new MotdHandler( this, ev, HandleMotdComplete );
 }
Пример #25
0
 // Methods
 // Event handlers
 protected virtual void HandleJoin( object sender, MessageEventArgs ev )
 {
     Debug.Print( "User.HandleJoin: sender type='{0}' args='{1}'", sender.GetType( ).Name, string.Join( "','", ev.Message.Args ) );
 }
Пример #26
0
 // Numeric 353
 private void HandleRplNamReply( object sender, MessageEventArgs ev )
 {
     _protocolHandler.StartCapture( "Server.HandleRplNamReply running NamesHandler" );
     var namesHandler = new NamesHandler( this, HandleNamesComplete, ev );
 }
Пример #27
0
 protected virtual void HandleNick( object sender, MessageEventArgs ev )
 {
     Debug.Print( "User.HandleNick: oldNick='{0}' newNick='{1}'", _nickUserHost.NickName, ev.Message.Args[0] );
     NickName = ev.Message.Args[0];
 }
Пример #28
0
 // Numeric 311
 private void HandleRplWhoisUser( object sender, MessageEventArgs ev )
 {
     _protocolHandler.StartCapture( "Server.HandleRplWhoisUser running WhoisHandler" );
     var whoisHandler = new WhoisHandler( this, HandleWhoisComplete, ev );
 }
Пример #29
0
 protected virtual void HandleQuit( object sender, MessageEventArgs ev )
 {
     Debug.Print( "User.HandleQuit: origin='{0}' target='{1}' args='{2}'", ev.Message.Origin, ev.Message.Target, string.Join( "','", ev.Message.Args ) );
     OnQuit( _server.LookUpOrRegisterUser( ev.Message.Origin ), string.Join( " ", ev.Message.Args ) );
 }
Пример #30
0
 private void HandleServerNotice( object sender, MessageEventArgs ev )
 {
     Debug.Print( "Server.HandleServerNotice: origin='{0}' [target='{1}'] text='{2}'", ev.Message.Origin, ev.Message.Target, ev.Message.Args[0] );
     OnServerNotice( ev.Message.Origin, ev.Message.Args[0] );
 }
Пример #31
0
        protected virtual void HandleUserMode( object sender, MessageEventArgs ev )
        {
            Debug.Print( "SelfUser.HandleUserMode: target='{0}' mode change='{1}' mode args={2}", ev.Message.Target, ev.Message.Args[0], ev.Message.Args.Count > 1 ? "'" + ev.Message.Args[1] + "'" : "(none)" );

            var index = _userMode.IndexOf( ' ' );
            var currentMode = ( index > -1 ) ? _userMode.Substring( 0, index ) : _userMode;
            var positive = true;
            foreach ( var ch in ev.Message.Args[0] ) {
                switch ( ch ) {
                    case '+':
                        positive = true;
                        break;

                    case '-':
                        positive = false;
                        break;

                    default:
                        index = currentMode.IndexOf( ch );
                        if ( index > -1 ) {
                            // already in currentModes
                            if ( !positive ) {
                                currentMode = currentMode.Remove( index, 1 );
                            }
                        } else {
                            // not in currentModes
                            if ( positive ) {
                                currentMode += ch;
                            }
                        }
                        break;
                }
            }
            _userMode = currentMode;

            Debug.Print( "SelfUser.HandleUserMode: new user mode: {0}", _userMode );
            // TODO
        }
Пример #32
0
 // Methods
 // Numeric 315
 private void HandleRplEndOfWho( object sender, MessageEventArgs ev )
 {
     OnResponse( ev.Message );
     OnComplete( );
 }
Пример #33
0
        // Event handlers

        protected virtual void HandleError(object sender, MessageEventArgs ev)
        {
            OnError(ev.Message);
        }