From d52fba37b8c759d3b834beee960bb2bc2435de07 Mon Sep 17 00:00:00 2001 From: James Lu Date: Wed, 22 Jul 2015 21:15:34 -0700 Subject: [PATCH] add numericServer for sending raw numerics from servers, and WHOIS handling in coreplugin Basic WHOIS handling (user information, server information, IRCop access) are sent. #72 TODO: send channel lists, an extra note for relay clients, user modes, and idle time --- coreplugin.py | 22 ++++++++++++++++++++++ protocols/inspircd.py | 6 ++++++ protocols/ts6.py | 7 +++++++ 3 files changed, 35 insertions(+) diff --git a/coreplugin.py b/coreplugin.py index 32871e3..d06d4b8 100644 --- a/coreplugin.py +++ b/coreplugin.py @@ -36,3 +36,25 @@ def handle_commands(irc, source, command, args): utils.msg(irc, source, 'Uncaught exception in command %r: %s: %s' % (cmd, type(e).__name__, str(e))) return utils.add_hook(handle_commands, 'PRIVMSG') + +# Return WHOIS replies to IRCds that use them. +def handle_whois(irc, source, command, args): + target = args['target'] + user = irc.users.get(target) + if user is None: + log.warning('(%s) Got a WHOIS request for %r from %r, but the target doesn\'t exist in irc.users!', irc.name, target, source) + f = irc.proto.numericServer + server = utils.clientToServer(irc, target) or irc.sid + nick = user.nick + # https://www.alien.net.au/irc/irc2numerics.html + # 311: sends nick!user@host information + f(irc, server, 311, source, "%s %s %s * :%s" % (nick, user.ident, user.host, user.realname)) + # 312: sends the server the target is on, and the name + f(irc, server, 312, source, "%s %s :PyLink Server" % (nick, irc.serverdata['hostname'])) + # 313: sends a string denoting the target's operator privilege; + # we'll only send it if the user has umode +o. + if ('o', None) in user.modes: + f(irc, server, 313, source, "%s :is an IRC Operator" % nick) + # 318: End of WHOIS. + f(irc, server, 318, source, "%s :End of WHOIS" % nick.lower()) +utils.add_hook(handle_whois, 'WHOIS') diff --git a/protocols/inspircd.py b/protocols/inspircd.py index b095cd0..aa82579 100644 --- a/protocols/inspircd.py +++ b/protocols/inspircd.py @@ -293,6 +293,12 @@ def pingServer(irc, source=None, target=None): if not (target is None or source is None): _send(irc, source, 'PING %s %s' % (source, target)) +def numericServer(irc, source, numeric, text): + raise NotImplementedError("Numeric sending is not yet implemented by this " + "protocol module. WHOIS requests are handled " + "locally by InspIRCd servers, so there is no " + "need for PyLink to send numerics directly yet.") + def connect(irc): ts = irc.start_ts irc.uidgen = {} diff --git a/protocols/ts6.py b/protocols/ts6.py index 668c2be..1529ba0 100644 --- a/protocols/ts6.py +++ b/protocols/ts6.py @@ -230,6 +230,9 @@ def pingServer(irc, source=None, target=None): else: _send(irc, source, 'PING %s' % source) +def numericServer(irc, source, numeric, target, text): + _send(irc, source, '%s %s %s' % (numeric, target, text)) + def connect(irc): ts = irc.start_ts irc.uidgen = {} @@ -586,3 +589,7 @@ def handle_bmask(irc, numeric, command, args): modes.append(('+%s' % mode, ban)) utils.applyModes(irc, channel, modes) return {'target': channel, 'modes': modes, 'ts': ts} + +def handle_whois(irc, numeric, command, args): + # <- :42XAAAAAB WHOIS 5PYAAAAAA :pylink-devel + return {'target': args[0]}