Manages a simple irc connection on a low raw level.
With an instance of IrcClient, you can connect to an irc server and receive many events defined by the standard irc protocol. The messages received are automatically parsed to IrcLine objects to be easier accessible. After connection was established, you should call ReceiveLine to get the lines from the server.
Inheritance: IDisposable
示例#1
0
文件: IrcLine.cs 项目: hapm/IrcShark
        /// <summary>
        /// Initializes a new instance of the IrcLine class from the the given raw string.
        /// </summary>
        /// <param name="client">
        /// The <see cref="IrcClient"/>, this line was received by.
        /// </param>
        /// <param name="line">
        /// The raw line as a <see cref="System.String"/>.
        /// </param>
        /// <exception cref="InvalidLineFormatException">If the format of the raw string can't be parsed as an irc line, an InvalidLineFormatException is thrown.</exception>
        public IrcLine(IrcClient client, string line)
        {
            this.client = client;
            string[] normalParams;
            Match m = ircLineRegEx.Match(line);
            if (m.Success)
            {
                if (m.Groups[1].Success)
                {
                    prefix = m.Groups[1].Value;
                }

                command = m.Groups[2].Value;
                if (!Int32.TryParse(command, out numeric))
                {
                    numeric = 0;
                }

                normalParams = m.Groups[3].Value.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (m.Groups[4].Success)
                {
                    parameters = new string[normalParams.Length + 1];
                    normalParams.CopyTo(parameters, 0);
                    parameters[parameters.Length - 1] = m.Groups[4].Value;
                }
                else if (normalParams.Length != 0)
                {
                    parameters = normalParams;
                }
            }
            else
            {
                throw new InvalidLineFormatException(line);
            }
        }
示例#2
0
文件: UserInfo.cs 项目: hapm/IrcShark
 /// <summary>
 /// Initializes a new instance of the UserInfo class based on the host.
 /// </summary>
 /// <param name="client">
 /// The <see cref="IrcClient"/> this UserInfo belongs to.
 /// </param>
 /// <param name="host">
 /// A host as described in rfc 1459 as a <see cref="System.String"/>.
 /// </param>
 public UserInfo(IrcClient client, string host)
 {
     Match hostPieces;
     hostPieces = hostRegex.Match(host);
     if (hostPieces.Success)
     {
         nickName = hostPieces.Groups[1].Value;
         ident = hostPieces.Groups[2].Value;
         this.host = hostPieces.Groups[3].Value;
         this.client = client;
     }
     else
     {
         throw new ArgumentException("Malformed userhost can't be parsed correctly", "host");
     }
 }
示例#3
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);
 }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the ConnectEventArgs class.
 /// </summary>
 /// <param name="client">The client the event was fired from.</param>
 public ConnectEventArgs(IrcClient client)
     : base(client)
 {
 }
示例#5
0
 public void TestFixtureSetUp()
 {
     client = new IrcClient();
 }
示例#6
0
文件: UserInfo.cs 项目: hapm/IrcShark
 /// <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");
     }
 }
示例#7
0
文件: UserInfo.cs 项目: hapm/IrcShark
 /// <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;
 }
示例#8
0
文件: UserInfo.cs 项目: hapm/IrcShark
 /// <summary>
 /// Initializes a new instance of the UserInfo class with the given values.
 /// </summary>
 /// <param name="nickName">The nickname of the user.</param>
 /// <param name="ident">The ident of the user.</param>
 /// <param name="host">The user host.</param>
 /// <param name="client">The client, where the user was seen on.</param>
 public UserInfo(string nickName, string ident, string host, IrcClient client)
 {
     this.nickName = nickName;
     this.ident = ident;
     this.host = host;
     this.client = client;
 }
示例#9
0
 /// <summary>
 /// Initializes a new instance of the LoginEventArgs class.
 /// </summary>
 /// <param name="networkName">The name of the network.</param>
 /// <param name="nick">The accepted nickname.</param>
 /// <param name="client">The client, what logged in.</param>
 public LoginEventArgs(string networkName, string nick, IrcClient client)
     : base(client)
 {
     this.networkName = networkName;
     this.nick = nick;
 }
示例#10
0
 /// <summary>
 /// Initializes a new instance of the IrcStandardDefinition class and associates it with the given client.
 /// </summary>
 /// <param name="client">
 /// The <see cref="IrcClient"/>, this StandardDefinition belongs to.
 /// </param>
 public IrcStandardDefinition(IrcClient client)
 {
     this.client = client;
 }
示例#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;
 }
示例#12
0
 /// <summary>
 /// Initializes a new instance of the IrcEventArgs class.
 /// </summary>
 /// <param name="client">The client instance, the EventArgs belongs to.</param>
 public IrcEventArgs(IrcClient client)
 {
     this.client = client;
 }
示例#13
0
文件: IrcLine.cs 项目: hapm/IrcShark
 /// <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;
 }
示例#14
0
文件: IrcLine.cs 项目: hapm/IrcShark
        /// <summary>
        /// Initializes a new instance of the IrcLine class based on the parameters given.
        /// </summary>
        /// <remarks>
        /// The parameters array can only have one parameter with spaces in it, and this one need to be the last one!
        /// </remarks>
        /// <exception cref="InvalidLineFormatException">
        /// This exception is thrown if prefix, command or anyone of the parameters 
        /// excepting the last, have a space in them.
        /// </exception>
        /// <param name="client">
        /// The <see cref="IrcClient"/> this line belongs to.
        /// </param>
        /// <param name="prefix">
        /// The prefix of the line.
        /// </param>
        /// <param name="command">
        /// The command of the line.
        /// </param>
        /// <param name="parameters">
        /// An array of parameters.
        /// </param>
        public IrcLine(IrcClient client, string prefix, string command, string[] parameters)
        {
            this.client = client;
            if (prefix != null && prefix.Contains(" "))
            {
                throw new InvalidLineFormatException("prefix should not have spaces", prefix);
            }

            this.prefix = prefix;
            if (command.Contains(" "))
            {
                throw new InvalidLineFormatException("command should not have spaces", command);
            }

            this.command = command;
            if (parameters != null)
            {
                for (int i = 0; i < parameters.Length - 1; i++)
                {
                    if (parameters[i].Contains(" "))
                    {
                        throw new InvalidLineFormatException("only the last parameter should have spaces", parameters[i]);
                    }
                }

                this.parameters = (string[])parameters.Clone();
            }

            if (!Int32.TryParse(command, out numeric))
            {
                numeric = 0;
            }
        }
示例#15
0
 /// <summary>
 /// Initializes a new instance of the ErrorEventArgs class.
 /// </summary>
 /// <param name="client">The client, the error happens on.</param>
 /// <param name="msg">The related error message.</param>
 /// <param name="exception">The inner exception, that caused the error.</param>
 public ErrorEventArgs(IrcClient client, string msg, Exception exception)
     : base(client)
 {
     innerException = exception;
     message = msg;
 }
示例#16
0
 /// <summary>
 /// Initializes a new instance of the ErrorEventArgs class.
 /// </summary>
 /// <param name="client">The client, the error happens on.</param>
 /// <param name="msg">The related error message.</param>
 public ErrorEventArgs(IrcClient client, string msg)
     : base(client)
 {
     message = msg;
 }