3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-24 11:39:25 +01:00

Merge branch 'wip/admin-commands-loopback' into devel

Conflicts:
	plugins/relay.py
This commit is contained in:
James Lu 2015-08-17 07:52:45 -07:00
commit de36c7a62a
2 changed files with 36 additions and 17 deletions

View File

@ -62,6 +62,7 @@ def quit(irc, source, args):
u = utils.nickToUid(irc, nick) u = utils.nickToUid(irc, nick)
quitmsg = ' '.join(args[1:]) or 'Client quit' quitmsg = ' '.join(args[1:]) or 'Client quit'
irc.proto.quitClient(irc, u, quitmsg) irc.proto.quitClient(irc, u, quitmsg)
irc.callHooks([u, 'PYLINK_ADMIN_QUIT', {'text': quitmsg, 'parse_as': 'QUIT'}])
def joinclient(irc, source, args): def joinclient(irc, source, args):
"""<target> <channel1>,[<channel2>], etc. """<target> <channel1>,[<channel2>], etc.
@ -82,6 +83,9 @@ def joinclient(irc, source, args):
utils.msg(irc, source, "Error: Invalid channel name %r." % channel) utils.msg(irc, source, "Error: Invalid channel name %r." % channel)
return return
irc.proto.joinClient(irc, u, channel) irc.proto.joinClient(irc, u, channel)
irc.callHooks([u, 'PYLINK_ADMIN_JOIN', {'channel': channel, 'users': [u],
'modes': irc.channels[channel].modes,
'parse_as': 'JOIN'}])
utils.add_cmd(joinclient, name='join') utils.add_cmd(joinclient, name='join')
@utils.add_cmd @utils.add_cmd
@ -103,6 +107,7 @@ def nick(irc, source, args):
utils.msg(irc, source, 'Error: Invalid nickname %r.' % newnick) utils.msg(irc, source, 'Error: Invalid nickname %r.' % newnick)
return return
irc.proto.nickClient(irc, u, newnick) irc.proto.nickClient(irc, u, newnick)
irc.callHooks([u, 'PYLINK_ADMIN_NICK', {'newnick': newnick, 'oldnick': nick, 'parse_as': 'NICK'}])
@utils.add_cmd @utils.add_cmd
def part(irc, source, args): def part(irc, source, args):
@ -123,6 +128,7 @@ def part(irc, source, args):
utils.msg(irc, source, "Error: Invalid channel name %r." % channel) utils.msg(irc, source, "Error: Invalid channel name %r." % channel)
return return
irc.proto.partClient(irc, u, channel, reason) irc.proto.partClient(irc, u, channel, reason)
irc.callHooks([u, 'PYLINK_ADMIN_PART', {'channels': clist, 'text': reason, 'parse_as': 'PART'}])
@utils.add_cmd @utils.add_cmd
def kick(irc, source, args): def kick(irc, source, args):
@ -144,6 +150,7 @@ def kick(irc, source, args):
utils.msg(irc, source, "Error: Invalid channel name %r." % channel) utils.msg(irc, source, "Error: Invalid channel name %r." % channel)
return return
irc.proto.kickClient(irc, u, channel, targetu, reason) irc.proto.kickClient(irc, u, channel, targetu, reason)
irc.callHooks([u, 'PYLINK_ADMIN_KICK', {'channel': channel, 'target': targetu, 'text': reason, 'parse_as': 'KICK'}])
@utils.add_cmd @utils.add_cmd
def showuser(irc, source, args): def showuser(irc, source, args):
@ -205,9 +212,11 @@ def mode(irc, source, args):
return return
if utils.isInternalServer(irc, modesource): if utils.isInternalServer(irc, modesource):
irc.proto.modeServer(irc, modesource, target, parsedmodes) irc.proto.modeServer(irc, modesource, target, parsedmodes)
irc.callHooks([modesource, 'PYLINK_ADMIN_MODE', {'target': target, 'modes': parsedmodes, 'parse_as': 'MODE'}])
else: else:
sourceuid = utils.nickToUid(irc, modesource) sourceuid = utils.nickToUid(irc, modesource)
irc.proto.modeClient(irc, sourceuid, target, parsedmodes) irc.proto.modeClient(irc, sourceuid, target, parsedmodes)
irc.callHooks([sourceuid, 'PYLINK_ADMIN_MODE', {'target': target, 'modes': parsedmodes, 'parse_as': 'MODE'}])
@utils.add_cmd @utils.add_cmd
def msg(irc, source, args): def msg(irc, source, args):
@ -235,3 +244,4 @@ def msg(irc, source, args):
utils.msg(irc, source, 'Error: no text given.') utils.msg(irc, source, 'Error: no text given.')
return return
irc.proto.messageClient(irc, sourceuid, real_target, text) irc.proto.messageClient(irc, sourceuid, real_target, text)
irc.callHooks([sourceuid, 'PYLINK_ADMIN_MSG', {'target': real_target, 'text': text, 'parse_as': 'PRIVMSG'}])

