3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 21:19:31 +01:00

ts6: implement services account tracking (#25)

This adds a new protocol hook: [user_logging_in, 'CLIENT_SERVICES_LOGIN', {'text': account_name}], sent whenever someone logs in to services. Actual state tracking is done in coreplugin.py
This commit is contained in:
James Lu 2016-02-07 18:38:22 -08:00
parent cf15bed58d
commit 0fff91edfd
2 changed files with 33 additions and 2 deletions

View File

@ -135,6 +135,11 @@ def handle_operup(irc, source, command, args):
log.info("(%s) Successful oper-up (opertype %r) from %s", irc.name, args.get('text'), utils.getHostmask(irc, source)) log.info("(%s) Successful oper-up (opertype %r) from %s", irc.name, args.get('text'), utils.getHostmask(irc, source))
utils.add_hook(handle_operup, 'CLIENT_OPERED') utils.add_hook(handle_operup, 'CLIENT_OPERED')
def handle_services_login(irc, source, command, args):
"""Sets services login status for users."""
irc.users[source].services_account = args['text']
utils.add_hook(handle_services_login, 'CLIENT_SERVICES_LOGIN')
# Essential, core commands go here so that the "commands" plugin with less-important, # Essential, core commands go here so that the "commands" plugin with less-important,
# but still generic functions can be reloaded. # but still generic functions can be reloaded.

View File

@ -486,10 +486,10 @@ class TS6Protocol(TS6BaseProtocol):
"""Handles incoming EUID commands (user introduction).""" """Handles incoming EUID commands (user introduction)."""
# <- :42X EUID GL 1 1437505322 +ailoswz ~gl 127.0.0.1 127.0.0.1 42XAAAAAB * * :realname # <- :42X EUID GL 1 1437505322 +ailoswz ~gl 127.0.0.1 127.0.0.1 42XAAAAAB * * :realname
nick = args[0] nick = args[0]
ts, modes, ident, host, ip, uid, realhost = args[2:9] ts, modes, ident, host, ip, uid, realhost, accountname, realname = args[2:11]
if realhost == '*': if realhost == '*':
realhost = None realhost = None
realname = args[-1]
log.debug('(%s) handle_euid got args: nick=%s ts=%s uid=%s ident=%s ' log.debug('(%s) handle_euid got args: nick=%s ts=%s uid=%s ident=%s '
'host=%s realname=%s realhost=%s ip=%s', self.irc.name, nick, ts, uid, 'host=%s realname=%s realhost=%s ip=%s', self.irc.name, nick, ts, uid,
ident, host, realname, realhost, ip) ident, host, realname, realhost, ip)
@ -498,14 +498,21 @@ class TS6Protocol(TS6BaseProtocol):
ip = '0.0.0.0' ip = '0.0.0.0'
self.irc.users[uid] = IrcUser(nick, ts, uid, ident, host, realname, realhost, ip) self.irc.users[uid] = IrcUser(nick, ts, uid, ident, host, realname, realhost, ip)
parsedmodes = utils.parseModes(self.irc, uid, [modes]) parsedmodes = utils.parseModes(self.irc, uid, [modes])
log.debug('Applying modes %s for %s', parsedmodes, uid) log.debug('Applying modes %s for %s', parsedmodes, uid)
utils.applyModes(self.irc, uid, parsedmodes) utils.applyModes(self.irc, uid, parsedmodes)
self.irc.servers[numeric].users.add(uid) self.irc.servers[numeric].users.add(uid)
# Call the OPERED UP hook if +o is being added to the mode list. # Call the OPERED UP hook if +o is being added to the mode list.
if ('+o', None) in parsedmodes: if ('+o', None) in parsedmodes:
otype = 'Server_Administrator' if ('+a', None) in parsedmodes else 'IRC_Operator' otype = 'Server_Administrator' if ('+a', None) in parsedmodes else 'IRC_Operator'
self.irc.callHooks([uid, 'CLIENT_OPERED', {'text': otype}]) self.irc.callHooks([uid, 'CLIENT_OPERED', {'text': otype}])
# Set the accountname if present
if accountname != "*":
self.irc.callHooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': accountname}])
return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip} return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip}
def handle_uid(self, numeric, command, args): def handle_uid(self, numeric, command, args):
@ -641,4 +648,23 @@ class TS6Protocol(TS6BaseProtocol):
'your IRCd configuration.', self.irc.name, setter, badmode, 'your IRCd configuration.', self.irc.name, setter, badmode,
charlist[badmode]) charlist[badmode])
def handle_encap(self, numeric, command, args):
"""
Handles the ENCAP command - encapsulated TS6 commands with a variety of
subcommands used for different purposes.
"""
commandname = args[1]
if commandname == 'SU':
# Handles SU, which is used for setting login information
# <- :00A ENCAP * SU 42XAAAAAC :GLolol
# <- :00A ENCAP * SU 42XAAAAAC
try:
account = args[3] # Account name is being set
except IndexError:
account = '' # No account name means a logout
uid = args[2]
self.irc.callHooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': account}])
Class = TS6Protocol Class = TS6Protocol