X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fircsocket.rb;h=36a223f9d52cc456efc1179835d143184e51f2ee;hb=0ad9f7d566fb2683f08a06094dac5beab6253ff8;hp=81a7fd16e3fcc98641fc19a356238cee397d9836;hpb=43b5cd9777cc13c6d3ac14a4015a0c8e8d9e5b50;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/ircsocket.rb b/lib/rbot/ircsocket.rb index 81a7fd16..36a223f9 100644 --- a/lib/rbot/ircsocket.rb +++ b/lib/rbot/ircsocket.rb @@ -1,10 +1,18 @@ +#-- vim:sw=2:et +#++ +# +# :title: IRC Socket +# +# This module implements the IRC socket interface, including IRC message +# penalty computation and the message queue system + require 'monitor' class ::String # Calculate the penalty which will be assigned to this message # by the IRCd def irc_send_penalty - # According to eggrdop, the initial penalty is + # According to eggdrop, the initial penalty is penalty = 1 + self.size/100 # on everything but UnderNET where it's # penalty = 2 + self.size/120 @@ -238,6 +246,9 @@ module Irc # normalized uri of the current server attr_reader :server_uri + # penalty multiplier (percent) + attr_accessor :penalty_pct + # default trivial filter class class IdentityFilter def in(x) @@ -267,11 +278,8 @@ module Irc @spooler = false @lines_sent = 0 @lines_received = 0 - if opts.kind_of?(Hash) and opts.key?(:ssl) - @ssl = opts[:ssl] - else - @ssl = false - end + @ssl = opts[:ssl] + @penalty_pct = opts[:penalty_pct] || 100 end def connected? @@ -396,15 +404,13 @@ module Irc loop do begin now = Time.now - flood_delay = @flood_send - MAX_IRC_SEND_PENALTY - now - delay = [flood_delay, 0].max - if delay > 0 + flood_delay = @flood_send - MAX_IRC_SEND_PENALTY - now + delay = [flood_delay, 0].max + if delay > 0 debug "sleep(#{delay}) # (f: #{flood_delay})" sleep(delay) end msg = @sendq.shift - now = Time.now - @flood_send = now if @flood_send < now debug "got #{msg.inspect} from queue, sending" emergency_puts(msg, true) rescue Exception => e @@ -427,9 +433,11 @@ module Irc # the latter is racy and can cause double message output in # some circumstances actual = @filter.out(message) + "\n" + now = Time.new @sock.syswrite actual - @last_send = Time.new - @flood_send += message.irc_send_penalty if penalty + @last_send = now + @flood_send = now if @flood_send < now + @flood_send += message.irc_send_penalty*@penalty_pct/100.0 if penalty @lines_sent += 1 end rescue Exception => e