View File

@ -61,7 +61,7 @@ def normalizeNick(irc, netname, nick, separator=None, oldnick=''):
nick += suffix nick += suffix
# FIXME: factorize # FIXME: factorize
while utils.nickToUid(irc, nick) or utils.nickToUid(irc, oldnick) and not \ while utils.nickToUid(irc, nick) or utils.nickToUid(irc, oldnick) and not \
utils.isInternalClient(irc, utils.nickToUid(irc, nick)): isRelayClient(irc, utils.nickToUid(irc, nick)):
# The nick we want exists? Darn, create another one then, but only if # The nick we want exists? Darn, create another one then, but only if
# the target isn't an internal client! # the target isn't an internal client!
# Increase the separator length by 1 if the user was already tagged, # Increase the separator length by 1 if the user was already tagged,
@ -281,6 +281,9 @@ utils.add_hook(handle_nick, 'NICK')
def handle_part(irc, numeric, command, args): def handle_part(irc, numeric, command, args):
channels = args['channels'] channels = args['channels']
text = args['text'] text = args['text']
# Don't allow the PyLink client PARTing to be relayed.
if numeric == irc.pseudoclient.uid:
return
for channel in channels: for channel in channels:
for netname, user in relayusers[(irc.name, numeric)].copy().items(): for netname, user in relayusers[(irc.name, numeric)].copy().items():
remoteirc = utils.networkobjects[netname] remoteirc = utils.networkobjects[netname]
@ -358,7 +361,8 @@ def handle_kick(irc, source, command, args):
kicker = source kicker = source
kicker_modes = getPrefixModes(irc, irc, channel, kicker) kicker_modes = getPrefixModes(irc, irc, channel, kicker)
relay = findRelay((irc.name, channel)) relay = findRelay((irc.name, channel))
if relay is None: # Don't allow kicks to the PyLink client to be relayed.
if relay is None or target == irc.pseudoclient.uid:
return return
for name, remoteirc in utils.networkobjects.items(): for name, remoteirc in utils.networkobjects.items():
if irc.name == name or not remoteirc.connected.is_set(): if irc.name == name or not remoteirc.connected.is_set():
@ -369,7 +373,7 @@ def handle_kick(irc, source, command, args):
continue continue
real_kicker = getRemoteUser(irc, remoteirc, kicker, spawnIfMissing=False) real_kicker = getRemoteUser(irc, remoteirc, kicker, spawnIfMissing=False)
log.debug('(%s) Relay kick: real kicker for %s on %s is %s', irc.name, kicker, name, real_kicker) log.debug('(%s) Relay kick: real kicker for %s on %s is %s', irc.name, kicker, name, real_kicker)
if not utils.isInternalClient(irc, target): if not isRelayClient(irc, target):
log.debug('(%s) Relay kick: target %s is NOT an internal client', irc.name, target) log.debug('(%s) Relay kick: target %s is NOT an internal client', irc.name, target)
# Both the target and kicker are external clients; i.e. # Both the target and kicker are external clients; i.e.
# they originate from the same network. We won't have # they originate from the same network. We won't have
@ -397,6 +401,8 @@ def handle_kick(irc, source, command, args):
"(half)opped." % channel, notice=True) "(half)opped." % channel, notice=True)
return return
if not real_target:
return
# Propogate the kick! # Propogate the kick!
if real_kicker: if real_kicker:
log.debug('(%s) Relay kick: Kicking %s from channel %s via %s on behalf of %s/%s', irc.name, real_target, remotechan,real_kicker, kicker, irc.name) log.debug('(%s) Relay kick: Kicking %s from channel %s via %s on behalf of %s/%s', irc.name, real_target, remotechan,real_kicker, kicker, irc.name)
@ -417,7 +423,7 @@ def handle_kick(irc, source, command, args):
remoteirc.proto.kickServer(remoteirc, remoteirc.sid, remoteirc.proto.kickServer(remoteirc, remoteirc.sid,
remotechan, real_target, text) remotechan, real_target, text)
if target != irc.pseudoclient.uid and not irc.users[target].channels: if isRelayClient(irc, target) and not irc.users[target].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.') irc.proto.quitClient(irc, target, 'Left all shared channels.')
@ -632,6 +638,16 @@ def handle_kill(irc, numeric, command, args):
utils.add_hook(handle_kill, 'KILL') utils.add_hook(handle_kill, 'KILL')
def isRelayClient(irc, user):
try:
if irc.users[user].remote:
# Is the .remote attribute set? If so, don't relay already
# relayed clients; that'll trigger an endless loop!
return True
except (KeyError, AttributeError): # Nope, it isn't.
pass
return False
def relayJoins(irc, channel, users, ts): def relayJoins(irc, channel, users, ts):
for name, remoteirc in utils.networkobjects.items(): for name, remoteirc in utils.networkobjects.items():
queued_users = [] queued_users = []
@ -645,17 +661,10 @@ def relayJoins(irc, channel, users, ts):
continue continue
log.debug('(%s) relayJoins: got %r for users', irc.name, users) log.debug('(%s) relayJoins: got %r for users', irc.name, users)
for user in users.copy(): for user in users.copy():
if utils.isInternalClient(irc, user) or user not in irc.users: if isRelayClient(irc, user):
# We don't need to clone PyLink pseudoclients... That's # Don't clone relay clients; that'll cause some bad, bad
# meaningless. # things to happen.
continue continue
try:
if irc.users[user].remote:
# Is the .remote attribute set? If so, don't relay already
# relayed clients; that'll trigger an endless loop!
continue
except AttributeError: # Nope, it isn't.
pass
log.debug('Okay, spawning %s/%s everywhere', user, irc.name) log.debug('Okay, spawning %s/%s everywhere', user, irc.name)
assert user in irc.users, "(%s) How is this possible? %r isn't in our user database." % (irc.name, user) assert user in irc.users, "(%s) How is this possible? %r isn't in our user database." % (irc.name, user)
u = getRemoteUser(irc, remoteirc, user) u = getRemoteUser(irc, remoteirc, user)
@ -686,7 +695,7 @@ def relayPart(irc, channel, user):
if remotechan is None or remoteuser is None: if remotechan is None or remoteuser is None:
continue continue
remoteirc.proto.partClient(remoteirc, remoteuser, remotechan, 'Channel delinked.') remoteirc.proto.partClient(remoteirc, remoteuser, remotechan, 'Channel delinked.')
if not remoteirc.users[remoteuser].channels: if isRelayClient(remoteirc, remoteuser) and not remoteirc.users[remoteuser].channels:
remoteirc.proto.quitClient(remoteirc, remoteuser, 'Left all shared channels.') remoteirc.proto.quitClient(remoteirc, remoteuser, 'Left all shared channels.')
del relayusers[(irc.name, user)][remoteirc.name] del relayusers[(irc.name, user)][remoteirc.name]
@ -698,7 +707,7 @@ def removeChannel(irc, channel):
relay = findRelay((irc.name, channel)) relay = findRelay((irc.name, channel))
if relay: if relay:
for user in irc.channels[channel].users.copy(): for user in irc.channels[channel].users.copy():
if not utils.isInternalClient(irc, user): if not isRelayClient(irc, user):
relayPart(irc, channel, user) relayPart(irc, channel, user)
# Don't ever part the main client from any of its autojoin channels. # Don't ever part the main client from any of its autojoin channels.
else: else:
@ -893,7 +902,7 @@ def handle_save(irc, numeric, command, args):
realuser = getLocalUser(irc, target) realuser = getLocalUser(irc, target)
log.debug('(%s) relay handle_save: %r got in a nick collision! Real user: %r', log.debug('(%s) relay handle_save: %r got in a nick collision! Real user: %r',
irc.name, target, realuser) irc.name, target, realuser)
if utils.isInternalClient(irc, target) and realuser: if isRelayClient(irc, target) and realuser:
# Nick collision! # Nick collision!
# It's one of our relay clients; try to fix our nick to the next # It's one of our relay clients; try to fix our nick to the next
# available normalized nick. # available normalized nick.