summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-06-18 17:48:57 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-06-18 18:04:33 +0200
commit257acdbfb3a4b0de7e3280e9f04d173e3016efbe (patch)
tree8324fd7fb75a4366c18877f9edae109b07daae87
parent5488a6b91bdebd4dc2620f72c02d043cf5236dc3 (diff)
rfc2812: fix MODE line parsing
-rw-r--r--lib/rbot/rfc2812.rb73
1 files changed, 40 insertions, 33 deletions
diff --git a/lib/rbot/rfc2812.rb b/lib/rbot/rfc2812.rb
index 3159759b..819ea291 100644
--- a/lib/rbot/rfc2812.rb
+++ b/lib/rbot/rfc2812.rb
@@ -1445,46 +1445,53 @@ module Irc
# are needed
who_wants_params = []
- argv[1..-1].each { |arg|
- setting = arg[0].chr
- if "+-".include?(setting)
- setting = setting == "+" ? :set : :reset
- arg[1..-1].each_byte { |b|
- m = b.chr.intern
- if m == :+
- setting = :set
- next
- elsif m == :-
- setting = :reset
- next
- end
- data[:modes] << [setting, m]
- case m
- when *@server.supports[:chanmodes][:typea]
- who_wants_params << data[:modes].length - 1
- when *@server.supports[:chanmodes][:typeb]
- who_wants_params << data[:modes].length - 1
- when *@server.supports[:chanmodes][:typec]
- if setting == :set
- who_wants_params << data[:modes].length - 1
- end
- when *@server.supports[:chanmodes][:typed]
- # Nothing to do
- when *@server.supports[:prefix][:modes]
- who_wants_params << data[:modes].length - 1
- else
- warning "Unknown mode #{m} in #{serverstring.inspect}"
- end
- }
- else
+ modes = argv[1..-1].dup
+ debug modes
+ getting_args = false
+ while arg = modes.shift
+ debug arg
+ if getting_args
+ # getting args for previously set modes
idx = who_wants_params.shift
if idx.nil?
warning "Oops, problems parsing #{serverstring.inspect}"
break
end
data[:modes][idx] << arg
+ getting_args = false if who_wants_params.empty?
+ else
+ debug @server.supports[:chanmodes]
+ setting = :set
+ arg.each_char do |c|
+ m = c.intern
+ case m
+ when :+
+ setting = :set
+ when :-
+ setting = :reset
+ else
+ data[:modes] << [setting, m]
+ case m
+ when *@server.supports[:chanmodes][:typea]
+ who_wants_params << data[:modes].length - 1
+ when *@server.supports[:chanmodes][:typeb]
+ who_wants_params << data[:modes].length - 1
+ when *@server.supports[:chanmodes][:typec]
+ if setting == :set
+ who_wants_params << data[:modes].length - 1
+ end
+ when *@server.supports[:chanmodes][:typed]
+ # Nothing to do
+ when *@server.supports[:prefix][:modes]
+ who_wants_params << data[:modes].length - 1
+ else
+ warning "Unknown mode #{m} in #{serverstring.inspect}"
+ end
+ end
+ end
+ getting_args = true unless who_wants_params.empty?
end
- }
+ end
data[:modes].each { |mode|
set, key, val = mode