X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Frfc2812.rb;h=e56c76bc6b0d80da54ad53f335c5b704c89ac27b;hb=f13a4901e82fd533815175b95600652ac427d2bd;hp=c8e2e410c8b5cbdb6ac175b47a32721a090588ea;hpb=5cc6ece3d483db28f92f82a78b926ba6ce62769d;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/rfc2812.rb b/lib/rbot/rfc2812.rb index c8e2e410..e56c76bc 100644 --- a/lib/rbot/rfc2812.rb +++ b/lib/rbot/rfc2812.rb @@ -820,8 +820,8 @@ module Irc # create a new IrcClient instance def initialize - @server = Server.new # The Server - @client = User.new # The User representing the client on this Server + @server = Server.new # The Server + @client = @server.user("") # The User representing the client on this Server @handlers = Hash.new @@ -888,7 +888,7 @@ module Irc if prefix != nil data[:source] = prefix if prefix =~ /^(\S+)!(\S+)$/ - data[:source] = @server.user($1) + data[:source] = @server.user(prefix) else if @server.hostname && @server.hostname != data[:source] warning "Unknown origin #{data[:source]} for message\n#{serverstring.inspect}" @@ -922,6 +922,7 @@ module Irc data[:nick] = $2 data[:address] = $3 @client = @server.user(data[:netmask]) + set = true when /Welcome to the Internet Relay Network\s(\S+)/ data[:nick] = $1 when /Welcome.*\s+(\S+)$/ @@ -929,7 +930,7 @@ module Irc when /^(\S+)$/ data[:nick] = $1 end - @user ||= @server.user(data[:nick]) + @client = @server.user(data[:nick]) unless set handle(:welcome, data) when RPL_YOURHOST # "Your host is , running version " @@ -954,7 +955,7 @@ module Irc # PREFIX=(ov)@+ CASEMAPPING=ascii CAPAB IRCD=dancer :are available # on this server" # - @server.parse_isupport(params.split(' ', 2).last) + @server.parse_isupport(argv[1..-2].join(' ')) handle(:isupport, data) when ERR_NICKNAMEINUSE # "* :Nickname is already in use" @@ -1001,12 +1002,13 @@ module Irc chan = @server.get_channel(data[:channel]) unless chan - warning "Received topic #{data[:topic].inspect} for channel #{data[:channel].inspect} I was not on" + warning "Received names #{data[:topic].inspect} for channel #{data[:channel].inspect} I was not on" return end users = [] argv[3].scan(/\S+/).each { |u| + # FIXME beware of servers that allow multiple prefixes if(u =~ /^(#{@server.supports[:prefix][:prefixes].join})?(.*)$/) umode = $1 user = $2 @@ -1016,9 +1018,9 @@ module Irc users.each { |ar| u = @server.user(ar[0]) - chan.users << u + chan.users << u unless chan.users.include?(u) if ar[1] - m = @server.supports[:prefix][:prefixes].index(ar[1]) + m = @server.supports[:prefix][:prefixes].index(ar[1].to_sym) m = @server.supports[:prefix][:modes][m] chan.mode[m.to_sym].set(u) end @@ -1098,7 +1100,7 @@ module Irc handle(:privmsg, data) # Now we split it - if(data[:target].class <= Channel) + if data[:target].kind_of?(Channel) handle(:public, data) else handle(:msg, data) @@ -1110,7 +1112,7 @@ module Irc when User handle(:notice, data) else - # "server notice" (not from user, noone to reply to + # "server notice" (not from user, noone to reply to) handle(:snotice, data) end when 'KICK' @@ -1138,6 +1140,7 @@ module Irc data[:message] = argv[0] data[:was_on] = @server.channels.inject(ChannelList.new) { |list, ch| list << ch if ch.users.include?(data[:source]) + list } @server.delete_user(data[:source]) @@ -1150,8 +1153,8 @@ module Irc handle(:join, data) when 'TOPIC' data[:channel] = @server.channel(argv[0]) - data[:topic] = ChannelTopic.new(argv[1], data[:source], Time.new) - data[:channel].topic = data[:topic] + data[:topic] = Channel::Topic.new(argv[1], data[:source], Time.new) + data[:channel].topic.replace(data[:topic]) handle(:changetopic, data) when 'INVITE' @@ -1162,11 +1165,13 @@ module Irc when 'NICK' data[:is_on] = @server.channels.inject(ChannelList.new) { |list, ch| list << ch if ch.users.include?(data[:source]) + list } data[:newnick] = argv[0] data[:oldnick] = data[:source].nick.dup - data[:source].nick = data[:nick] + data[:source].nick = data[:newnick] + debug "#{data[:oldnick]} (now #{data[:newnick]}) was on #{data[:is_on].join(', ')}" handle(:nick, data) @@ -1195,7 +1200,8 @@ module Irc argv[1..-1].each { |arg| setting = arg[0].chr if "+-".include?(setting) - arg[1..-1].each_byte { |m| + arg[1..-1].each_byte { |b| + m = b.chr case m.to_sym when *@server.supports[:chanmodes][:typea] data[:modes] << [setting + m]