# This module defines the Irc::Client class, a class that can handle and
# dispatch messages based on RFC 2821 (Internet Relay Chat: Client Protocol)
+class ServerMessageParseError < ServerError
+end
+
module Irc
# - The server sends Replies 001 to 004 to a user upon
# successful registration.
ERR_NOSERVICEHOST=492
RPL_DATASTR=290
+ # A structure to hold LIST data, in the Irc namespace
+ ListData = Struct.new :channel, :users, :topic
+
# Implements RFC 2812 and prior IRC RFCs.
#
# Clients should register Proc{}s to handle the various server events, and
# This is used by some messages to build lists of users that
# will be delegated when the ENDOF... message is received
@tmpusers = []
+
+ # Same as above, just for bans
+ @tmpbans = []
end
# Clear the server and reset the user
data[:serverstring] = serverstring
unless serverstring.chomp =~ /^(:(\S+)\s)?(\S+)(\s(.*))?$/
- raise "Unparseable Server Message!!!: #{serverstring.inspect}"
+ raise ServerMessageParseError, (serverstring.chomp rescue serverstring)
end
prefix, command, params = $2, $3, $5
data[:users] = @tmpusers
handle(:names, data)
@tmpusers = Array.new
+ when RPL_BANLIST
+ data[:channel] = @server.channel(argv[1])
+ data[:mask] = argv[2]
+ data[:by] = argv[3]
+ data[:at] = argv[4]
+ @tmpbans << data
+ when RPL_ENDOFBANLIST
+ data[:channel] = @server.channel(argv[1])
+ data[:bans] = @tmpbans
+ handle(:banlist, data)
+ @tmpbans = Array.new
when RPL_LUSERCLIENT
# ":There are <integer> users and <integer>
# services on <integer> servers"
when RPL_WHOISCHANNELS
@whois ||= Hash.new
@whois[:nick] = argv[1]
- @whois[:channels] = []
+ @whois[:channels] ||= []
user = @server.user(@whois[:nick])
argv[-1].split.each do |prechan|
pfx = prechan.scan(/[#{@server.supports[:prefix][:prefixes].join}]/)
@whois[:channels] << [chan, modes]
end
+ when RPL_LISTSTART
+ # ignore
+ when RPL_LIST
+ @list ||= Hash.new
+ chan = argv[1]
+ users = argv[2]
+ topic = argv[3]
+ @list[chan] = ListData.new(chan, users, topic)
+ when RPL_LISTEND
+ @list ||= Hash.new
+ data[:list] = @list
+ handle(:list, data)
when RPL_CHANNELMODEIS
parse_mode(serverstring, argv[1..-1], data)
handle(:mode, data)