Holds host informations about a user.
Inheritance: IIrcObject
Beispiel #1
0
 public void Client()
 {
     UserInfo info = new UserInfo(client, "[email protected]");
     Assert.AreSame(client, info.Client);
     info = new UserInfo(new IrcLine(client, ":[email protected] CMD :test"));
     Assert.AreSame(client, info.Client);
 }
Beispiel #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];
 }
Beispiel #3
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);
 }
Beispiel #4
0
        public void Constructor()
        {
            UserInfo info = new UserInfo(client, "[email protected]");
            Assert.IsNotNull(info);
            try
            {
                info = new UserInfo(client, "blubl@bla@blubb");
                Assert.Fail("userinfo was created with @ in host");
            }
            catch (ArgumentException)
            {
            }

            try
            {
                info = new UserInfo(client, " ");
                Assert.Fail("userinfo was created with empty host");
            }
            catch (ArgumentException)
            {
            }

            try
            {
                info = new UserInfo(client, "blu@bla!blubb");
                Assert.Fail("userinfo was created with bad host");
            }
            catch (ArgumentException)
            {
            }

            try
            {
                info = new UserInfo(client, "!bla@blubb");
                Assert.Fail("userinfo was created without nickname");
            }
            catch (ArgumentException)
            {
            }

            try
            {
                info = new UserInfo(client, "f!bla@");
                Assert.Fail("userinfo was created without host");
            }
            catch (ArgumentException)
            {
            }

            try
            {
                info = new UserInfo(client, "bla!@blubb");
                Assert.Fail("userinfo was created without ident");
            }
            catch (ArgumentException)
            {
            }
        }
Beispiel #5
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];
            }
        }
Beispiel #6
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;
            }
        }
        /// <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;
            }
        }
Beispiel #8
0
 /// <summary>
 /// Initializes a new instance of the PartReceivedEventArgs class.
 /// </summary>
 /// <param name="channelName">The name of the channel.</param>
 /// <param name="partedUser">The user, who parted.</param>
 public PartReceivedEventArgs(string channelName, UserInfo partedUser)
     : base(partedUser.Client)
 {
     this.channelName = channelName;
     user = partedUser;
 }
Beispiel #9
0
 public void ToStringTest()
 {
     UserInfo info = new UserInfo(client, "[email protected]");
     Assert.AreEqual("[email protected]", info.ToString());
     info = new UserInfo(client, "me!foobar@you");
     Assert.AreEqual("me!foobar@you", info.ToString());
 }
Beispiel #10
0
 public void NickName()
 {
     UserInfo info = new UserInfo(client, "[email protected]");
     Assert.AreEqual("nick", info.NickName);
     info = new UserInfo(client, "me!foobar@you");
     Assert.AreEqual("me", info.NickName);
     info = new UserInfo(new IrcLine(client, ":[email protected] CMD :test"));
     Assert.AreEqual("nick", info.NickName);
     info = new UserInfo(new IrcLine(client, ":me!foobar@you CMD :test"));
     Assert.AreEqual("me", info.NickName);
 }
Beispiel #11
0
 public void Ident()
 {
     UserInfo info = new UserInfo(client, "[email protected]");
     Assert.AreEqual("ident", info.Ident);
     info = new UserInfo(client, "me!foobar@you");
     Assert.AreEqual("foobar", info.Ident);
     info = new UserInfo(new IrcLine(client, ":[email protected] CMD :test"));
     Assert.AreEqual("ident", info.Ident);
     info = new UserInfo(new IrcLine(client, ":me!foobar@you CMD :test"));
     Assert.AreEqual("foobar", info.Ident);
 }
Beispiel #12
0
 public void GetHashCodeTest()
 {
     UserInfo info = new UserInfo(client, "[email protected]");
     Assert.AreEqual("[email protected]".GetHashCode(), info.GetHashCode());
     info = new UserInfo(client, "foo!bar@me");
     Assert.AreEqual("foo!bar@me".GetHashCode(), info.GetHashCode());
 }
Beispiel #13
0
 public void Equals()
 {
     UserInfo info1 = new UserInfo(client, "[email protected]");
     UserInfo info2 = new UserInfo(client, "[email protected]");
     Assert.IsTrue(info1.Equals(info2));
     Assert.IsTrue(info2.Equals(info1));
     info2 = new UserInfo(client, "foo!bar@you");
     Assert.IsFalse(info1.Equals(info2));
     Assert.IsFalse(info2.Equals(info1));
 }
Beispiel #14
0
 public void Constructor2()
 {
     UserInfo info = new UserInfo(new IrcLine(client, ":[email protected] CMD :test"));
     Assert.IsNotNull(info);
     try
     {
         info = new UserInfo(new IrcLine(client, "CMD :test"));
         Assert.Fail("userinfo was created with an IrcLine what doesn't have a prefix");
     }
     catch (ArgumentException)
     {
     }
 }
Beispiel #15
0
 /// <summary>
 /// Initializes a new instance of the QuitReceivedEventArgs class.
 /// </summary>
 /// <param name="user">The user, that quited.</param>
 /// <param name="message">The message the user sent when quitting.</param>
 public QuitReceivedEventArgs(UserInfo user, string message)
     : base(user.Client)
 {
     this.user = user;
     this.quitMessage = message;
 }
Beispiel #16
0
 /// <summary>
 /// Initializes a new instance of the JoinReceivedEventArgs class.
 /// </summary>
 /// <param name="channelName">The name of the joined channel.</param>
 /// <param name="joinedUser">The UserInfo for the joined user.</param>
 public JoinReceivedEventArgs(string channelName, UserInfo joinedUser)
     : base(joinedUser.Client)
 {
     this.channelName = channelName;
     user = joinedUser;
 }
Beispiel #17
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];
 }
Beispiel #18
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;
 }
Beispiel #19
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;
                }
            }
        }