]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
rfc2812: better handling of incomplete mode lines
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 7 Jan 2009 22:39:33 +0000 (23:39 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 8 Jan 2009 13:50:46 +0000 (14:50 +0100)
Sometimes the bot may receive incomplete or malformed mode lines. This
can be seen for example by kicking repeatedly and at very short
intervals the bot from a channel with +l set to some numbers (at least
on freenode).

We (don't) handle these malformed modelines by skipping them rather than
crashing.

lib/rbot/rfc2812.rb

index 21cd9ff7d4782edb52449f2d09e34db7fb1259d4..ee0d08d605d40781c40b0e3e656d4d82a0a68e43 100644 (file)
@@ -1534,7 +1534,7 @@ module Irc
             data[:modes].last << arg
           end
         }
-      else
+      when Channel
         # array of indices in data[:modes] where parameters
         # are needed
         who_wants_params = []
@@ -1587,6 +1587,10 @@ module Irc
             getting_args = true unless who_wants_params.empty?
           end
         end
+        unless who_wants_params.empty?
+          warning "Unhandled malformed modeline #{data[:modestring]} (unexpected empty arguments)"
+          return
+        end
 
         data[:modes].each { |mode|
           set, key, val = mode
@@ -1596,6 +1600,8 @@ module Irc
             data[:target].mode[key].send(set)
           end
         }
+      else
+        warning "Ignoring #{data[:modestring]} for unrecognized target #{argv[0]} (#{data[:target].inspect})"
       end
     end
   end