From 90671f2fe2dded0e1423dee33d073c6531b02b41 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Mon, 5 Mar 2007 21:59:51 +0000 Subject: [PATCH] Previous commit wasn't that good, too restrictive. Relax, and differentiate between user id and mask --- lib/rbot/irc.rb | 37 ++++++++++++++++++++++++++----------- lib/rbot/rfc2812.rb | 2 +- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/lib/rbot/irc.rb b/lib/rbot/irc.rb index 1c9d4dcd..a07c8b23 100644 --- a/lib/rbot/irc.rb +++ b/lib/rbot/irc.rb @@ -533,19 +533,34 @@ class Regexp GEN_HOST = /#{HOSTNAME}|#{HOSTADDR}/ - # FreeNode network replaces the host of affiliated users with - # 'virtual hosts' - # FIXME we need the true syntax to match it properly ... - PDPC_HOST_PART = /[0-9A-Za-z.-]+/ - PDPC_HOST = /#{PDPC_HOST_PART}(?:\/#{PDPC_HOST_PART})+/ - - # NOTE: the final optional and non-greedy dot is needed because some - # servers (e.g. FreeNode) send the hostname of the services as "services." - # which is not RFC compliant, but sadly done. - GEN_MASK_HOST = /#{PDPC_HOST}|#{GEN_HOST}\.??/ + # # FreeNode network replaces the host of affiliated users with + # # 'virtual hosts' + # # FIXME we need the true syntax to match it properly ... + # PDPC_HOST_PART = /[0-9A-Za-z.-]+/ + # PDPC_HOST = /#{PDPC_HOST_PART}(?:\/#{PDPC_HOST_PART})+/ + + # # NOTE: the final optional and non-greedy dot is needed because some + # # servers (e.g. FreeNode) send the hostname of the services as "services." + # # which is not RFC compliant, but sadly done. + # GEN_HOST_EXT = /#{PDPC_HOST}|#{GEN_HOST}\.??/ + + # Sadly, different networks have different, RFC-breaking ways of cloaking + # the actualy host address: see above for an example to handle FreeNode. + # Another example would be Azzurra, wich also inserts a "=" in the + # cloacked host. So let's just not care about this and go with the simplest + # thing: + GEN_HOST_EXT = /\S+/ + + # User-matching Regexp + GEN_USER_ID = /(#{GEN_NICK})(?:(?:!(#{GEN_USER}))?@(#{GEN_HOST_EXT}))?/ + + # For Netmask, we want to allow wildcards * and ? in the nick + # (they are already allowed in the user and host part + GEN_NICK_MASK = /(?:#{NICK_FIRST}|[?*])?(?:#{NICK_ANY}|[?*])+/ # Netmask-matching Regexp - GEN_MASK = /(#{GEN_NICK})(?:(?:!(#{GEN_USER}))?@(#{GEN_MASK_HOST}))?/ + GEN_MASK = /(#{GEN_NICK_MASK})(?:(?:!(#{GEN_USER}))?@(#{GEN_HOST_EXT}))?/ + end end diff --git a/lib/rbot/rfc2812.rb b/lib/rbot/rfc2812.rb index efa50035..1ab981f8 100644 --- a/lib/rbot/rfc2812.rb +++ b/lib/rbot/rfc2812.rb @@ -902,7 +902,7 @@ module Irc # This is not always true, though, since some servers do not send a # full hostmask for user messages. # - if prefix =~ /^#{Regexp::Irc::GEN_MASK}$/ + if prefix =~ /^#{Regexp::Irc::GEN_USER_ID}$/ data[:source] = @server.user(prefix) else if @server.hostname -- 2.39.5