mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +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:
parent
d3ee7ed918
commit
dd91b7e5a0
@ -145,7 +145,7 @@ def getRemoteUser(irc, remoteirc, user, spawnIfMissing=True):
|
||||
u = remoteirc.proto.spawnClient(remoteirc, nick, ident=ident,
|
||||
host=host, realname=realname,
|
||||
modes=modes, ts=userobj.ts).uid
|
||||
remoteirc.users[u].remote = irc.name
|
||||
remoteirc.users[u].remote = (irc.name, user)
|
||||
away = userobj.away
|
||||
if 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
|
||||
getRemoteUser() does."""
|
||||
# First, iterate over everyone!
|
||||
remoteuser = None
|
||||
for k, v in relayusers.items():
|
||||
if k[0] == irc.name:
|
||||
# We don't need to do anything if the target users is on
|
||||
# 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
|
||||
try:
|
||||
remoteuser = irc.users[user].remote
|
||||
except (AttributeError, KeyError):
|
||||
remoteuser = None
|
||||
log.debug('(%s) getLocalUser: remoteuser set to %r (looking up %s/%s).', irc.name, remoteuser, user, irc.name)
|
||||
if remoteuser:
|
||||
# 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)
|
||||
|
||||
if target != irc.pseudoclient.uid and not irc.users[target].channels:
|
||||
irc.proto.quitClient(irc, target, 'Left all shared channels.')
|
||||
remoteuser = getLocalUser(irc, target)
|
||||
del relayusers[remoteuser][irc.name]
|
||||
irc.proto.quitClient(irc, target, 'Left all shared channels.')
|
||||
|
||||
utils.add_hook(handle_kick, 'KICK')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user