Represents a raw irc line received over an irc connection.
Allows to analyze a raw irc line. The raw line is automatically broken down to it single propertys according to rfc 1459. They can be easily accessed by the given class propertys.
Inheritance: IIrcObject
Ejemplo n.º 1
0
 public void BaseLine()
 {
     UserInfo info = new UserInfo(client, "[email protected]");
     Assert.IsNull(info.BaseLine);
     IrcLine line = new IrcLine(client, ":[email protected] CMD :test");
     info = new UserInfo(line);
     Assert.AreSame(line, info.BaseLine);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the KickReceivedEventArgs class.
 /// </summary>
 /// <param name="line">The line with the kick command.</param>
 public KickReceivedEventArgs(IrcLine line)
     : base(line)
 {
     kicker = new UserInfo(line);
     kickedName = line.Parameters[1];
     channelName = line.Parameters[0];
     reason = line.Parameters[2];
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the PartReceivedEventArgs class.
        /// </summary>
        /// <param name="line">The line to create the event args from.</param>
        public PartReceivedEventArgs(IrcLine line)
            : base(line)
        {
            user = new UserInfo(line);
            channelName = line.Parameters[0];

            if (line.Parameters.Length > 1)
            {
                partMessage = line.Parameters[1];
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the QuitReceivedEventArgs class.
        /// </summary>
        /// <param name="line">The line containing the quit command.</param>
        public QuitReceivedEventArgs(IrcLine line)
            : base(line)
        {
            user = new UserInfo(line);

            if (line.Parameters.Length > 0)
            {
                quitMessage = line.Parameters[0];
            }
            else
            {
                quitMessage = string.Empty;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the BadNickEventArgs class.
        /// </summary>
        /// <param name="baseLine">The line, what created the bad nick event.</param>
        /// <param name="inLogin">Determines if the event was fired in the login state.</param>
        public BadNickEventArgs(IrcLine baseLine, bool inLogin)
            : base(baseLine)
        {
            switch (baseLine.Numeric)
            {
                case 432:
                    reason = BadNickReasons.ErroneusNickname;
                    break;
                case 433:
                    reason = BadNickReasons.NicknameInUse;
                    break;
                default:
                    throw new ArgumentException("The given line is no 432 or 433 numeric", "baseLine");
            }

            isLogin = inLogin;
        }
Ejemplo n.º 6
0
 public void Constructor()
 {
     IrcClient client = new IrcClient();
     IrcLine erroneousNick = new IrcLine(client, ":prefix 432 :Erroneous nickname");
     IrcLine nickInUse = new IrcLine(client, ":prefix 433 :Nickname is already in use");
     BadNickEventArgs args = new BadNickEventArgs(erroneousNick, true);
     Assert.IsTrue(args.IsLogin);
     Assert.AreEqual(BadNickReasons.ErroneusNickname, args.Reason);
     args = new BadNickEventArgs(nickInUse, false);
     Assert.IsFalse(args.IsLogin);
     Assert.AreEqual(BadNickReasons.NicknameInUse, args.Reason);
     args = new BadNickEventArgs(erroneousNick, false);
     Assert.IsFalse(args.IsLogin);
     Assert.AreEqual(BadNickReasons.ErroneusNickname, args.Reason);
     args = new BadNickEventArgs(nickInUse, true);
     Assert.IsTrue(args.IsLogin);
     Assert.AreEqual(BadNickReasons.NicknameInUse, args.Reason);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the MessageReceivedEventArgs class.
        /// </summary>
        /// <param name="line">The line with the message.</param>
        public MessageReceivedEventArgs(IrcLine line)
            : base(line)
        {
            sender = new UserInfo(line);
            string l;
            l = Message;

            if (l[0] == '\x01' && l[l.Length - 1] == '\x01')
            {
                l = l.Substring(1, l.Length - 2);
                ctcpCommandString = l;
                int firstSpace = l.IndexOf(' ');

                if (firstSpace > 0)
                {
                    ctcpCommandString = l.Substring(0, firstSpace);
                    ctcpParameters = l.Substring(firstSpace + 1);
                }

                switch (ctcpCommandString)
                {
                    case "ACTION":
                        ctcpCommand = CtcpCommands.Action;
                        break;

                    case "VERSION":
                        ctcpCommand = CtcpCommands.Version;
                        break;

                    default:
                        ctcpCommand = CtcpCommands.Unkown;
                        break;
                }
            }
            else
            {
                ctcpCommand = CtcpCommands.None;
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the UserInfo class based on the given <see cref="IrcLine" />.
 /// </summary>
 /// <param name="baseLine">
 /// The <see cref="IrcLine"/> this UserInfo was build from.
 /// </param>
 public UserInfo(IrcLine baseLine)
 {
     this.baseLine = baseLine;
     Match hostPieces;
     hostPieces = hostRegex.Match(BaseLine.Prefix);
     if (hostPieces.Success)
     {
         nickName = hostPieces.Groups[1].Value;
         ident = hostPieces.Groups[2].Value;
         this.host = hostPieces.Groups[3].Value;
         this.client = BaseLine.Client;
     }
     else
     {
         throw new ArgumentException("Malformed userhost can't be parsed correctly", "baseLine");
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the UserInfo class, based on an existing UserInfo.
 /// </summary>
 /// <param name="source">The UserInfo instance to copy from.</param>
 public UserInfo(UserInfo source)
 {
     baseLine = source.BaseLine;
     client = source.Client;
     host = source.Host;
     ident = source.Ident;
     nickName = source.NickName;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the PingReceivedEventArgs class.
 /// </summary>
 /// <param name="line">The line what holds the ping event.</param>
 public PingReceivedEventArgs(IrcLine line)
     : base(line)
 {
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the IrcEventArgs class.
 /// </summary>
 /// <param name="line">The line, the EventArgs where created from.</param>
 public IrcEventArgs(IrcLine line)
 {
     client = line.Client;
     this.line = line;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Fires the LineReceived event.
 /// </summary>
 /// <param name="line">The line that was received.</param>
 protected virtual void OnLineReceived(IrcLine line)
 {
     KickReceivedEventArgs kickArgs = new KickReceivedEventArgs(line);
     if (KickReceived != null)
     {
         KickReceived(this, kickArgs);
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the JoinReceivedEventArgs class.
 /// </summary>
 /// <param name="line">The line to create the event args from.</param>
 public JoinReceivedEventArgs(IrcLine line)
     : base(line)
 {
     user = new UserInfo(line);
     channelName = line.Parameters[0];
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the NumericReceivedEventArgs class.
 /// </summary>
 /// <param name="line">The line with the numeric command.</param>
 public NumericReceivedEventArgs(IrcLine line)
     : base(line)
 {
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the IrcLine class as a copy of another IrcLine object.
 /// </summary>
 /// <param name="source">
 /// The <see cref="IrcLine"/> to copy.
 /// </param>
 public IrcLine(IrcLine source)
 {
     prefix = source.Prefix;
     command = source.Command;
     parameters = source.Parameters;
     client = source.Client;
     numeric = source.Numeric;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the NoticeReceivedEventArgs class.
 /// </summary>
 /// <param name="line">The line creating the notice event.</param>
 public NoticeReceivedEventArgs(IrcLine line)
     : base(line)
 {
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Reads a new line from the server.
        /// </summary>
        /// <remarks>
        /// This method blocks the calling thread until a new line was received from server.
        /// Only use this method, if you want to bypass the automatically raised events and kine handling.
        /// If you want to have this features use <see cref="IrcClient.ReceiveLine" /> instead.
        /// </remarks>
        /// <returns>The received line.</returns>
        public IrcLine ReadLine()
        {
            string line;
            if (Connected)
            {
                try
                {
                    if (inStream == null)
                    {
                        return null;
                    }

                    line = inStream.ReadLine();
                    if (line != null)
                    {
                        IrcLine ircLine = new IrcLine(this, line);
                        return ircLine;
                    }
                }
                catch (InvalidLineFormatException ex)
                {
                    OnError(ex.Message, ex);
                }
                catch (Exception ex)
                {
                    OnError("Couldn't receive line", ex);
                }
            }

            return null;
        }