From aeff57ecf846b714e08d0095f1aea28a74e47d0b Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 10 Feb 2007 09:59:15 +0000 Subject: Handle server connections (e.g. through a bip proxy) that do not use the full user hostmask as a prefix of user messages --- lib/rbot/rfc2812.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/rbot/rfc2812.rb b/lib/rbot/rfc2812.rb index 900c750d..9ca6571a 100644 --- a/lib/rbot/rfc2812.rb +++ b/lib/rbot/rfc2812.rb @@ -886,16 +886,27 @@ module Irc prefix, command, params = $2, $3, $5 if prefix != nil - data[:source] = prefix - if prefix =~ /^(\S+)!(\S+)$/ + # Most servers will send a full nick!user@host prefix for + # messages from users. Therefore, when the prefix doesn't match this + # syntax it's usually the server hostname. + # + # This is not always true, though, since some servers do not send a + # full hostmask for user messages. + # + if prefix =~ /^(?:\S+)(?:!\S+)?@(?:\S+)$/ data[:source] = @server.user(prefix) else - if @server.hostname && @server.hostname != data[:source] - warning "Unknown origin #{data[:source]} for message\n#{serverstring.inspect}" + if @server.hostname + if @server.hostname != prefix + debug "Origin #{prefix} for message\n\t#{serverstring.inspect}\nis neither a user hostmask nor the server hostname, assuming it's a nick" + data[:source] = @server.user(prefix) + else + data[:source] = @server + end else @server.instance_variable_set(:@hostname, data[:source]) + data[:source] = @server end - data[:source] = @server end end -- cgit v1.2.3