3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-01-05 17:53:00 +01:00

plugins: migrate irc.proto calls to irc

This commit is contained in:
James Lu 2017-06-25 02:07:24 -07:00
parent 748c1bc158
commit 4696519bad
8 changed files with 69 additions and 69 deletions

View File

@ -113,7 +113,7 @@ def match(irc, channel, uids=None):
log.debug("(%s) automode: sending modes from modebot_uid %s", log.debug("(%s) automode: sending modes from modebot_uid %s",
irc.name, modebot_uid) irc.name, modebot_uid)
irc.proto.mode(modebot_uid, channel, outgoing_modes) irc.mode(modebot_uid, channel, outgoing_modes)
# Create a hook payload to support plugins like relay. # Create a hook payload to support plugins like relay.
irc.callHooks([modebot_uid, 'AUTOMODE_MODE', irc.callHooks([modebot_uid, 'AUTOMODE_MODE',

View File

@ -18,7 +18,7 @@ def spawnclient(irc, source, args):
except ValueError: except ValueError:
irc.error("Not enough arguments. Needs 3: nick, user, host.") irc.error("Not enough arguments. Needs 3: nick, user, host.")
return return
irc.proto.spawnClient(nick, ident, host, manipulatable=True) irc.spawnClient(nick, ident, host, manipulatable=True)
irc.reply("Done.") irc.reply("Done.")
@utils.add_cmd @utils.add_cmd
@ -45,7 +45,7 @@ def quit(irc, source, args):
irc.error("Cannot force quit a protected PyLink services client.") irc.error("Cannot force quit a protected PyLink services client.")
return return
irc.proto.quit(u, quitmsg) irc.quit(u, quitmsg)
irc.reply("Done.") irc.reply("Done.")
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_QUIT', {'text': quitmsg, 'parse_as': 'QUIT'}]) irc.callHooks([u, 'PYLINK_BOTSPLUGIN_QUIT', {'text': quitmsg, 'parse_as': 'QUIT'}])
@ -99,9 +99,9 @@ def joinclient(irc, source, args):
# join() doesn't support prefixes. # join() doesn't support prefixes.
if prefixes: if prefixes:
irc.proto.sjoin(irc.sid, real_channel, [(joinmodes, u)]) irc.sjoin(irc.sid, real_channel, [(joinmodes, u)])
else: else:
irc.proto.join(u, real_channel) irc.join(u, real_channel)
# Call a join hook manually so other plugins like relay can understand it. # Call a join hook manually so other plugins like relay can understand it.
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_JOIN', {'channel': real_channel, 'users': [u], irc.callHooks([u, 'PYLINK_BOTSPLUGIN_JOIN', {'channel': real_channel, 'users': [u],
@ -141,7 +141,7 @@ def nick(irc, source, args):
irc.error("Cannot force nick changes for a protected PyLink services client.") irc.error("Cannot force nick changes for a protected PyLink services client.")
return return
irc.proto.nick(u, newnick) irc.nick(u, newnick)
irc.reply("Done.") irc.reply("Done.")
# Ditto above: manually send a NICK change hook payload to other plugins. # Ditto above: manually send a NICK change hook payload to other plugins.
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_NICK', {'newnick': newnick, 'oldnick': nick, 'parse_as': 'NICK'}]) irc.callHooks([u, 'PYLINK_BOTSPLUGIN_NICK', {'newnick': newnick, 'oldnick': nick, 'parse_as': 'NICK'}])
@ -188,7 +188,7 @@ def part(irc, source, args):
if not utils.isChannel(channel): if not utils.isChannel(channel):
irc.error("Invalid channel name %r." % channel) irc.error("Invalid channel name %r." % channel)
return return
irc.proto.part(u, channel, reason) irc.part(u, channel, reason)
irc.reply("Done.") irc.reply("Done.")
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_PART', {'channels': clist, 'text': reason, 'parse_as': 'PART'}]) irc.callHooks([u, 'PYLINK_BOTSPLUGIN_PART', {'channels': clist, 'text': reason, 'parse_as': 'PART'}])
@ -236,7 +236,7 @@ def msg(irc, source, args):
else: else:
real_target = target real_target = target
irc.proto.message(sourceuid, real_target, text) irc.message(sourceuid, real_target, text)
irc.reply("Done.") irc.reply("Done.")
irc.callHooks([sourceuid, 'PYLINK_BOTSPLUGIN_MSG', {'target': real_target, 'text': text, 'parse_as': 'PRIVMSG'}]) irc.callHooks([sourceuid, 'PYLINK_BOTSPLUGIN_MSG', {'target': real_target, 'text': text, 'parse_as': 'PRIVMSG'}])
utils.add_cmd(msg, 'say') utils.add_cmd(msg, 'say')

View File

@ -78,7 +78,7 @@ def _changehost(irc, target, args):
if char not in allowed_chars: if char not in allowed_chars:
new_host = new_host.replace(char, '-') new_host = new_host.replace(char, '-')
irc.proto.updateClient(target, 'HOST', new_host) irc.updateClient(target, 'HOST', new_host)
# Only operate on the first match. # Only operate on the first match.
break break

View File

@ -110,7 +110,7 @@ def showchan(irc, source, args):
# Mark TS values as untrusted on Clientbot and others (where TS is read-only or not trackable) # Mark TS values as untrusted on Clientbot and others (where TS is read-only or not trackable)
f('\x02Channel creation time\x02: %s (%s)%s' % (ctime(c.ts), c.ts, f('\x02Channel creation time\x02: %s (%s)%s' % (ctime(c.ts), c.ts,
' [UNTRUSTED]' if not irc.proto.hasCap('has-ts') else '')) ' [UNTRUSTED]' if not irc.hasCap('has-ts') else ''))
# Show only modes that aren't list-style modes. # Show only modes that aren't list-style modes.
modes = irc.joinModes([m for m in c.modes if m[0] not in irc.cmodes['*A']], sort=True) modes = irc.joinModes([m for m in c.modes if m[0] not in irc.cmodes['*A']], sort=True)

View File

@ -70,7 +70,7 @@ def jupe(irc, source, args):
irc.error("Invalid server name '%s'." % servername) irc.error("Invalid server name '%s'." % servername)
return return
sid = irc.proto.spawnServer(servername, desc=desc) sid = irc.spawnServer(servername, desc=desc)
irc.callHooks([irc.pseudoclient.uid, 'OPERCMDS_SPAWNSERVER', irc.callHooks([irc.pseudoclient.uid, 'OPERCMDS_SPAWNSERVER',
{'name': servername, 'sid': sid, 'text': desc}]) {'name': servername, 'sid': sid, 'text': desc}])
@ -104,7 +104,7 @@ def kick(irc, source, args):
return return
sender = irc.pseudoclient.uid sender = irc.pseudoclient.uid
irc.proto.kick(sender, channel, targetu, reason) irc.kick(sender, channel, targetu, reason)
irc.reply("Done.") irc.reply("Done.")
irc.callHooks([sender, 'CHANCMDS_KICK', {'channel': channel, 'target': targetu, irc.callHooks([sender, 'CHANCMDS_KICK', {'channel': channel, 'target': targetu,
'text': reason, 'parse_as': 'KICK'}]) 'text': reason, 'parse_as': 'KICK'}])
@ -132,7 +132,7 @@ def kill(irc, source, args):
irc.error("No such nick '%s'." % target) irc.error("No such nick '%s'." % target)
return return
irc.proto.kill(sender, targetu, reason) irc.kill(sender, targetu, reason)
# Format the kill reason properly in hooks. # Format the kill reason properly in hooks.
reason = "Killed (%s (%s))" % (irc.getFriendlyName(sender), reason) reason = "Killed (%s (%s))" % (irc.getFriendlyName(sender), reason)
@ -173,7 +173,7 @@ def mode(irc, source, args):
irc.error("No valid modes were given.") irc.error("No valid modes were given.")
return return
irc.proto.mode(irc.pseudoclient.uid, target, parsedmodes) irc.mode(irc.pseudoclient.uid, target, parsedmodes)
# Call the appropriate hooks for plugins like relay. # Call the appropriate hooks for plugins like relay.
irc.callHooks([irc.pseudoclient.uid, 'OPERCMDS_MODEOVERRIDE', irc.callHooks([irc.pseudoclient.uid, 'OPERCMDS_MODEOVERRIDE',
@ -198,7 +198,7 @@ def topic(irc, source, args):
irc.error("Unknown channel %r." % channel) irc.error("Unknown channel %r." % channel)
return return
irc.proto.topic(irc.pseudoclient.uid, channel, topic) irc.topic(irc.pseudoclient.uid, channel, topic)
irc.reply("Done.") irc.reply("Done.")
irc.callHooks([irc.pseudoclient.uid, 'CHANCMDS_TOPIC', irc.callHooks([irc.pseudoclient.uid, 'CHANCMDS_TOPIC',

View File

@ -117,7 +117,7 @@ def normalize_nick(irc, netname, nick, times_tagged=0, uid=''):
# Charybdis, IRCu, etc. don't allow / in nicks, and will SQUIT with a protocol # Charybdis, IRCu, etc. don't allow / in nicks, and will SQUIT with a protocol
# violation if it sees one. Or it might just ignore the client introduction and # violation if it sees one. Or it might just ignore the client introduction and
# cause bad desyncs. # cause bad desyncs.
protocol_allows_slashes = irc.proto.hasCap('slash-in-nicks') or \ protocol_allows_slashes = irc.hasCap('slash-in-nicks') or \
irc.serverdata.get('relay_force_slashes') irc.serverdata.get('relay_force_slashes')
if '/' not in separator or not protocol_allows_slashes: if '/' not in separator or not protocol_allows_slashes:
@ -176,11 +176,11 @@ def normalize_host(irc, host):
log.debug('(%s) relay.normalize_host: IRCd=%s, host=%s', irc.name, irc.protoname, host) log.debug('(%s) relay.normalize_host: IRCd=%s, host=%s', irc.name, irc.protoname, host)
allowed_chars = string.ascii_letters + string.digits + '-.:' allowed_chars = string.ascii_letters + string.digits + '-.:'
if irc.proto.hasCap('slash-in-hosts'): if irc.hasCap('slash-in-hosts'):
# UnrealIRCd and IRCd-Hybrid don't allow slashes in hostnames # UnrealIRCd and IRCd-Hybrid don't allow slashes in hostnames
allowed_chars += '/' allowed_chars += '/'
if irc.proto.hasCap('underscore-in-hosts'): if irc.hasCap('underscore-in-hosts'):
# Most IRCds allow _ in hostnames, but hybrid/charybdis/ratbox IRCds do not. # Most IRCds allow _ in hostnames, but hybrid/charybdis/ratbox IRCds do not.
allowed_chars += '_' allowed_chars += '_'
@ -219,7 +219,7 @@ def spawn_relay_server(irc, remoteirc):
suffix = conf.conf.get('relay', {}).get('server_suffix', 'relay') suffix = conf.conf.get('relay', {}).get('server_suffix', 'relay')
# Strip any leading or trailing .'s # Strip any leading or trailing .'s
suffix = suffix.strip('.') suffix = suffix.strip('.')
sid = irc.proto.spawnServer('%s.%s' % (remoteirc.name, suffix), sid = irc.spawnServer('%s.%s' % (remoteirc.name, suffix),
desc="PyLink Relay network - %s" % desc="PyLink Relay network - %s" %
(remoteirc.getFullNetworkName()), endburst_delay=3) (remoteirc.getFullNetworkName()), endburst_delay=3)
except (RuntimeError, ValueError): # Network not initialized yet, or a server name conflict. except (RuntimeError, ValueError): # Network not initialized yet, or a server name conflict.
@ -326,14 +326,14 @@ def spawn_relay_user(irc, remoteirc, user, times_tagged=0):
realhost = None realhost = None
ip = '0.0.0.0' ip = '0.0.0.0'
u = remoteirc.proto.spawnClient(nick, ident=ident, host=host, realname=realname, modes=modes, u = remoteirc.spawnClient(nick, ident=ident, host=host, realname=realname, modes=modes,
opertype=opertype, server=rsid, ip=ip, realhost=realhost).uid opertype=opertype, server=rsid, ip=ip, realhost=realhost).uid
try: try:
remoteirc.users[u].remote = (irc.name, user) remoteirc.users[u].remote = (irc.name, user)
remoteirc.users[u].opertype = opertype remoteirc.users[u].opertype = opertype
away = userobj.away away = userobj.away
if away: if away:
remoteirc.proto.away(u, away) remoteirc.away(u, away)
except KeyError: except KeyError:
# User got killed somehow while we were setting options on it. # User got killed somehow while we were setting options on it.
# This is probably being done by the uplink, due to something like an # This is probably being done by the uplink, due to something like an
@ -477,7 +477,7 @@ def initialize_channel(irc, channel):
# Only update the topic if it's different from what we already have, # Only update the topic if it's different from what we already have,
# and topic bursting is complete. # and topic bursting is complete.
if remoteirc.channels[remotechan].topicset and topic != irc.channels[channel].topic: if remoteirc.channels[remotechan].topicset and topic != irc.channels[channel].topic:
irc.proto.topicBurst(irc.sid, channel, topic) irc.topicBurst(irc.sid, channel, topic)
# Send our users and channel modes to the other nets # Send our users and channel modes to the other nets
log.debug('(%s) relay.initialize_channel: joining our (%s) users: %s', irc.name, remotenet, irc.channels[channel].users) log.debug('(%s) relay.initialize_channel: joining our (%s) users: %s', irc.name, remotenet, irc.channels[channel].users)
@ -494,7 +494,7 @@ def remove_channel(irc, channel):
if channel not in map(str.lower, irc.serverdata.get('channels', [])): if channel not in map(str.lower, irc.serverdata.get('channels', [])):
world.services['pylink'].extra_channels[irc.name].discard(channel) world.services['pylink'].extra_channels[irc.name].discard(channel)
if irc.pseudoclient: if irc.pseudoclient:
irc.proto.part(irc.pseudoclient.uid, channel, 'Channel delinked.') irc.part(irc.pseudoclient.uid, channel, 'Channel delinked.')
relay = get_relay((irc.name, channel)) relay = get_relay((irc.name, channel))
if relay: if relay:
@ -506,12 +506,12 @@ def remove_channel(irc, channel):
if user == irc.pseudoclient.uid and channel in \ if user == irc.pseudoclient.uid and channel in \
irc.serverdata.get('channels', []): irc.serverdata.get('channels', []):
continue continue
irc.proto.part(user, channel, 'Channel delinked.') irc.part(user, channel, 'Channel delinked.')
# Don't ever quit it either... # Don't ever quit it either...
if user != irc.pseudoclient.uid and not irc.users[user].channels: if user != irc.pseudoclient.uid and not irc.users[user].channels:
remoteuser = get_orig_user(irc, user) remoteuser = get_orig_user(irc, user)
del relayusers[remoteuser][irc.name] del relayusers[remoteuser][irc.name]
irc.proto.quit(user, 'Left all shared channels.') irc.quit(user, 'Left all shared channels.')
def check_claim(irc, channel, sender, chanobj=None): def check_claim(irc, channel, sender, chanobj=None):
""" """
@ -648,7 +648,7 @@ def relay_joins(irc, channel, users, ts, burst=True):
# Fetch the known channel TS and all the prefix modes for each user. This ensures # Fetch the known channel TS and all the prefix modes for each user. This ensures
# the different sides of the relay are merged properly. # the different sides of the relay are merged properly.
if not irc.proto.hasCap('has-ts'): if not irc.hasCap('has-ts'):
# Special hack for clientbot: just use the remote's modes so mode changes # Special hack for clientbot: just use the remote's modes so mode changes
# take precendence. (TS is always outside the clientbot's control) # take precendence. (TS is always outside the clientbot's control)
ts = remoteirc.channels[remotechan].ts ts = remoteirc.channels[remotechan].ts
@ -668,10 +668,10 @@ def relay_joins(irc, channel, users, ts, burst=True):
modes = get_supported_cmodes(irc, remoteirc, channel, irc.channels[channel].modes) modes = get_supported_cmodes(irc, remoteirc, channel, irc.channels[channel].modes)
rsid = get_remote_sid(remoteirc, irc) rsid = get_remote_sid(remoteirc, irc)
if rsid: if rsid:
remoteirc.proto.sjoin(rsid, remotechan, queued_users, ts=ts, modes=modes) remoteirc.sjoin(rsid, remotechan, queued_users, ts=ts, modes=modes)
else: else:
# A regular JOIN only needs the user and the channel. TS, source SID, etc., can all be omitted. # A regular JOIN only needs the user and the channel. TS, source SID, etc., can all be omitted.
remoteirc.proto.join(queued_users[0][1], remotechan) remoteirc.join(queued_users[0][1], remotechan)
joined_nets[remoteirc] = {'channel': remotechan, 'users': [u[-1] for u in queued_users]} joined_nets[remoteirc] = {'channel': remotechan, 'users': [u[-1] for u in queued_users]}
@ -701,11 +701,11 @@ def relay_part(irc, channel, user):
continue continue
# Part the relay client with the channel delinked message. # Part the relay client with the channel delinked message.
remoteirc.proto.part(remoteuser, remotechan, 'Channel delinked.') remoteirc.part(remoteuser, remotechan, 'Channel delinked.')
# If the relay client no longer has any channels, quit them to prevent inflating /lusers. # If the relay client no longer has any channels, quit them to prevent inflating /lusers.
if isRelayClient(remoteirc, remoteuser) and not remoteirc.users[remoteuser].channels: if isRelayClient(remoteirc, remoteuser) and not remoteirc.users[remoteuser].channels:
remoteirc.proto.quit(remoteuser, 'Left all shared channels.') remoteirc.quit(remoteuser, 'Left all shared channels.')
del relayusers[(irc.name, user)][remoteirc.name] del relayusers[(irc.name, user)][remoteirc.name]
@ -783,7 +783,7 @@ def get_supported_cmodes(irc, remoteirc, channel, modes):
"for network %r.", "for network %r.",
irc.name, modechar, arg, remoteirc.name) irc.name, modechar, arg, remoteirc.name)
if (not irc.proto.hasCap('can-spawn-clients')) and irc.pseudoclient and arg == irc.pseudoclient.uid: if (not irc.hasCap('can-spawn-clients')) and irc.pseudoclient and arg == irc.pseudoclient.uid:
# Skip modesync on the main PyLink client. # Skip modesync on the main PyLink client.
log.debug("(%s) relay.get_supported_cmodes: filtering prefix change (%r, %r) on Clientbot relayer", log.debug("(%s) relay.get_supported_cmodes: filtering prefix change (%r, %r) on Clientbot relayer",
irc.name, name, arg) irc.name, name, arg)
@ -848,7 +848,7 @@ def handle_relay_whois(irc, source, command, args):
"""Convenience wrapper to return WHOIS replies.""" """Convenience wrapper to return WHOIS replies."""
# WHOIS replies are by convention prefixed with the target user's nick. # WHOIS replies are by convention prefixed with the target user's nick.
text = '%s %s' % (targetuser.nick, text) text = '%s %s' % (targetuser.nick, text)
irc.proto.numeric(server, num, source, text) irc.numeric(server, num, source, text)
def checkSendKey(infoline): def checkSendKey(infoline):
""" """
@ -876,7 +876,7 @@ def handle_relay_whois(irc, source, command, args):
# Send account information if told to and the target is logged in. # Send account information if told to and the target is logged in.
wreply(330, "%s :is logged in (on %s) as" % (realuser.services_account, netname)) wreply(330, "%s :is logged in (on %s) as" % (realuser.services_account, netname))
if checkSendKey('whois_show_server') and realirc.proto.hasCap('can-track-servers'): if checkSendKey('whois_show_server') and realirc.hasCap('can-track-servers'):
wreply(320, ":is actually connected via the following server:") wreply(320, ":is actually connected via the following server:")
realserver = realirc.getServer(uid) realserver = realirc.getServer(uid)
realserver = realirc.servers[realserver] realserver = realirc.servers[realserver]
@ -936,7 +936,7 @@ def handle_join(irc, numeric, command, args):
if modes: if modes:
log.debug('(%s) relay.handle_join: reverting modes on BURST: %s', irc.name, irc.joinModes(modes)) log.debug('(%s) relay.handle_join: reverting modes on BURST: %s', irc.name, irc.joinModes(modes))
irc.proto.mode(irc.sid, channel, modes) irc.mode(irc.sid, channel, modes)
relay_joins(irc, channel, users, ts, burst=False) relay_joins(irc, channel, users, ts, burst=False)
utils.add_hook(handle_join, 'JOIN') utils.add_hook(handle_join, 'JOIN')
@ -950,7 +950,7 @@ def handle_quit(irc, numeric, command, args):
for netname, user in relayusers[(irc.name, numeric)].copy().items(): for netname, user in relayusers[(irc.name, numeric)].copy().items():
remoteirc = world.networkobjects[netname] remoteirc = world.networkobjects[netname]
try: # Try to quit the client. If this fails because they're missing, bail. try: # Try to quit the client. If this fails because they're missing, bail.
remoteirc.proto.quit(user, args['text']) remoteirc.quit(user, args['text'])
except LookupError: except LookupError:
pass pass
del relayusers[(irc.name, numeric)] del relayusers[(irc.name, numeric)]
@ -1007,7 +1007,7 @@ def handle_nick(irc, numeric, command, args):
remoteirc = world.networkobjects[netname] remoteirc = world.networkobjects[netname]
newnick = normalize_nick(remoteirc, irc.name, args['newnick'], uid=user) newnick = normalize_nick(remoteirc, irc.name, args['newnick'], uid=user)
if remoteirc.users[user].nick != newnick: if remoteirc.users[user].nick != newnick:
remoteirc.proto.nick(user, newnick) remoteirc.nick(user, newnick)
utils.add_hook(handle_nick, 'NICK') utils.add_hook(handle_nick, 'NICK')
def handle_part(irc, numeric, command, args): def handle_part(irc, numeric, command, args):
@ -1017,14 +1017,14 @@ def handle_part(irc, numeric, command, args):
if numeric == irc.pseudoclient.uid: if numeric == irc.pseudoclient.uid:
# For clientbot: treat forced parts to the bot as clearchan, and attempt to rejoin only # For clientbot: treat forced parts to the bot as clearchan, and attempt to rejoin only
# if it affected a relay. # if it affected a relay.
if not irc.proto.hasCap('can-spawn-clients'): if not irc.hasCap('can-spawn-clients'):
for channel in [c for c in channels if get_relay((irc.name, c))]: for channel in [c for c in channels if get_relay((irc.name, c))]:
for user in irc.channels[channel].users: for user in irc.channels[channel].users:
if (not irc.isInternalClient(user)) and (not isRelayClient(irc, user)): if (not irc.isInternalClient(user)) and (not isRelayClient(irc, user)):
irc.callHooks([irc.sid, 'CLIENTBOT_SERVICE_KICKED', {'channel': channel, 'target': user, irc.callHooks([irc.sid, 'CLIENTBOT_SERVICE_KICKED', {'channel': channel, 'target': user,
'text': 'Clientbot was force parted (Reason: %s)' % text or 'None', 'text': 'Clientbot was force parted (Reason: %s)' % text or 'None',
'parse_as': 'KICK'}]) 'parse_as': 'KICK'}])
irc.proto.join(irc.pseudoclient.uid, channel) irc.join(irc.pseudoclient.uid, channel)
return return
return return
@ -1035,9 +1035,9 @@ def handle_part(irc, numeric, command, args):
remotechan = get_remote_channel(irc, remoteirc, channel) remotechan = get_remote_channel(irc, remoteirc, channel)
if remotechan is None: if remotechan is None:
continue continue
remoteirc.proto.part(user, remotechan, text) remoteirc.part(user, remotechan, text)
if not remoteirc.users[user].channels: if not remoteirc.users[user].channels:
remoteirc.proto.quit(user, 'Left all shared channels.') remoteirc.quit(user, 'Left all shared channels.')
del relayusers[(irc.name, numeric)][remoteirc.name] del relayusers[(irc.name, numeric)][remoteirc.name]
utils.add_hook(handle_part, 'PART') utils.add_hook(handle_part, 'PART')
@ -1120,9 +1120,9 @@ def handle_messages(irc, numeric, command, args):
try: try:
if notice: if notice:
remoteirc.proto.notice(user, real_target, real_text) remoteirc.notice(user, real_target, real_text)
else: else:
remoteirc.proto.message(user, real_target, real_text) remoteirc.message(user, real_target, real_text)
except LookupError: except LookupError:
# Our relay clone disappeared while we were trying to send the message. # Our relay clone disappeared while we were trying to send the message.
# This is normally due to a nick conflict with the IRCd. # This is normally due to a nick conflict with the IRCd.
@ -1149,7 +1149,7 @@ def handle_messages(irc, numeric, command, args):
return return
remoteirc = world.networkobjects[homenet] remoteirc = world.networkobjects[homenet]
if (not remoteirc.proto.hasCap('can-spawn-clients')) and not conf.conf.get('relay', {}).get('allow_clientbot_pms'): if (not remoteirc.hasCap('can-spawn-clients')) and not conf.conf.get('relay', {}).get('allow_clientbot_pms'):
irc.msg(numeric, 'Private messages to users connected via Clientbot have ' irc.msg(numeric, 'Private messages to users connected via Clientbot have '
'been administratively disabled.', notice=True) 'been administratively disabled.', notice=True)
return return
@ -1158,9 +1158,9 @@ def handle_messages(irc, numeric, command, args):
try: try:
if notice: if notice:
remoteirc.proto.notice(user, real_target, text) remoteirc.notice(user, real_target, text)
else: else:
remoteirc.proto.message(user, real_target, text) remoteirc.message(user, real_target, text)
except LookupError: except LookupError:
# Our relay clone disappeared while we were trying to send the message. # Our relay clone disappeared while we were trying to send the message.
# This is normally due to a nick conflict with the IRCd. # This is normally due to a nick conflict with the IRCd.
@ -1180,7 +1180,7 @@ def handle_kick(irc, source, command, args):
relay = get_relay((irc.name, channel)) relay = get_relay((irc.name, channel))
# Special case for clientbot: treat kicks to the PyLink service bot as channel clear. # Special case for clientbot: treat kicks to the PyLink service bot as channel clear.
if (not irc.proto.hasCap('can-spawn-clients')) and irc.pseudoclient and target == irc.pseudoclient.uid: if (not irc.hasCap('can-spawn-clients')) and irc.pseudoclient and target == irc.pseudoclient.uid:
for user in irc.channels[channel].users: for user in irc.channels[channel].users:
if (not irc.isInternalClient(user)) and (not isRelayClient(irc, user)): if (not irc.isInternalClient(user)) and (not isRelayClient(irc, user)):
reason = "Clientbot kicked by %s (Reason: %s)" % (irc.getFriendlyName(source), text) reason = "Clientbot kicked by %s (Reason: %s)" % (irc.getFriendlyName(source), text)
@ -1222,7 +1222,7 @@ def handle_kick(irc, source, command, args):
# kick ops, admins can't kick owners, etc. # kick ops, admins can't kick owners, etc.
modes = get_prefix_modes(remoteirc, irc, remotechan, real_target) modes = get_prefix_modes(remoteirc, irc, remotechan, real_target)
# Join the kicked client back with its respective modes. # Join the kicked client back with its respective modes.
irc.proto.sjoin(irc.sid, channel, [(modes, target)]) irc.sjoin(irc.sid, channel, [(modes, target)])
if kicker in irc.users: if kicker in irc.users:
log.info('(%s) relay: Blocked KICK (reason %r) from %s/%s to relay client %s on %s.', log.info('(%s) relay: Blocked KICK (reason %r) from %s/%s to relay client %s on %s.',
irc.name, args['text'], irc.users[source].nick, irc.name, irc.name, args['text'], irc.users[source].nick, irc.name,
@ -1241,13 +1241,13 @@ def handle_kick(irc, source, command, args):
# Propogate the kick! # Propogate the kick!
if real_kicker: if real_kicker:
log.debug('(%s) relay.handle_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.handle_kick: Kicking %s from channel %s via %s on behalf of %s/%s', irc.name, real_target, remotechan,real_kicker, kicker, irc.name)
remoteirc.proto.kick(real_kicker, remotechan, real_target, args['text']) remoteirc.kick(real_kicker, remotechan, real_target, args['text'])
else: else:
# Kick originated from a server, or the kicker isn't in any # Kick originated from a server, or the kicker isn't in any
# common channels with the target relay network. # common channels with the target relay network.
rsid = get_remote_sid(remoteirc, irc) rsid = get_remote_sid(remoteirc, irc)
log.debug('(%s) relay.handle_kick: Kicking %s from channel %s via %s on behalf of %s/%s', irc.name, real_target, remotechan, rsid, kicker, irc.name) log.debug('(%s) relay.handle_kick: Kicking %s from channel %s via %s on behalf of %s/%s', irc.name, real_target, remotechan, rsid, kicker, irc.name)
if not irc.proto.hasCap('can-spawn-clients'): if not irc.hasCap('can-spawn-clients'):
# Special case for clientbot: no kick prefixes are needed. # Special case for clientbot: no kick prefixes are needed.
text = args['text'] text = args['text']
else: else:
@ -1260,16 +1260,16 @@ def handle_kick(irc, source, command, args):
except AttributeError: except AttributeError:
text = "(<unknown kicker>@%s) %s" % (irc.name, args['text']) text = "(<unknown kicker>@%s) %s" % (irc.name, args['text'])
rsid = rsid or remoteirc.sid # Fall back to the main PyLink SID if get_remote_sid() fails rsid = rsid or remoteirc.sid # Fall back to the main PyLink SID if get_remote_sid() fails
remoteirc.proto.kick(rsid, remotechan, real_target, text) remoteirc.kick(rsid, remotechan, real_target, text)
# If the target isn't on any channels, quit them. # If the target isn't on any channels, quit them.
if remoteirc != irc and (not remoteirc.users[real_target].channels) and not origuser: if remoteirc != irc and (not remoteirc.users[real_target].channels) and not origuser:
del relayusers[(irc.name, target)][remoteirc.name] del relayusers[(irc.name, target)][remoteirc.name]
remoteirc.proto.quit(real_target, 'Left all shared channels.') remoteirc.quit(real_target, 'Left all shared channels.')
if origuser and not irc.users[target].channels: if origuser and not irc.users[target].channels:
del relayusers[origuser][irc.name] del relayusers[origuser][irc.name]
irc.proto.quit(target, 'Left all shared channels.') irc.quit(target, 'Left all shared channels.')
utils.add_hook(handle_kick, 'KICK') utils.add_hook(handle_kick, 'KICK')
@ -1292,7 +1292,7 @@ def handle_chgclient(irc, source, command, args):
newtext = normalize_host(remoteirc, text) newtext = normalize_host(remoteirc, text)
else: # Don't overwrite the original text variable on every iteration. else: # Don't overwrite the original text variable on every iteration.
newtext = text newtext = text
remoteirc.proto.updateClient(user, field, newtext) remoteirc.updateClient(user, field, newtext)
except NotImplementedError: # IRCd doesn't support changing the field we want except NotImplementedError: # IRCd doesn't support changing the field we want
log.debug('(%s) relay.handle_chgclient: Ignoring changing field %r of %s on %s (for %s/%s);' log.debug('(%s) relay.handle_chgclient: Ignoring changing field %r of %s on %s (for %s/%s);'
' remote IRCd doesn\'t support it', irc.name, field, ' remote IRCd doesn\'t support it', irc.name, field,
@ -1322,17 +1322,17 @@ def handle_mode(irc, numeric, command, args):
# from the corresponding server. # from the corresponding server.
u = get_remote_user(irc, remoteirc, numeric, spawn_if_missing=False) u = get_remote_user(irc, remoteirc, numeric, spawn_if_missing=False)
if u: if u:
remoteirc.proto.mode(u, remotechan, supported_modes) remoteirc.mode(u, remotechan, supported_modes)
else: else:
rsid = get_remote_sid(remoteirc, irc) rsid = get_remote_sid(remoteirc, irc)
rsid = rsid or remoteirc.sid rsid = rsid or remoteirc.sid
remoteirc.proto.mode(rsid, remotechan, supported_modes) remoteirc.mode(rsid, remotechan, supported_modes)
else: # Mode change blocked by CLAIM. else: # Mode change blocked by CLAIM.
reversed_modes = irc.reverseModes(target, modes, oldobj=oldchan) reversed_modes = irc.reverseModes(target, modes, oldobj=oldchan)
log.debug('(%s) relay.handle_mode: Reversing mode changes of %r with %r (CLAIM).', log.debug('(%s) relay.handle_mode: Reversing mode changes of %r with %r (CLAIM).',
irc.name, modes, reversed_modes) irc.name, modes, reversed_modes)
if reversed_modes: if reversed_modes:
irc.proto.mode(irc.sid, target, reversed_modes) irc.mode(irc.sid, target, reversed_modes)
break break
else: else:
@ -1350,7 +1350,7 @@ def handle_mode(irc, numeric, command, args):
remoteuser = get_remote_user(irc, remoteirc, target, spawn_if_missing=False) remoteuser = get_remote_user(irc, remoteirc, target, spawn_if_missing=False)
if remoteuser and modes: if remoteuser and modes:
remoteirc.proto.mode(remoteuser, remoteuser, modes) remoteirc.mode(remoteuser, remoteuser, modes)
utils.add_hook(handle_mode, 'MODE') utils.add_hook(handle_mode, 'MODE')
@ -1370,12 +1370,12 @@ def handle_topic(irc, numeric, command, args):
# This might originate from a server too. # This might originate from a server too.
remoteuser = get_remote_user(irc, remoteirc, numeric, spawn_if_missing=False) remoteuser = get_remote_user(irc, remoteirc, numeric, spawn_if_missing=False)
if remoteuser: if remoteuser:
remoteirc.proto.topic(remoteuser, remotechan, topic) remoteirc.topic(remoteuser, remotechan, topic)
else: else:
rsid = get_remote_sid(remoteirc, irc) rsid = get_remote_sid(remoteirc, irc)
remoteirc.proto.topicBurst(rsid, remotechan, topic) remoteirc.topicBurst(rsid, remotechan, topic)
elif oldtopic: # Topic change blocked by claim. elif oldtopic: # Topic change blocked by claim.
irc.proto.topicBurst(irc.sid, channel, oldtopic) irc.topicBurst(irc.sid, channel, oldtopic)
utils.add_hook(handle_topic, 'TOPIC') utils.add_hook(handle_topic, 'TOPIC')
@ -1403,7 +1403,7 @@ def handle_kill(irc, numeric, command, args):
modes = get_prefix_modes(remoteirc, irc, remotechan, realuser[1]) modes = get_prefix_modes(remoteirc, irc, remotechan, realuser[1])
log.debug('(%s) relay.handle_kill: userpair: %s, %s', irc.name, modes, realuser) log.debug('(%s) relay.handle_kill: userpair: %s, %s', irc.name, modes, realuser)
client = get_remote_user(remoteirc, irc, realuser[1], times_tagged=1) client = get_remote_user(remoteirc, irc, realuser[1], times_tagged=1)
irc.proto.sjoin(get_remote_sid(irc, remoteirc), localchan, [(modes, client)]) irc.sjoin(get_remote_sid(irc, remoteirc), localchan, [(modes, client)])
if userdata and numeric in irc.users: if userdata and numeric in irc.users:
log.info('(%s) relay.handle_kill: Blocked KILL (reason %r) from %s to relay client %s/%s.', log.info('(%s) relay.handle_kill: Blocked KILL (reason %r) from %s to relay client %s/%s.',
@ -1432,7 +1432,7 @@ utils.add_hook(handle_kill, 'KILL')
def handle_away(irc, numeric, command, args): def handle_away(irc, numeric, command, args):
for netname, user in relayusers[(irc.name, numeric)].items(): for netname, user in relayusers[(irc.name, numeric)].items():
remoteirc = world.networkobjects[netname] remoteirc = world.networkobjects[netname]
remoteirc.proto.away(user, args['text']) remoteirc.away(user, args['text'])
utils.add_hook(handle_away, 'AWAY') utils.add_hook(handle_away, 'AWAY')
def handle_invite(irc, source, command, args): def handle_invite(irc, source, command, args):
@ -1453,7 +1453,7 @@ def handle_invite(irc, source, command, args):
'channel not on their network!', 'channel not on their network!',
notice=True) notice=True)
else: else:
remoteirc.proto.invite(remotesource, remoteuser, remoteirc.invite(remotesource, remoteuser,
remotechan) remotechan)
utils.add_hook(handle_invite, 'INVITE') utils.add_hook(handle_invite, 'INVITE')
@ -1540,7 +1540,7 @@ def nick_collide(irc, target):
newnick = normalize_nick(irc, remotenet, nick, times_tagged=1) newnick = normalize_nick(irc, remotenet, nick, times_tagged=1)
log.debug('(%s) relay.nick_collide: Fixing nick of relay client %r (%s) to %s', log.debug('(%s) relay.nick_collide: Fixing nick of relay client %r (%s) to %s',
irc.name, target, nick, newnick) irc.name, target, nick, newnick)
irc.proto.nick(target, newnick) irc.nick(target, newnick)
def handle_save(irc, numeric, command, args): def handle_save(irc, numeric, command, args):
target = args['target'] target = args['target']
@ -1582,7 +1582,7 @@ def create(irc, source, args):
if not utils.isChannel(channel): if not utils.isChannel(channel):
irc.error('Invalid channel %r.' % channel) irc.error('Invalid channel %r.' % channel)
return return
if not irc.proto.hasCap('can-host-relay'): if not irc.hasCap('can-host-relay'):
irc.error('Clientbot networks cannot be used to host a relay.') irc.error('Clientbot networks cannot be used to host a relay.')
return return
if source not in irc.channels[channel].users: if source not in irc.channels[channel].users:
@ -1723,7 +1723,7 @@ def link(irc, source, args):
# Special case for Clientbot: join the requested channel first, then # Special case for Clientbot: join the requested channel first, then
# require that the caller be opped. # require that the caller be opped.
if localchan not in irc.pseudoclient.channels: if localchan not in irc.pseudoclient.channels:
irc.proto.join(irc.pseudoclient.uid, localchan) irc.join(irc.pseudoclient.uid, localchan)
irc.reply('Joining %r now to check for op status; please run this command again after I join.' % localchan) irc.reply('Joining %r now to check for op status; please run this command again after I join.' % localchan)
return return
elif not irc.channels[localchan].isOpPlus(source): elif not irc.channels[localchan].isOpPlus(source):
@ -1774,7 +1774,7 @@ def link(irc, source, args):
our_ts = irc.channels[localchan].ts our_ts = irc.channels[localchan].ts
their_ts = world.networkobjects[remotenet].channels[channel].ts their_ts = world.networkobjects[remotenet].channels[channel].ts
if (our_ts < their_ts) and irc.proto.hasCap('has-ts'): if (our_ts < their_ts) and irc.hasCap('has-ts'):
log.debug('(%s) relay: Blocking link request %s%s -> %s%s due to bad TS (%s < %s)', irc.name, log.debug('(%s) relay: Blocking link request %s%s -> %s%s due to bad TS (%s < %s)', irc.name,
irc.name, localchan, remotenet, args.channel, our_ts, their_ts) irc.name, localchan, remotenet, args.channel, our_ts, their_ts)
irc.error("The channel creation date (TS) on %s (%s) is lower than the target " irc.error("The channel creation date (TS) on %s (%s) is lower than the target "

View File

@ -204,7 +204,7 @@ def rpm(irc, source, args):
return return
relay = world.plugins.get('relay') relay = world.plugins.get('relay')
if irc.proto.hasCap('can-spawn-clients'): if irc.hasCap('can-spawn-clients'):
irc.error('This command is only supported on Clientbot networks. Try /msg %s <text>' % target) irc.error('This command is only supported on Clientbot networks. Try /msg %s <text>' % target)
return return
elif relay is None: elif relay is None:

View File

@ -78,7 +78,7 @@ def _map(irc, source, args, show_relay=True):
# This is a relay server - display the remote map of the network it represents # This is a relay server - display the remote map of the network it represents
relay_server = serverlist[leaf].remote relay_server = serverlist[leaf].remote
remoteirc = world.networkobjects[relay_server] remoteirc = world.networkobjects[relay_server]
if remoteirc.proto.hasCap('can-track-servers'): if remoteirc.hasCap('can-track-servers'):
# Only ever show relay subservers once - this prevents infinite loops. # Only ever show relay subservers once - this prevents infinite loops.
showall(remoteirc, remoteirc.sid, hops=hops, is_relay_server=True) showall(remoteirc, remoteirc.sid, hops=hops, is_relay_server=True)