예제 #1
0
		public void OnNumeric(NumericLine line)
		{
			switch (line.Numeric)
			{
				case NumericCommand.RPL_WELCOME:
					new User(line.Message.Substring(line.Message.LastIndexOf(' ') + 1)).CopyTo(this);
					break;
				case NumericCommand.RPL_NAMREPLY:
					{
						var channel = line.GetChannel();
						var nicknames = line.Message.Replace("~", "").Replace("&", "").Replace("@", "").Replace("%", "").Replace("+", "").Split(' ');

						foreach (var nickname in nicknames.Where(n => !channel.Users.ContainsKey(n)))
							channel.Users.Add(nickname, new User { Nickname = nickname });
					}
					break;
				case NumericCommand.RPL_TOPIC:
					line.GetChannel().Topic.Message = line.Message;
					break;
				case NumericCommand.RPL_TOPICWHOTIME:
					{
						var topic = line.GetChannel().Topic;
						topic.Author = new User(line[4]);
						topic.Time = IrcUtils.DateTimeFromUnixTime(Exts.ParseIntegerInvariant(line[5]));
					}
					break;
				case NumericCommand.ERR_NICKNAMEINUSE:
					if (line.Target == "*") // no nickname set yet
						Client.SetNickname(Client.Nickname + new Random().Next(10000, 99999));
					break;
			}
		}
예제 #2
0
        public void OnNumeric(NumericLine line)
        {
            switch (line.Numeric)
            {
            case NumericCommand.RPL_WELCOME:
                new User(line.Message.Substring(line.Message.LastIndexOf(' ') + 1)).CopyTo(this);
                break;

            case NumericCommand.RPL_NAMREPLY:
            {
                var channel   = line.GetChannel();
                var nicknames = line.Message.Replace("~", "").Replace("&", "").Replace("@", "").Replace("%", "").Replace("+", "").Split(' ');

                foreach (var nickname in nicknames.Where(n => !channel.Users.ContainsKey(n)))
                {
                    channel.Users.Add(nickname, new User {
                            Nickname = nickname
                        });
                }
            }
            break;

            case NumericCommand.RPL_TOPIC:
                line.GetChannel().Topic.Message = line.Message;
                break;

            case NumericCommand.RPL_TOPICWHOTIME:
            {
                var topic = line.GetChannel().Topic;
                topic.Author = new User(line[4]);
                topic.Time   = IrcUtils.DateTimeFromUnixTime(int.Parse(line[5]));
            }
            break;

            case NumericCommand.ERR_NICKNAMEINUSE:
                if (line.Target == "*")                         // no nickname set yet
                {
                    Client.SetNickname(Client.Nickname + new Random().Next(10000, 99999));
                }
                break;
            }
        }
예제 #3
0
		void ProcessLine(string line)
		{
			if (string.IsNullOrEmpty(line))
				return;

			var l = new Line(this, line);
			OnLineRead(l);

			int numeric;
			if (Exts.TryParseIntegerInvariant(l.Command, out numeric))
			{
				var nl = new NumericLine(l, numeric);
				LocalUser.OnNumeric(nl);
				OnNumeric(nl);
				switch (nl.Numeric)
				{
					case NumericCommand.RPL_WELCOME:
						OnRegister(nl);
						break;
					case NumericCommand.RPL_ENDOFNAMES:
						OnSync(nl);
						break;
				}
			}
			else
			{
				switch (l.Command)
				{
					case "PING":
						Pong(l.Message);
						OnPing(l);
						break;
					case "PRIVMSG":
						if (IrcUtils.IsChannel(l.Target))
							OnPublicMessage(l);
						else
							OnPrivateMessage(l);
						break;
					case "NOTICE":
						if (IrcUtils.IsChannel(l.Target))
							OnPublicNotice(l);
						else
							OnPrivateNotice(l);
						break;
					case "JOIN":
						var jl = new JoinLine(l);
						LocalUser.OnJoin(jl);
						OnJoin(jl);
						break;
					case "PART":
						LocalUser.OnPart(l);
						OnPart(l);
						break;
					case "NICK":
						var nsl = new NicknameSetLine(l);
						LocalUser.OnNicknameSet(nsl);
						OnNicknameSet(nsl);
						break;
					case "QUIT":
						OnQuit(l);
						LocalUser.OnQuit(l);
						break;
					case "KICK":
						var kl = new KickLine(l);
						LocalUser.OnKick(kl);
						OnKick(kl);
						break;
					case "TOPIC":
						LocalUser.OnTopicSet(l);
						OnTopicSet(l);
						break;
				}
			}
		}
예제 #4
0
        void ProcessLine(string line)
        {
            if (string.IsNullOrEmpty(line))
            {
                return;
            }

            var l = new Line(this, line);

            OnLineRead(l);

            int numeric;

            if (int.TryParse(l.Command, out numeric))
            {
                var nl = new NumericLine(l, numeric);
                LocalUser.OnNumeric(nl);
                OnNumeric(nl);
                switch (nl.Numeric)
                {
                case NumericCommand.RPL_WELCOME:
                    OnRegister(nl);
                    break;

                case NumericCommand.RPL_ENDOFNAMES:
                    OnSync(nl);
                    break;
                }
            }
            else
            {
                switch (l.Command)
                {
                case "PING":
                    Pong(l.Message);
                    OnPing(l);
                    break;

                case "PRIVMSG":
                    if (IrcUtils.IsChannel(l.Target))
                    {
                        OnPublicMessage(l);
                    }
                    else
                    {
                        OnPrivateMessage(l);
                    }
                    break;

                case "NOTICE":
                    if (IrcUtils.IsChannel(l.Target))
                    {
                        OnPublicNotice(l);
                    }
                    else
                    {
                        OnPrivateNotice(l);
                    }
                    break;

                case "JOIN":
                    var jl = new JoinLine(l);
                    LocalUser.OnJoin(jl);
                    OnJoin(jl);
                    break;

                case "PART":
                    LocalUser.OnPart(l);
                    OnPart(l);
                    break;

                case "NICK":
                    var nsl = new NicknameSetLine(l);
                    LocalUser.OnNicknameSet(nsl);
                    OnNicknameSet(nsl);
                    break;

                case "QUIT":
                    OnQuit(l);
                    LocalUser.OnQuit(l);
                    break;

                case "KICK":
                    var kl = new KickLine(l);
                    LocalUser.OnKick(kl);
                    OnKick(kl);
                    break;

                case "TOPIC":
                    LocalUser.OnTopicSet(l);
                    OnTopicSet(l);
                    break;
                }
            }
        }