Esempio n. 1
0
            protected internal override bool OnReply(IrcLine line, ref bool final)
            {
                switch (line.Message)
                {
                case RPL_WHOSPCRPL:
                    if (line.Parameters.Length != this.fields.Length + 1)
                    {
                        return(false);
                    }

                    var reply = new WhoResponse();

                    for (int i = line.Parameters.Length - 1; i >= 1; --i)
                    {
                        switch (this.fields[i - 1])
                        {
                        case WhoxField.QueryType:
                            if (line.Parameters[i] != this.QueryType)
                            {
                                return(false);
                            }
                            break;

                        case WhoxField.Channel:
                            reply.Channel = line.Parameters[i];
                            break;

                        case WhoxField.Ident:
                            reply.Ident = line.Parameters[i];
                            break;

                        case WhoxField.Host:
                            reply.Host = line.Parameters[i];
                            break;

                        case WhoxField.IPAddress:
                            if (line.Parameters[i] != "255.255.255.255")
                            {
                                reply.IPAddress = line.Parameters[i];
                            }
                            break;

                        case WhoxField.ServerName:
                            reply.Server = line.Parameters[i];
                            break;

                        case WhoxField.Nickname:
                            reply.Nickname = line.Parameters[i];
                            break;

                        case WhoxField.Flags:
                            foreach (char flag in line.Parameters[i])
                            {
                                switch (flag)
                                {
                                case 'G':
                                    reply.Away = true;
                                    break;

                                case '*':
                                    reply.Oper = true;
                                    break;

                                default:
                                    if (client.Extensions.StatusPrefix.TryGetValue(flag, out char mode))
                                    {
                                        if (reply.ChannelStatus == null)
                                        {
                                            reply.ChannelStatus = new ChannelStatus(this.client);
                                        }
                                        reply.ChannelStatus.Add(mode);
                                    }
                                    break;
                                }
                            }
                            break;

                        case WhoxField.HopCount:
                            if (line.Parameters[i] != "0")
                            {
                                reply.HopCount = int.Parse(line.Parameters[i]);
                            }
                            break;

                        case WhoxField.IdleTime:
                            if (line.Parameters[i] != "0")
                            {
                                reply.IdleTime = int.Parse(line.Parameters[i]);
                            }
                            break;

                        case WhoxField.Account:
                            if (line.Parameters[i] != "0")
                            {
                                reply.Account = line.Parameters[i];
                            }
                            break;

                        case WhoxField.FullName:
                            reply.FullName = line.Parameters[i];
                            break;
                        }
                    }

                    this.responses.Add(reply);
                    break;

                case RPL_ENDOFWHO:
                    this.taskSource.SetResult(this.Responses);
                    final = true;
                    break;

                case ERR_NOSUCHSERVER:
                case ERR_NOSUCHCHANNEL:
                    this.taskSource.SetException(new AsyncRequestErrorException(line));
                    final = true;
                    break;
                }

                return(true);
            }
Esempio n. 2
0
            protected internal override bool OnReply(IrcLine line, ref bool final)
            {
                switch (line.Message)
                {
                case RPL_WHOREPLY:
                    string[] fields = line.Parameters[7].Split(new char[] { ' ' }, 2);

                    var reply = new WhoResponse()
                    {
                        Ident    = line.Parameters[2],
                        Host     = line.Parameters[3],
                        Server   = line.Parameters[4],
                        Nickname = line.Parameters[5],
                        HopCount = int.Parse(fields[0]),
                        FullName = fields[1]
                    };

                    if (line.Parameters[1] != "*")
                    {
                        reply.Channel       = line.Parameters[1];
                        reply.ChannelStatus = new ChannelStatus(this.client);
                    }

                    foreach (char flag in line.Parameters[6])
                    {
                        switch (flag)
                        {
                        case 'G':
                            reply.Away = true;
                            break;

                        case '*':
                            reply.Oper = true;
                            break;

                        default:
                            if (client.Extensions.StatusPrefix.TryGetValue(flag, out char mode))
                            {
                                if (reply.ChannelStatus == null)
                                {
                                    reply.ChannelStatus = new ChannelStatus(this.client);
                                }
                                reply.ChannelStatus.Add(mode);
                            }
                            break;
                        }
                    }

                    this.responses.Add(reply);
                    break;

                case RPL_ENDOFWHO:
                    this.taskSource.SetResult(this.Responses);
                    final = true;
                    break;

                case ERR_NOSUCHSERVER:
                case ERR_NOSUCHCHANNEL:
                    this.taskSource.SetException(new AsyncRequestErrorException(line));
                    final = true;
                    break;
                }

                return(true);
            }