The LineReceivedEventArgs belongs to the IrcClient.LineReceivedEventHandler and the IrcClient.LineReceived event.
Inheritance: IrcEventArgs
Ejemplo n.º 1
0
        /// <summary>
        /// Handles a line received from server.
        /// </summary>
        /// <param name="e">The arguments for the received line.</param>
        private void HandleLine(LineReceivedEventArgs e)
        {
            if (e.Line.IsNumeric)
            {
                if (NumericReceived != null)
                {
                    NumericReceived(this, new NumericReceivedEventArgs(e.Line));
                }

                switch (e.Line.Numeric)
                {
                    case 1: // Parse the Server Info
                        currentNickname = e.Line.Parameters[0];
                        network = e.Line.Parameters[1].Split(' ')[3];
                        self = new UserInfo(this, e.Line.Parameters[1].Split(' ')[6]);
                        break;

                    case 3: // Parse Welcome-Message
                        OnOnLogin();
                        break;

                    case 376: // End of MOTD message
                        // OnOnLogin();
                        break;
                }
            }
            else
            {
                e.Handled = true;
                switch (e.Line.Command)
                {
                    case "PING": // Handle the Ping here
                        PingReceivedEventArgs pingArgs = new PingReceivedEventArgs(e.Line);
                        if (PingReceived != null)
                        {
                            PingReceived(this, pingArgs);
                        }

                        if (!pingArgs.Handled)
                        {
                            if (e.Line.Parameters.Length > 0)
                            {
                                SendLine("PONG :" + e.Line.Parameters[0]);
                            }
                            else
                            {
                                SendLine("PONG");
                            }
                        }

                        break;

                    case "JOIN": // Parse Join-Message
                        JoinReceivedEventArgs joinArgs = new JoinReceivedEventArgs(e.Line);
                        if (JoinReceived != null)
                        {
                            JoinReceived(this, joinArgs);
                        }

                        break;

                    case "PART": // Parse Part-Message
                        PartReceivedEventArgs partArgs = new PartReceivedEventArgs(e.Line);
                        if (PartReceived != null)
                        {
                            PartReceived(this, partArgs);
                        }

                        break;

                    case "QUIT": // Parse Quit-Message
                        QuitReceivedEventArgs quitArgs = new QuitReceivedEventArgs(e.Line);
                        if (QuitReceived != null)
                        {
                            QuitReceived(this, quitArgs);
                        }

                        break;

                    case "NICK": // Parse Nick-Message
                        if (e.Line.Client.ToString() == this.ToString())
                        {
                            this.currentNickname = e.Line.Parameters[0];
                        }

                        NickChangeReceivedEventArgs nickChangeArgs = new NickChangeReceivedEventArgs(e.Line);
                        if (NickChangeReceived != null)
                        {
                            NickChangeReceived(this, nickChangeArgs);
                        }

                        break;

                    case "MODE": // Parse Mode-Message
                        ModeReceivedEventArgs modeArgs = new ModeReceivedEventArgs(e.Line);
                        if (ModeReceived != null)
                        {
                            ModeReceived(this, modeArgs);
                        }

                        break;

                    case "NOTICE": // Parse Notice-Message
                        NoticeReceivedEventArgs noticeArgs = new NoticeReceivedEventArgs(e.Line);
                        if (NoticeReceived != null)
                        {
                            NoticeReceived(this, noticeArgs);
                        }

                        break;

                    case "PRIVMSG": // Parse Private-Message
                        MessageReceivedEventArgs privmsgArgs = new MessageReceivedEventArgs(e.Line);
                        if (MessageReceived != null)
                        {
                            MessageReceived(this, privmsgArgs);
                        }

                        break;

                    case "KICK": // Parse Kick-Message
                        OnLineReceived(e.Line);
                        break;

                    default:
                        e.Handled = false;
                        break;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads the next line, raise all events and handle it if needed.
        /// </summary>
        /// <remarks>
        /// This method does the same as <see cref="IrcClient.ReadLine" /> does but additionally
        /// raise all events of the line. If the line is a PING line, it is handled and automatically
        /// answered by an according PONG.
        /// </remarks>
        public void ReceiveLine()
        {
            IrcLine line = ReadLine();
            if (line == null)
            {
                return;
            }

            LineReceivedEventArgs args = new LineReceivedEventArgs(line);
            if (LineReceived != null)
            {
                LineReceived(this, args);
            }

            if (!args.Handled)
            {
                HandleLine(args);
            }
        }