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

relay: more efficient getLocalUser

Set the .remote attribute of each relay client to the original netname, user pair.
This commit is contained in:
James Lu 2015-08-15 19:18:04 -07:00
parent d3ee7ed918
commit dd91b7e5a0

View File

@ -145,7 +145,7 @@ def getRemoteUser(irc, remoteirc, user, spawnIfMissing=True):
u = remoteirc.proto.spawnClient(remoteirc, nick, ident=ident, u = remoteirc.proto.spawnClient(remoteirc, nick, ident=ident,
host=host, realname=realname, host=host, realname=realname,
modes=modes, ts=userobj.ts).uid modes=modes, ts=userobj.ts).uid
remoteirc.users[u].remote = irc.name remoteirc.users[u].remote = (irc.name, user)
away = userobj.away away = userobj.away
if away: if away:
remoteirc.proto.awayClient(remoteirc, u, away) remoteirc.proto.awayClient(remoteirc, u, away)
@ -163,21 +163,10 @@ def getLocalUser(irc, user, targetirc=None):
representing the original user on the target network, similar to what representing the original user on the target network, similar to what
getRemoteUser() does.""" getRemoteUser() does."""
# First, iterate over everyone! # First, iterate over everyone!
remoteuser = None try:
for k, v in relayusers.items(): remoteuser = irc.users[user].remote
if k[0] == irc.name: except (AttributeError, KeyError):
# We don't need to do anything if the target users is on remoteuser = None
# the same network as us.
continue
if v.get(irc.name) == user:
# If the stored pseudoclient UID for the kicked user on
# this network matches the target we have, set that user
# as the one we're kicking! It's a handful, but remember
# we're mapping (home network, UID) pairs to their
# respective relay pseudoclients on other networks.
remoteuser = k
log.debug('(%s) getLocalUser: found %s to correspond to %s.', irc.name, v, k)
break
log.debug('(%s) getLocalUser: remoteuser set to %r (looking up %s/%s).', irc.name, remoteuser, user, irc.name) log.debug('(%s) getLocalUser: remoteuser set to %r (looking up %s/%s).', irc.name, remoteuser, user, irc.name)
if remoteuser: if remoteuser:
# If targetirc is given, we'll return simply the UID of the user on the # If targetirc is given, we'll return simply the UID of the user on the
@ -430,9 +419,9 @@ def handle_kick(irc, source, command, args):
remotechan, real_target, text) remotechan, real_target, text)
if target != irc.pseudoclient.uid and not irc.users[target].channels: if target != irc.pseudoclient.uid and not irc.users[target].channels:
irc.proto.quitClient(irc, target, 'Left all shared channels.')
remoteuser = getLocalUser(irc, target) remoteuser = getLocalUser(irc, target)
del relayusers[remoteuser][irc.name] del relayusers[remoteuser][irc.name]
irc.proto.quitClient(irc, target, 'Left all shared channels.')
utils.add_hook(handle_kick, 'KICK') utils.add_hook(handle_kick, 'KICK')