]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
azgame plugin: better handling of late checks
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 1 Nov 2007 22:10:58 +0000 (22:10 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 1 Nov 2007 22:10:58 +0000 (22:10 +0000)
data/rbot/plugins/games/azgame.rb

index f84fa159d9f6a10a93965f1f0830aed1e2921f83..fb81b6d74948f1109944d09d2065258bb87d8296 100644 (file)
@@ -40,11 +40,18 @@ class AzGame
   def check(word)\r
     w = word.downcase\r
     debug "checking #{w} for #{@word} in #{@range}"\r
+    # Since we're called threaded, bail out early if a winner\r
+    # was assigned already\r
+    return [:ignore, nil] if @winner\r
     return [:bingo, nil] if w == @word\r
     return [:out, @range] if w < @range.first or w > @range.last\r
     return [:ignore, @range] if w == @range.first or w == @range.last\r
+    # This is potentially slow (for languages that check online)\r
     return [:noexist, @range] unless @plugin.send("is_#{@lang}?", w)\r
     debug "we like it"\r
+    # Check again if there was a winner in the mean time,\r
+    # and bail out if there was\r
+    return [:ignore, nil] if @winner\r
     if w < @word and w > @range.first\r
       @range.first.replace(w)\r
       return [:in, @range]\r
@@ -166,10 +173,14 @@ class AzGamePlugin < Plugin
       when :out\r
         m.reply _("%{word} is not in the range %{bold}%{range}%{bold}") % {:word => word, :bold => Bold, :range => isit.last} if m.address?\r
       when :noexist\r
+        # bail out early if the game was won in the mean time\r
+        return if !@games[k] or @games[k].winner\r
         m.reply _("%{word} doesn't exist or is not acceptable for the game") % {:word => word}\r
         @games[k].total_failed += 1\r
         @games[k].failed[m.source] += 1\r
       when :in\r
+        # bail out early if the game was won in the mean time\r
+        return if !@games[k] or @games[k].winner\r
         m.reply _("close, but no cigar. New range: %{bold}%{range}%{bold}") % {:bold => Bold, :range => isit.last}\r
         @games[k].total_tries += 1\r
         @games[k].tries[m.source] += 1\r