protected internal override bool OnReply(IrcLine line, ref bool final) { if (client.CaseMappingComparer.Equals(line.Message, "NOTICE")) { if (line.Parameters[1].Length >= 2 && line.Parameters[1].StartsWith("\u0001") && line.Parameters[1].EndsWith("\u0001") && client.CaseMappingComparer.Equals(Hostmask.GetNickname(line.Prefix), this.target) && client.CaseMappingComparer.Equals(line.Parameters[0], client.Me.Nickname)) { var fields = line.Parameters[1].Substring(1, line.Parameters[1].Length - 2).Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (this.request.Equals(fields[0], StringComparison.InvariantCultureIgnoreCase)) { this.taskSource.SetResult(fields.Length >= 2 ? fields[1] : null); final = true; return(true); } } } else if (line.Message[0] == '4') { if (client.CaseMappingComparer.Equals(line.Parameters[1], this.target)) { this.taskSource.SetException(new AsyncRequestErrorException(line)); final = true; return(true); } } return(false); }
protected internal override bool OnReply(IrcLine line, ref bool final) { if (this.user.Client.CaseMappingComparer.Equals(Hostmask.GetNickname(line.Prefix ?? this.user.Client.ServerName), this.user.Nickname) && this.user.Client.CaseMappingComparer.Equals(line.Parameters[0], this.target.Target)) { this.TaskSource.SetResult(line.Parameters[1]); final = true; } return(false); }
protected internal override bool OnReply(IrcLine line, ref bool final) { if (final) { if (!char.IsDigit(line.Message[0]) && this.nickname != null && line.Prefix != null && !this.client.CaseMappingComparer.Equals(this.nickname, Hostmask.GetNickname(line.Prefix))) { // Wrong user. final = false; return(false); } if (line.Message[0] == '4' || (this.errors != null && this.errors.Contains(line.Message))) { this.TaskSource.SetException(new AsyncRequestErrorException(line)); return(true); } this.TaskSource.SetResult(null); } return(false); }
public IrcLineEventArgs(string data, IrcLine line, bool matchesAsyncRequests) : base(data) { this.Line = line; this.MatchesAsyncRequests = matchesAsyncRequests; }
public static IrcLine Parse(string line) { return(IrcLine.Parse(line, true)); }
public AsyncRequestErrorException(IrcLine line) : base(line.Parameters[line.Parameters.Length - 1]) { this.Line = line; }
protected internal override bool OnReply(IrcLine line, ref bool final) { response.lines.Add(line); switch (line.Message) { case RPL_AWAY: response.AwayMessage = line.Parameters[2]; break; case RPL_WHOISREGNICK: if (response.Account == null) { response.Account = line.Parameters[1]; } break; case RPL_WHOISUSER: response.Nickname = line.Parameters[1]; response.Ident = line.Parameters[2]; response.Host = line.Parameters[3]; response.FullName = line.Parameters[5]; break; case RPL_WHOISSERVER: response.ServerName = line.Parameters[2]; response.ServerInfo = line.Parameters[3]; break; case RPL_WHOISOPERATOR: response.Oper = true; break; case RPL_WHOISIDLE: response.IdleTime = TimeSpan.FromSeconds(long.Parse(line.Parameters[2])); if (line.Parameters.Length > 4) { response.SignonTime = IrcClient.DecodeUnixTime(long.Parse(line.Parameters[3])); } break; case RPL_WHOISCHANNELS: foreach (var token in line.Parameters[2].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) { for (int i = 0; i < token.Length; ++i) { if (this.client.Extensions.ChannelTypes.Contains(token[i])) { response.channels.Add(token.Substring(i), ChannelStatus.FromPrefix(this.client, token.Take(i))); break; } } } break; case RPL_WHOISACCOUNT: response.Account = line.Parameters[2]; break; case RPL_ENDOFWHOIS: if (response.Nickname != null) { this.taskSource.SetResult(response); } else if (error != null) { this.taskSource.SetException(new AsyncRequestErrorException(line)); } else { this.taskSource.SetException(new IOException("The server did not send any response.")); } final = true; break; case ERR_NOSUCHSERVER: case ERR_NOSUCHNICK: case ERR_NONICKNAMEGIVEN: if (error == null) { error = line; } break; } return(true); }
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); }
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); }
/// <summary>Called when one of the replies listed in the <see cref="Replies"/> table is received.</summary> /// <param name="line">The IRC line that was matched.</param> /// <param name="final">Indicates whether this is considered a final response, and the <see cref="AsyncRequest"/> will be dropped.</param> /// <returns>True if processing of async requests of this type should be stopped; false otherwise.</returns> protected internal abstract bool OnReply(IrcLine line, ref bool final);