X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Firc.rb;h=8ef55712cf48affeb815482241a1635b3f26d51c;hb=a4ff366eea4c88083be8a3d30cc6395f17b55fe2;hp=5d3b01ec1a1139551867b507fafaaa20c62390c3;hpb=0b705e79109fa004bf8956ef65288cf00a9f3312;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/irc.rb b/lib/rbot/irc.rb index 5d3b01ec..8ef55712 100644 --- a/lib/rbot/irc.rb +++ b/lib/rbot/irc.rb @@ -84,11 +84,18 @@ module Irc @key.to_s end + # Two Casemaps are equal if they have the same upper and lower ranges + # + def ==(arg) + other = arg.to_irc_casemap + return self.upper == other.upper && self.lower == other.lower + end + # Raise an error if _arg_ and self are not the same Casemap # def must_be(arg) other = arg.to_irc_casemap - raise "Casemap mismatch (#{self} != #{other})" unless self == other + raise "Casemap mismatch (#{self.inspect} != #{other.inspect})" unless self == other return true end @@ -176,14 +183,18 @@ module Irc # @server (if possible) or at the @casemap otherwise # def casemap - @server.casemap rescue @casemap + return @server.casemap if defined?(@server) and @server + return @casemap end # Returns a hash with the current @server and @casemap as values of # :server and :casemap # def server_and_casemap - {:server => @server, :casemap => @casemap} + h = {} + h[:server] = @server if defined?(@server) and @server + h[:casemap] = @casemap if defined?(@casemap) and @casemap + return h end # We allow up/downcasing with a different casemap @@ -531,10 +542,10 @@ module Irc # def inspect str = "<#{self.class}:#{'0x%x' % self.object_id}:" - str << " @server=#{@server}" if @server + str << " @server=#{@server}" if defined?(@server) and @server str << " @nick=#{@nick.inspect} @user=#{@user.inspect}" - str << " @host=#{@host.inspect} casemap=#{casemap.inspect}>" - str + str << " @host=#{@host.inspect} casemap=#{casemap.inspect}" + str << ">" end # Equality: two Netmasks are equal if they downcase to the same thing @@ -612,10 +623,15 @@ module Irc # def matches?(arg) cmp = arg.to_irc_netmask(:casemap => casemap) + debug "Matching #{self.fullform} against #{arg.fullform}" [:nick, :user, :host].each { |component| us = self.send(component).irc_downcase(casemap) them = cmp.send(component).irc_downcase(casemap) - raise NotImplementedError if us.has_irc_glob? && them.has_irc_glob? + if us.has_irc_glob? && them.has_irc_glob? + next if us == them + warn NotImplementedError + return false + end return false if us.has_irc_glob? && !them.has_irc_glob? return false unless us =~ them.to_irc_regexp } @@ -770,14 +786,14 @@ module Irc def replace(other) case other when User - nick = other.nick - user = other.user - host = other.host + self.nick = other.nick + self.user = other.user + self.host = other.host @server = other.server @casemap = other.casemap unless @server - @away = other.away + @away = other.away? else - replace(other.to_irc_user(server_and_casemap)) + self.replace(other.to_irc_user(server_and_casemap)) end end @@ -1008,8 +1024,8 @@ module Irc str = "<#{self.class}:#{'0x%x' % self.object_id}:" str << " on server #{server}" if server str << " @name=#{@name.inspect} @topic=#{@topic.text.inspect}" - str << " @users=<#{@users.sort.join(', ')}>" - str + str << " @users=[#{@users.sort.join(', ')}]" + str << ">" end # Returns self @@ -1154,8 +1170,8 @@ module Irc str = "<#{self.class}:#{'0x%x' % self.object_id}:" str << " @hostname=#{hostname}" str << " @channels=#{chans}" - str << " @users=#{users}>" - str + str << " @users=#{users}" + str << ">" end # Create a new Server, with all instance variables reset to nil (for @@ -1176,7 +1192,7 @@ module Irc # def reset_capabilities @supports = { - :casemapping => 'rfc1459', + :casemapping => 'rfc1459'.to_irc_casemap, :chanlimit => {}, :chanmodes => { :typea => nil, # Type A: address lists @@ -1269,9 +1285,9 @@ module Irc key = prekey.downcase.to_sym end case key - when :casemapping, :network + when :casemapping noval_warn(key, val) { - @supports[key] = val + @supports[key] = val.to_irc_casemap } when :chanlimit, :idchan, :maxlist, :targmax noval_warn(key, val) { @@ -1281,15 +1297,6 @@ module Irc @supports[key][k] = v.to_i } } - when :maxchannels - noval_warn(key, val) { - reparse += "CHANLIMIT=(chantypes):#{val} " - } - when :maxtargets - noval_warn(key, val) { - @supports[key]['PRIVMSG'] = val.to_i - @supports[key]['NOTICE'] = val.to_i - } when :chanmodes noval_warn(key, val) { groups = val.split(',') @@ -1312,6 +1319,19 @@ module Irc when :invex val ||= 'I' @supports[key] = val + when :maxchannels + noval_warn(key, val) { + reparse += "CHANLIMIT=(chantypes):#{val} " + } + when :maxtargets + noval_warn(key, val) { + @supports[key]['PRIVMSG'] = val.to_i + @supports[key]['NOTICE'] = val.to_i + } + when :network + noval_warn(key, val) { + @supports[key] = val + } when :nicklen noval_warn(key, val) { @supports[key] = val.to_i @@ -1498,17 +1518,20 @@ module Irc def new_user(str, fails=true) tmp = str.to_irc_user(:server => self) old = get_user(tmp.nick) + # debug "Tmp: #{tmp.inspect}" + # debug "Old: #{old.inspect}" if old # debug "User already existed as #{old.inspect}" if tmp.known? if old.known? + # debug "Both were known" # Do not raise an error: things like Freenode change the hostname after identification warning "User #{tmp.nick} has inconsistent Netmasks! #{self} knows #{old.inspect} but access was tried with #{tmp.inspect}" if old != tmp raise "User #{tmp} already exists on server #{self}" if fails end - if old != tmp + if old.fullform.downcase != tmp.fullform.downcase old.replace(tmp) - # debug "User improved to #{old.inspect}" + # debug "Known user now #{old.inspect}" end end return old