2015-12-26 23:45:28 +01:00
|
|
|
"""
|
|
|
|
inspircd.py: InspIRCd 2.x protocol module for PyLink.
|
|
|
|
"""
|
|
|
|
|
2015-03-20 00:21:49 +01:00
|
|
|
import time
|
2015-04-18 07:11:49 +02:00
|
|
|
import sys
|
2015-06-17 05:05:41 +02:00
|
|
|
import os
|
2015-07-05 22:22:17 +02:00
|
|
|
import re
|
2015-12-18 06:18:11 +01:00
|
|
|
import threading
|
2015-07-05 22:22:17 +02:00
|
|
|
|
2015-09-05 23:25:11 +02:00
|
|
|
# Import hacks to access utils and classes...
|
2015-09-03 21:57:57 +02:00
|
|
|
curdir = os.path.dirname(__file__)
|
|
|
|
sys.path += [curdir, os.path.dirname(curdir)]
|
2015-06-21 05:36:35 +02:00
|
|
|
import utils
|
2015-07-05 22:22:17 +02:00
|
|
|
from log import log
|
2015-06-07 07:17:45 +02:00
|
|
|
from classes import *
|
2015-04-04 03:45:18 +02:00
|
|
|
|
2016-04-25 06:08:07 +02:00
|
|
|
from ts6_common import *
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
class InspIRCdProtocol(TS6BaseProtocol):
|
|
|
|
def __init__(self, irc):
|
2016-04-06 03:37:09 +02:00
|
|
|
super().__init__(irc)
|
2015-09-25 03:36:54 +02:00
|
|
|
# Set our case mapping (rfc1459 maps "\" and "|" together, for example).
|
2015-09-06 03:00:57 +02:00
|
|
|
self.casemapping = 'rfc1459'
|
|
|
|
|
|
|
|
# Raw commands sent from servers vary from protocol to protocol. Here, we map
|
|
|
|
# non-standard names to our hook handlers, so command handlers' outputs
|
|
|
|
# are called with the right hooks.
|
|
|
|
self.hook_map = {'FJOIN': 'JOIN', 'RSQUIT': 'SQUIT', 'FMODE': 'MODE',
|
|
|
|
'FTOPIC': 'TOPIC', 'OPERTYPE': 'MODE', 'FHOST': 'CHGHOST',
|
2015-11-01 03:15:03 +01:00
|
|
|
'FIDENT': 'CHGIDENT', 'FNAME': 'CHGNAME', 'SVSTOPIC': 'TOPIC'}
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2016-03-27 00:23:22 +01:00
|
|
|
self.min_proto_ver = 1202
|
|
|
|
self.proto_ver = 1202
|
2016-03-27 03:19:19 +02:00
|
|
|
self.max_proto_ver = 1202 # Anything above should warn (not officially supported)
|
2016-03-27 00:23:22 +01:00
|
|
|
|
2016-01-18 06:02:30 +01:00
|
|
|
### Outgoing commands
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
def spawnClient(self, nick, ident='null', host='null', realhost=None, modes=set(),
|
2016-03-26 20:55:23 +01:00
|
|
|
server=None, ip='0.0.0.0', realname=None, ts=None, opertype='IRC Operator',
|
2015-09-18 04:01:54 +02:00
|
|
|
manipulatable=False):
|
2015-09-06 03:00:57 +02:00
|
|
|
"""Spawns a client with nick <nick> on the given IRC connection.
|
|
|
|
|
|
|
|
Note: No nick collision / valid nickname checks are done here; it is
|
|
|
|
up to plugins to make sure they don't introduce anything invalid."""
|
|
|
|
server = server or self.irc.sid
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalServer(server):
|
2016-01-10 02:44:05 +01:00
|
|
|
raise ValueError('Server %r is not a PyLink server!' % server)
|
2015-09-13 01:02:51 +02:00
|
|
|
# Create an UIDGenerator instance for every SID, so that each gets
|
|
|
|
# distinct values.
|
2016-04-25 06:08:07 +02:00
|
|
|
uid = self.uidgen.setdefault(server, TS6UIDGenerator(server)).next_uid()
|
2015-09-06 03:00:57 +02:00
|
|
|
ts = ts or int(time.time())
|
|
|
|
realname = realname or self.irc.botdata['realname']
|
|
|
|
realhost = realhost or host
|
|
|
|
raw_modes = utils.joinModes(modes)
|
|
|
|
u = self.irc.users[uid] = IrcUser(nick, ts, uid, ident=ident, host=host, realname=realname,
|
2016-03-26 20:55:23 +01:00
|
|
|
realhost=realhost, ip=ip, manipulatable=manipulatable, opertype=opertype)
|
2015-09-06 03:00:57 +02:00
|
|
|
utils.applyModes(self.irc, uid, modes)
|
|
|
|
self.irc.servers[server].users.add(uid)
|
|
|
|
self._send(server, "UID {uid} {ts} {nick} {realhost} {host} {ident} {ip}"
|
|
|
|
" {ts} {modes} + :{realname}".format(ts=ts, host=host,
|
|
|
|
nick=nick, ident=ident, uid=uid,
|
|
|
|
modes=raw_modes, ip=ip, realname=realname,
|
|
|
|
realhost=realhost))
|
|
|
|
if ('o', None) in modes or ('+o', None) in modes:
|
2016-03-26 20:55:23 +01:00
|
|
|
self._operUp(uid, opertype)
|
2015-09-06 03:00:57 +02:00
|
|
|
return u
|
|
|
|
|
2016-01-17 01:36:45 +01:00
|
|
|
def join(self, client, channel):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Joins a PyLink client to a channel."""
|
2015-09-06 03:00:57 +02:00
|
|
|
# InspIRCd doesn't distinguish between burst joins and regular joins,
|
|
|
|
# so what we're actually doing here is sending FJOIN from the server,
|
|
|
|
# on behalf of the clients that are joining.
|
|
|
|
channel = utils.toLower(self.irc, channel)
|
2016-01-01 02:28:47 +01:00
|
|
|
server = self.irc.isInternalClient(client)
|
2015-09-06 03:00:57 +02:00
|
|
|
if not server:
|
2016-01-10 02:44:05 +01:00
|
|
|
log.error('(%s) Error trying to join %r to %r (no such client exists)', self.irc.name, client, channel)
|
|
|
|
raise LookupError('No such PyLink client exists.')
|
2015-09-06 03:00:57 +02:00
|
|
|
# Strip out list-modes, they shouldn't be ever sent in FJOIN.
|
|
|
|
modes = [m for m in self.irc.channels[channel].modes if m[0] not in self.irc.cmodes['*A']]
|
|
|
|
self._send(server, "FJOIN {channel} {ts} {modes} :,{uid}".format(
|
|
|
|
ts=self.irc.channels[channel].ts, uid=client, channel=channel,
|
|
|
|
modes=utils.joinModes(modes)))
|
|
|
|
self.irc.channels[channel].users.add(client)
|
|
|
|
self.irc.users[client].channels.add(channel)
|
|
|
|
|
2016-01-17 01:53:46 +01:00
|
|
|
def sjoin(self, server, channel, users, ts=None):
|
2015-09-06 03:00:57 +02:00
|
|
|
"""Sends an SJOIN for a group of users to a channel.
|
|
|
|
|
|
|
|
The sender should always be a Server ID (SID). TS is optional, and defaults
|
|
|
|
to the one we've stored in the channel state if not given.
|
|
|
|
<users> is a list of (prefix mode, UID) pairs:
|
|
|
|
|
|
|
|
Example uses:
|
2016-01-17 01:53:46 +01:00
|
|
|
sjoin('100', '#test', [('', '100AAABBC'), ('qo', 100AAABBB'), ('h', '100AAADDD')])
|
|
|
|
sjoin(self.irc.sid, '#test', [('o', self.irc.pseudoclient.uid)])
|
2015-09-06 03:00:57 +02:00
|
|
|
"""
|
|
|
|
channel = utils.toLower(self.irc, channel)
|
|
|
|
server = server or self.irc.sid
|
2016-01-17 01:53:46 +01:00
|
|
|
assert users, "sjoin: No users sent?"
|
|
|
|
log.debug('(%s) sjoin: got %r for users', self.irc.name, users)
|
2015-09-06 03:00:57 +02:00
|
|
|
if not server:
|
2016-01-10 02:44:05 +01:00
|
|
|
raise LookupError('No such PyLink client exists.')
|
2015-11-08 19:49:09 +01:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
orig_ts = self.irc.channels[channel].ts
|
2015-11-09 00:14:03 +01:00
|
|
|
ts = ts or orig_ts
|
|
|
|
self.updateTS(channel, ts)
|
2015-11-08 19:49:09 +01:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
log.debug("sending SJOIN to %s%s with ts %s (that's %r)", channel, self.irc.name, ts,
|
|
|
|
time.strftime("%c", time.localtime(ts)))
|
|
|
|
# Strip out list-modes, they shouldn't ever be sent in FJOIN (protocol rules).
|
|
|
|
modes = [m for m in self.irc.channels[channel].modes if m[0] not in self.irc.cmodes['*A']]
|
|
|
|
uids = []
|
|
|
|
changedmodes = []
|
|
|
|
namelist = []
|
|
|
|
# We take <users> as a list of (prefixmodes, uid) pairs.
|
|
|
|
for userpair in users:
|
|
|
|
assert len(userpair) == 2, "Incorrect format of userpair: %r" % userpair
|
|
|
|
prefixes, user = userpair
|
|
|
|
namelist.append(','.join(userpair))
|
|
|
|
uids.append(user)
|
|
|
|
for m in prefixes:
|
|
|
|
changedmodes.append(('+%s' % m, user))
|
|
|
|
try:
|
|
|
|
self.irc.users[user].channels.add(channel)
|
|
|
|
except KeyError: # Not initialized yet?
|
2016-01-17 01:53:46 +01:00
|
|
|
log.debug("(%s) sjoin: KeyError trying to add %r to %r's channel list?", self.irc.name, channel, user)
|
2015-09-06 03:00:57 +02:00
|
|
|
if ts <= orig_ts:
|
|
|
|
# Only save our prefix modes in the channel state if our TS is lower than or equal to theirs.
|
|
|
|
utils.applyModes(self.irc, channel, changedmodes)
|
|
|
|
namelist = ' '.join(namelist)
|
|
|
|
self._send(server, "FJOIN {channel} {ts} {modes} :{users}".format(
|
|
|
|
ts=ts, users=namelist, channel=channel,
|
|
|
|
modes=utils.joinModes(modes)))
|
|
|
|
self.irc.channels[channel].users.update(uids)
|
|
|
|
|
|
|
|
def _operUp(self, target, opertype=None):
|
|
|
|
"""Opers a client up (internal function specific to InspIRCd).
|
|
|
|
|
|
|
|
This should be called whenever user mode +o is set on anyone, because
|
|
|
|
InspIRCd requires a special command (OPERTYPE) to be sent in order to
|
|
|
|
recognize ANY non-burst oper ups.
|
|
|
|
|
|
|
|
Plugins don't have to call this function themselves, but they can
|
|
|
|
set the opertype attribute of an IrcUser object (in self.irc.users),
|
|
|
|
and the change will be reflected here."""
|
|
|
|
userobj = self.irc.users[target]
|
2015-07-20 08:45:52 +02:00
|
|
|
try:
|
2015-09-20 20:25:45 +02:00
|
|
|
otype = opertype or userobj.opertype or 'IRC Operator'
|
2015-09-06 03:00:57 +02:00
|
|
|
except AttributeError:
|
|
|
|
log.debug('(%s) opertype field for %s (%s) isn\'t filled yet!',
|
|
|
|
self.irc.name, target, userobj.nick)
|
|
|
|
# whatever, this is non-standard anyways.
|
2015-09-20 20:25:45 +02:00
|
|
|
otype = 'IRC Operator'
|
2015-09-15 01:55:35 +02:00
|
|
|
assert otype, "Tried to send an empty OPERTYPE!"
|
2015-09-06 03:00:57 +02:00
|
|
|
log.debug('(%s) Sending OPERTYPE from %s to oper them up.',
|
|
|
|
self.irc.name, target)
|
|
|
|
userobj.opertype = otype
|
2015-09-20 20:25:45 +02:00
|
|
|
self._send(target, 'OPERTYPE %s' % otype.replace(" ", "_"))
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2016-01-17 02:08:17 +01:00
|
|
|
def mode(self, numeric, target, modes, ts=None):
|
|
|
|
"""Sends mode changes from a PyLink client/server."""
|
2015-09-06 03:00:57 +02:00
|
|
|
# -> :9PYAAAAAA FMODE #pylink 1433653951 +os 9PYAAAAAA
|
|
|
|
# -> :9PYAAAAAA MODE 9PYAAAAAA -i+w
|
2016-01-17 02:08:17 +01:00
|
|
|
|
|
|
|
if (not self.irc.isInternalClient(numeric)) and \
|
|
|
|
(not self.irc.isInternalServer(numeric)):
|
|
|
|
raise LookupError('No such PyLink client/server exists.')
|
|
|
|
|
2015-09-13 08:35:20 +02:00
|
|
|
log.debug('(%s) inspircd._sendModes: received %r for mode list', self.irc.name, modes)
|
2015-09-06 03:00:57 +02:00
|
|
|
if ('+o', None) in modes and not utils.isChannel(target):
|
2015-12-18 06:19:40 +01:00
|
|
|
# https://github.com/inspircd/inspircd/blob/master/src/modules/m_spanningtree/opertype.cpp#L26-L28
|
2015-09-06 03:00:57 +02:00
|
|
|
# Servers need a special command to set umode +o on people.
|
|
|
|
self._operUp(target)
|
|
|
|
utils.applyModes(self.irc, target, modes)
|
|
|
|
joinedmodes = utils.joinModes(modes)
|
|
|
|
if utils.isChannel(target):
|
|
|
|
ts = ts or self.irc.channels[utils.toLower(self.irc, target)].ts
|
|
|
|
self._send(numeric, 'FMODE %s %s %s' % (target, ts, joinedmodes))
|
|
|
|
else:
|
|
|
|
self._send(numeric, 'MODE %s %s' % (target, joinedmodes))
|
|
|
|
|
2016-01-17 02:03:22 +01:00
|
|
|
def kill(self, numeric, target, reason):
|
|
|
|
"""Sends a kill from a PyLink client/server."""
|
|
|
|
if (not self.irc.isInternalClient(numeric)) and \
|
|
|
|
(not self.irc.isInternalServer(numeric)):
|
|
|
|
raise LookupError('No such PyLink client/server exists.')
|
|
|
|
|
2016-02-26 06:11:42 +01:00
|
|
|
# InspIRCd will show the raw kill message sent from our server as the quit message.
|
|
|
|
# So, make the kill look actually like a kill instead of someone quitting with
|
|
|
|
# an arbitrary message.
|
|
|
|
if target in self.irc.servers:
|
|
|
|
sourcenick = self.irc.servers[numeric].name
|
|
|
|
else:
|
|
|
|
sourcenick = self.irc.users[numeric].nick
|
|
|
|
|
|
|
|
self._send(numeric, 'KILL %s :Killed (%s (%s))' % (target, sourcenick, reason))
|
2016-01-17 02:03:22 +01:00
|
|
|
|
2015-10-09 05:12:52 +02:00
|
|
|
# We only need to call removeClient here if the target is one of our
|
|
|
|
# clients, since any remote servers will send a QUIT from
|
|
|
|
# their target if the command succeeds.
|
2016-01-01 02:28:47 +01:00
|
|
|
if self.irc.isInternalClient(target):
|
2015-10-09 05:12:52 +02:00
|
|
|
self.removeClient(target)
|
|
|
|
|
2016-01-17 02:09:52 +01:00
|
|
|
def topicBurst(self, numeric, target, text):
|
2015-09-25 03:36:54 +02:00
|
|
|
"""Sends a topic change from a PyLink server. This is usually used on burst."""
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalServer(numeric):
|
2016-01-10 02:44:05 +01:00
|
|
|
raise LookupError('No such PyLink server exists.')
|
2015-09-06 03:00:57 +02:00
|
|
|
ts = int(time.time())
|
|
|
|
servername = self.irc.servers[numeric].name
|
|
|
|
self._send(numeric, 'FTOPIC %s %s %s :%s' % (target, ts, servername, text))
|
|
|
|
self.irc.channels[target].topic = text
|
|
|
|
self.irc.channels[target].topicset = True
|
|
|
|
|
2016-01-17 01:38:27 +01:00
|
|
|
def invite(self, numeric, target, channel):
|
2015-09-06 03:00:57 +02:00
|
|
|
"""Sends an INVITE from a PyLink client.."""
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalClient(numeric):
|
2016-01-10 02:44:05 +01:00
|
|
|
raise LookupError('No such PyLink client exists.')
|
2015-09-06 03:00:57 +02:00
|
|
|
self._send(numeric, 'INVITE %s %s' % (target, channel))
|
|
|
|
|
2016-01-17 01:41:17 +01:00
|
|
|
def knock(self, numeric, target, text):
|
2015-09-06 03:00:57 +02:00
|
|
|
"""Sends a KNOCK from a PyLink client."""
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalClient(numeric):
|
2016-01-10 02:44:05 +01:00
|
|
|
raise LookupError('No such PyLink client exists.')
|
2015-09-06 03:00:57 +02:00
|
|
|
self._send(numeric, 'ENCAP * KNOCK %s :%s' % (target, text))
|
|
|
|
|
2015-12-31 00:54:09 +01:00
|
|
|
def updateClient(self, target, field, text):
|
|
|
|
"""Updates the ident, host, or realname of any connected client."""
|
2015-09-06 03:00:57 +02:00
|
|
|
field = field.upper()
|
2015-12-31 00:54:09 +01:00
|
|
|
|
|
|
|
if field not in ('IDENT', 'HOST', 'REALNAME', 'GECOS'):
|
|
|
|
raise NotImplementedError("Changing field %r of a client is "
|
|
|
|
"unsupported by this protocol." % field)
|
|
|
|
|
2016-01-01 02:28:47 +01:00
|
|
|
if self.irc.isInternalClient(target):
|
2015-12-31 00:54:09 +01:00
|
|
|
# It is one of our clients, use FIDENT/HOST/NAME.
|
|
|
|
if field == 'IDENT':
|
|
|
|
self.irc.users[target].ident = text
|
|
|
|
self._send(target, 'FIDENT %s' % text)
|
|
|
|
elif field == 'HOST':
|
|
|
|
self.irc.users[target].host = text
|
|
|
|
self._send(target, 'FHOST %s' % text)
|
|
|
|
elif field in ('REALNAME', 'GECOS'):
|
|
|
|
self.irc.users[target].realname = text
|
|
|
|
self._send(target, 'FNAME :%s' % text)
|
2015-09-06 03:00:57 +02:00
|
|
|
else:
|
2015-12-31 00:54:09 +01:00
|
|
|
# It is a client on another server, use CHGIDENT/HOST/NAME.
|
|
|
|
if field == 'IDENT':
|
|
|
|
self.irc.users[target].ident = text
|
|
|
|
self._send(self.irc.sid, 'CHGIDENT %s %s' % (target, text))
|
|
|
|
|
|
|
|
# Send hook payloads for other plugins to listen to.
|
|
|
|
self.irc.callHooks([self.irc.sid, 'CHGIDENT',
|
|
|
|
{'target': target, 'newident': text}])
|
|
|
|
elif field == 'HOST':
|
|
|
|
self.irc.users[target].host = text
|
|
|
|
self._send(self.irc.sid, 'CHGHOST %s %s' % (target, text))
|
|
|
|
|
|
|
|
self.irc.callHooks([self.irc.sid, 'CHGHOST',
|
|
|
|
{'target': target, 'newhost': text}])
|
|
|
|
|
|
|
|
elif field in ('REALNAME', 'GECOS'):
|
|
|
|
self.irc.users[target].realname = text
|
|
|
|
self._send(self.irc.sid, 'CHGNAME %s :%s' % (target, text))
|
|
|
|
|
|
|
|
self.irc.callHooks([self.irc.sid, 'CHGNAME',
|
|
|
|
{'target': target, 'newgecos': text}])
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2016-01-17 02:11:23 +01:00
|
|
|
def ping(self, source=None, target=None):
|
2015-09-06 03:00:57 +02:00
|
|
|
"""Sends a PING to a target server. Periodic PINGs are sent to our uplink
|
|
|
|
automatically by the Irc() internals; plugins shouldn't have to use this."""
|
|
|
|
source = source or self.irc.sid
|
|
|
|
target = target or self.irc.uplink
|
|
|
|
if not (target is None or source is None):
|
|
|
|
self._send(source, 'PING %s %s' % (source, target))
|
|
|
|
|
2016-01-17 01:47:35 +01:00
|
|
|
def numeric(self, source, numeric, target, text):
|
2015-09-06 03:00:57 +02:00
|
|
|
raise NotImplementedError("Numeric sending is not yet implemented by this "
|
|
|
|
"protocol module. WHOIS requests are handled "
|
|
|
|
"locally by InspIRCd servers, so there is no "
|
|
|
|
"need for PyLink to send numerics directly yet.")
|
|
|
|
|
2016-01-17 01:40:36 +01:00
|
|
|
def away(self, source, text):
|
2015-09-06 03:00:57 +02:00
|
|
|
"""Sends an AWAY message from a PyLink client. <text> can be an empty string
|
|
|
|
to unset AWAY status."""
|
|
|
|
if text:
|
|
|
|
self._send(source, 'AWAY %s :%s' % (int(time.time()), text))
|
|
|
|
else:
|
|
|
|
self._send(source, 'AWAY')
|
2015-12-18 06:50:50 +01:00
|
|
|
self.irc.users[source].away = text
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2015-12-18 06:18:11 +01:00
|
|
|
def spawnServer(self, name, sid=None, uplink=None, desc=None, endburst_delay=0):
|
2015-09-25 03:36:54 +02:00
|
|
|
"""
|
|
|
|
Spawns a server off a PyLink server. desc (server description)
|
|
|
|
defaults to the one in the config. uplink defaults to the main PyLink
|
|
|
|
server, and sid (the server ID) is automatically generated if not
|
|
|
|
given.
|
2015-12-18 06:18:11 +01:00
|
|
|
|
|
|
|
If endburst_delay is set greater than zero, the sending of ENDBURST
|
|
|
|
will be delayed by the amount given. This can be used to prevent
|
|
|
|
pseudoserver bursts from triggering IRCd join-flood preventions,
|
|
|
|
and prevent connections from filling up the snomasks too much.
|
2015-09-25 03:36:54 +02:00
|
|
|
"""
|
2015-09-06 03:00:57 +02:00
|
|
|
# -> :0AL SERVER test.server * 1 0AM :some silly pseudoserver
|
|
|
|
uplink = uplink or self.irc.sid
|
|
|
|
name = name.lower()
|
|
|
|
# "desc" defaults to the configured server description.
|
|
|
|
desc = desc or self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc']
|
|
|
|
if sid is None: # No sid given; generate one!
|
2015-09-12 21:05:53 +02:00
|
|
|
sid = self.sidgen.next_sid()
|
2015-09-06 03:00:57 +02:00
|
|
|
assert len(sid) == 3, "Incorrect SID length"
|
|
|
|
if sid in self.irc.servers:
|
|
|
|
raise ValueError('A server with SID %r already exists!' % sid)
|
|
|
|
for server in self.irc.servers.values():
|
|
|
|
if name == server.name:
|
|
|
|
raise ValueError('A server named %r already exists!' % name)
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalServer(uplink):
|
2016-01-10 02:44:05 +01:00
|
|
|
raise ValueError('Server %r is not a PyLink server!' % uplink)
|
2015-09-06 03:00:57 +02:00
|
|
|
if not utils.isServerName(name):
|
|
|
|
raise ValueError('Invalid server name %r' % name)
|
|
|
|
self._send(uplink, 'SERVER %s * 1 %s :%s' % (name, sid, desc))
|
2015-09-12 19:39:05 +02:00
|
|
|
self.irc.servers[sid] = IrcServer(uplink, name, internal=True, desc=desc)
|
2015-12-18 06:18:11 +01:00
|
|
|
|
|
|
|
endburstf = lambda: self._send(sid, 'ENDBURST')
|
|
|
|
if endburst_delay:
|
|
|
|
# Delay ENDBURST by X seconds if requested.
|
|
|
|
threading.Timer(endburst_delay, endburstf, ()).start()
|
|
|
|
else: # Else, send burst immediately
|
|
|
|
endburstf()
|
2015-09-06 03:00:57 +02:00
|
|
|
return sid
|
|
|
|
|
2016-01-17 01:53:06 +01:00
|
|
|
def squit(self, source, target, text='No reason given'):
|
2015-09-06 03:00:57 +02:00
|
|
|
"""SQUITs a PyLink server."""
|
|
|
|
# -> :9PY SQUIT 9PZ :blah, blah
|
|
|
|
self._send(source, 'SQUIT %s :%s' % (target, text))
|
|
|
|
self.handle_squit(source, 'SQUIT', [target, text])
|
|
|
|
|
2016-01-18 06:02:30 +01:00
|
|
|
### Core / command handlers
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
def connect(self):
|
|
|
|
"""Initializes a connection to a server."""
|
|
|
|
ts = self.irc.start_ts
|
|
|
|
|
|
|
|
f = self.irc.send
|
2016-03-27 00:23:22 +01:00
|
|
|
f('CAPAB START %s' % self.proto_ver)
|
|
|
|
f('CAPAB CAPABILITIES :PROTOCOL=%s' % self.proto_ver)
|
2015-09-06 03:00:57 +02:00
|
|
|
f('CAPAB END')
|
2016-03-26 19:35:29 +01:00
|
|
|
|
|
|
|
host = self.irc.serverdata["hostname"]
|
|
|
|
f('SERVER {host} {Pass} 0 {sid} :{sdesc}'.format(host=host,
|
2015-09-06 03:00:57 +02:00
|
|
|
Pass=self.irc.serverdata["sendpass"], sid=self.irc.sid,
|
|
|
|
sdesc=self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc']))
|
2016-03-26 19:35:29 +01:00
|
|
|
|
|
|
|
self._send(self.irc.sid, 'BURST %s' % ts)
|
|
|
|
# InspIRCd sends VERSION data on link, instead of whenever requested by a client.
|
|
|
|
self._send(self.irc.sid, 'VERSION :%s' % utils.fullVersion(self.irc))
|
|
|
|
self._send(self.irc.sid, 'ENDBURST')
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2016-01-18 06:02:30 +01:00
|
|
|
def handle_capab(self, source, command, args):
|
|
|
|
"""
|
|
|
|
Handles the CAPAB command, used for capability negotiation with our
|
|
|
|
uplink.
|
|
|
|
"""
|
|
|
|
# 6 CAPAB commands are usually sent on connect: CAPAB START, MODULES,
|
|
|
|
# MODSUPPORT, CHANMODES, USERMODES, and CAPABILITIES.
|
|
|
|
# The only ones of interest to us are CHANMODES, USERMODES, and
|
|
|
|
# CAPABILITIES.
|
|
|
|
|
|
|
|
if args[0] == 'CHANMODES':
|
|
|
|
# <- CAPAB CHANMODES :admin=&a allowinvite=A autoop=w ban=b
|
|
|
|
# banexception=e blockcolor=c c_registered=r exemptchanops=X
|
|
|
|
# filter=g flood=f halfop=%h history=H invex=I inviteonly=i
|
|
|
|
# joinflood=j key=k kicknorejoin=J limit=l moderated=m nickflood=F
|
|
|
|
# noctcp=C noextmsg=n nokick=Q noknock=K nonick=N nonotice=T
|
|
|
|
# official-join=!Y op=@o operonly=O opmoderated=U owner=~q
|
|
|
|
# permanent=P private=p redirect=L reginvite=R regmoderated=M
|
|
|
|
# secret=s sslonly=z stripcolor=S topiclock=t voice=+v
|
|
|
|
|
|
|
|
# Named modes are essential for a cross-protocol IRC service. We
|
|
|
|
# can use InspIRCd as a model here and assign a similar mode map to
|
|
|
|
# our cmodes list.
|
|
|
|
for modepair in args[-1].split():
|
|
|
|
name, char = modepair.split('=')
|
|
|
|
|
|
|
|
if name == 'reginvite': # Reginvite? That's a dumb name.
|
|
|
|
name = 'regonly'
|
|
|
|
|
|
|
|
if name == 'founder': # Channel mode +q
|
|
|
|
# Founder, owner; same thing. m_customprefix allows you to
|
|
|
|
# name it anything you like. The former is config default,
|
|
|
|
# but I personally prefer the latter.
|
|
|
|
name = 'owner'
|
2016-04-25 06:08:07 +02:00
|
|
|
|
2016-04-10 03:25:17 +02:00
|
|
|
if name == 'c_registered':
|
|
|
|
# Be consistent with other protocols
|
|
|
|
name = 'registered'
|
2016-01-18 06:02:30 +01:00
|
|
|
|
2016-04-10 03:25:17 +02:00
|
|
|
# We don't care about mode prefixes; just the mode char.
|
2016-01-18 06:02:30 +01:00
|
|
|
self.irc.cmodes[name] = char[-1]
|
|
|
|
|
|
|
|
|
|
|
|
elif args[0] == 'USERMODES':
|
|
|
|
# <- CAPAB USERMODES :bot=B callerid=g cloak=x deaf_commonchan=c
|
|
|
|
# helpop=h hidechans=I hideoper=H invisible=i oper=o regdeaf=R
|
|
|
|
# servprotect=k showwhois=W snomask=s u_registered=r u_stripcolor=S
|
|
|
|
# wallops=w
|
|
|
|
|
|
|
|
# Ditto above.
|
|
|
|
for modepair in args[-1].split():
|
|
|
|
name, char = modepair.split('=')
|
|
|
|
self.irc.umodes[name] = char
|
|
|
|
|
|
|
|
elif args[0] == 'CAPABILITIES':
|
|
|
|
# <- CAPAB CAPABILITIES :NICKMAX=21 CHANMAX=64 MAXMODES=20
|
|
|
|
# IDENTMAX=11 MAXQUIT=255 MAXTOPIC=307 MAXKICK=255 MAXGECOS=128
|
|
|
|
# MAXAWAY=200 IP6SUPPORT=1 PROTOCOL=1202 PREFIX=(Yqaohv)!~&@%+
|
|
|
|
# CHANMODES=IXbegw,k,FHJLfjl,ACKMNOPQRSTUcimnprstz
|
|
|
|
# USERMODES=,,s,BHIRSWcghikorwx GLOBOPS=1 SVSPART=1
|
|
|
|
|
|
|
|
# First, turn the arguments into a dict
|
|
|
|
caps = dict([x.split('=') for x in args[-1].split()])
|
|
|
|
|
|
|
|
|
|
|
|
# Check the protocol version
|
|
|
|
protocol_version = int(caps['PROTOCOL'])
|
2016-03-27 00:23:22 +01:00
|
|
|
if protocol_version < self.min_proto_ver:
|
2016-01-18 06:02:30 +01:00
|
|
|
raise ProtocolError("Remote protocol version is too old! "
|
2016-03-27 00:23:22 +01:00
|
|
|
"At least %s (InspIRCd 2.0.x) is "
|
|
|
|
"needed. (got %s)" % (self.min_proto_ver,
|
|
|
|
protocol_version))
|
2016-03-27 03:19:19 +02:00
|
|
|
elif protocol_version > self.max_proto_ver:
|
|
|
|
log.warning("(%s) PyLink support for InspIRCd 2.2+ is experimental, "
|
|
|
|
"and should not be relied upon for anything major.",
|
|
|
|
self.irc.name)
|
2016-01-18 06:02:30 +01:00
|
|
|
|
|
|
|
# Store the max nick and channel lengths
|
|
|
|
self.irc.maxnicklen = int(caps['NICKMAX'])
|
|
|
|
self.irc.maxchanlen = int(caps['CHANMAX'])
|
|
|
|
|
|
|
|
# Modes are divided into A, B, C, and D classes
|
|
|
|
# See http://www.irc.org/tech_docs/005.html
|
|
|
|
|
|
|
|
# FIXME: Find a neater way to assign/store this.
|
|
|
|
self.irc.cmodes['*A'], self.irc.cmodes['*B'], self.irc.cmodes['*C'], self.irc.cmodes['*D'] \
|
|
|
|
= caps['CHANMODES'].split(',')
|
|
|
|
self.irc.umodes['*A'], self.irc.umodes['*B'], self.irc.umodes['*C'], self.irc.umodes['*D'] \
|
|
|
|
= caps['USERMODES'].split(',')
|
|
|
|
|
|
|
|
# Separate the prefixes field (e.g. "(Yqaohv)!~&@%+") into a
|
|
|
|
# dict mapping mode characters to mode prefixes.
|
|
|
|
prefixsearch = re.search(r'\(([A-Za-z]+)\)(.*)', caps['PREFIX'])
|
|
|
|
self.irc.prefixmodes = dict(zip(prefixsearch.group(1),
|
|
|
|
prefixsearch.group(2)))
|
|
|
|
log.debug('(%s) self.irc.prefixmodes set to %r', self.irc.name,
|
|
|
|
self.irc.prefixmodes)
|
|
|
|
|
|
|
|
# Finally, set the irc.connected (protocol negotiation complete)
|
|
|
|
# state to True.
|
|
|
|
self.irc.connected.set()
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
def handle_ping(self, source, command, args):
|
|
|
|
"""Handles incoming PING commands, so we don't time out."""
|
|
|
|
# <- :70M PING 70M 0AL
|
|
|
|
# -> :0AL PONG 0AL 70M
|
2016-01-01 02:28:47 +01:00
|
|
|
if self.irc.isInternalServer(args[1]):
|
2015-09-06 03:00:57 +02:00
|
|
|
self._send(args[1], 'PONG %s %s' % (args[1], source))
|
|
|
|
|
|
|
|
def handle_pong(self, source, command, args):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Handles incoming PONG commands.
|
|
|
|
|
|
|
|
This is used to keep track of whether the uplink is alive by the Irc()
|
|
|
|
internals - a server that fails to reply to our PINGs eventually
|
|
|
|
times out and is disconnected."""
|
2015-09-06 03:00:57 +02:00
|
|
|
if source == self.irc.uplink and args[1] == self.irc.sid:
|
|
|
|
self.irc.lastping = time.time()
|
|
|
|
|
|
|
|
def handle_fjoin(self, servernumeric, command, args):
|
|
|
|
"""Handles incoming FJOIN commands (InspIRCd equivalent of JOIN/SJOIN)."""
|
|
|
|
# :70M FJOIN #chat 1423790411 +AFPfjnt 6:5 7:5 9:5 :o,1SRAABIT4 v,1IOAAF53R <...>
|
|
|
|
channel = utils.toLower(self.irc, args[0])
|
|
|
|
# InspIRCd sends each channel's users in the form of 'modeprefix(es),UID'
|
|
|
|
userlist = args[-1].split()
|
2015-11-08 19:49:09 +01:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
their_ts = int(args[1])
|
2015-11-08 19:49:09 +01:00
|
|
|
our_ts = self.irc.channels[channel].ts
|
|
|
|
self.updateTS(channel, their_ts)
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
modestring = args[2:-1] or args[2]
|
|
|
|
parsedmodes = utils.parseModes(self.irc, channel, modestring)
|
|
|
|
utils.applyModes(self.irc, channel, parsedmodes)
|
|
|
|
namelist = []
|
|
|
|
for user in userlist:
|
|
|
|
modeprefix, user = user.split(',', 1)
|
2016-01-28 02:49:00 +01:00
|
|
|
|
|
|
|
# Don't crash when we get an invalid UID.
|
|
|
|
if user not in self.irc.users:
|
|
|
|
log.debug('(%s) handle_fjoin: tried to introduce user %s not in our user list, ignoring...',
|
|
|
|
self.irc.name, user)
|
|
|
|
continue
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
namelist.append(user)
|
|
|
|
self.irc.users[user].channels.add(channel)
|
|
|
|
if their_ts <= our_ts:
|
|
|
|
utils.applyModes(self.irc, channel, [('+%s' % mode, user) for mode in modeprefix])
|
|
|
|
self.irc.channels[channel].users.add(user)
|
|
|
|
return {'channel': channel, 'users': namelist, 'modes': parsedmodes, 'ts': their_ts}
|
|
|
|
|
|
|
|
def handle_uid(self, numeric, command, args):
|
|
|
|
"""Handles incoming UID commands (user introduction)."""
|
|
|
|
# :70M UID 70MAAAAAB 1429934638 GL 0::1 hidden-7j810p.9mdf.lrek.0000.0000.IP gl 0::1 1429934638 +Wioswx +ACGKNOQXacfgklnoqvx :realname
|
|
|
|
uid, ts, nick, realhost, host, ident, ip = args[0:7]
|
|
|
|
realname = args[-1]
|
|
|
|
self.irc.users[uid] = IrcUser(nick, ts, uid, ident, host, realname, realhost, ip)
|
|
|
|
parsedmodes = utils.parseModes(self.irc, uid, [args[8], args[9]])
|
|
|
|
log.debug('Applying modes %s for %s', parsedmodes, uid)
|
|
|
|
utils.applyModes(self.irc, uid, parsedmodes)
|
|
|
|
self.irc.servers[numeric].users.add(uid)
|
|
|
|
return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip}
|
|
|
|
|
|
|
|
def handle_server(self, numeric, command, args):
|
|
|
|
"""Handles incoming SERVER commands (introduction of servers)."""
|
2016-01-18 06:02:30 +01:00
|
|
|
|
|
|
|
# Initial SERVER command on connect.
|
|
|
|
if self.irc.uplink is None:
|
|
|
|
# <- SERVER whatever.net abcdefgh 0 10X :some server description
|
|
|
|
servername = args[0].lower()
|
|
|
|
numeric = args[3]
|
|
|
|
|
|
|
|
if args[1] != self.irc.serverdata['recvpass']:
|
|
|
|
# Check if recvpass is correct
|
|
|
|
raise ProtocolError('Error: recvpass from uplink server %s does not match configuration!' % servername)
|
|
|
|
|
|
|
|
sdesc = args[-1]
|
|
|
|
self.irc.servers[numeric] = IrcServer(None, servername, desc=sdesc)
|
|
|
|
self.irc.uplink = numeric
|
|
|
|
return
|
|
|
|
|
|
|
|
# Other server introductions.
|
2015-09-06 03:00:57 +02:00
|
|
|
# <- :00A SERVER test.server * 1 00C :testing raw message syntax
|
|
|
|
servername = args[0].lower()
|
|
|
|
sid = args[3]
|
|
|
|
sdesc = args[-1]
|
2015-09-12 19:39:05 +02:00
|
|
|
self.irc.servers[sid] = IrcServer(numeric, servername, desc=sdesc)
|
2016-01-18 06:02:30 +01:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
return {'name': servername, 'sid': args[3], 'text': sdesc}
|
|
|
|
|
|
|
|
def handle_fmode(self, numeric, command, args):
|
|
|
|
"""Handles the FMODE command, used for channel mode changes."""
|
|
|
|
# <- :70MAAAAAA FMODE #chat 1433653462 +hhT 70MAAAAAA 70MAAAAAD
|
|
|
|
channel = utils.toLower(self.irc, args[0])
|
2015-09-13 22:47:18 +02:00
|
|
|
oldobj = self.irc.channels[channel].deepcopy()
|
2015-09-06 03:00:57 +02:00
|
|
|
modes = args[2:]
|
|
|
|
changedmodes = utils.parseModes(self.irc, channel, modes)
|
|
|
|
utils.applyModes(self.irc, channel, changedmodes)
|
|
|
|
ts = int(args[1])
|
2015-09-13 22:47:18 +02:00
|
|
|
return {'target': channel, 'modes': changedmodes, 'ts': ts,
|
|
|
|
'oldchan': oldobj}
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2015-09-09 04:50:46 +02:00
|
|
|
def handle_mode(self, numeric, command, args):
|
|
|
|
"""Handles incoming user mode changes."""
|
|
|
|
# In InspIRCd, MODE is used for setting user modes and
|
|
|
|
# FMODE is used for channel modes:
|
|
|
|
# <- :70MAAAAAA MODE 70MAAAAAA -i+xc
|
|
|
|
target = args[0]
|
|
|
|
modestrings = args[1:]
|
2016-01-20 06:23:07 +01:00
|
|
|
changedmodes = utils.parseModes(self.irc, target, modestrings)
|
2015-09-09 04:50:46 +02:00
|
|
|
utils.applyModes(self.irc, target, changedmodes)
|
|
|
|
return {'target': target, 'modes': changedmodes}
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
def handle_idle(self, numeric, command, args):
|
|
|
|
"""Handles the IDLE command, sent between servers in remote WHOIS queries."""
|
|
|
|
# <- :70MAAAAAA IDLE 1MLAAAAIG
|
|
|
|
# -> :1MLAAAAIG IDLE 70MAAAAAA 1433036797 319
|
|
|
|
sourceuser = numeric
|
|
|
|
targetuser = args[0]
|
|
|
|
self._send(targetuser, 'IDLE %s %s 0' % (sourceuser, self.irc.users[targetuser].ts))
|
|
|
|
|
|
|
|
def handle_ftopic(self, numeric, command, args):
|
|
|
|
"""Handles incoming FTOPIC (sets topic on burst)."""
|
|
|
|
# <- :70M FTOPIC #channel 1434510754 GLo|o|!GLolol@escape.the.dreamland.ca :Some channel topic
|
|
|
|
channel = utils.toLower(self.irc, args[0])
|
|
|
|
ts = args[1]
|
|
|
|
setter = args[2]
|
|
|
|
topic = args[-1]
|
|
|
|
self.irc.channels[channel].topic = topic
|
|
|
|
self.irc.channels[channel].topicset = True
|
2015-12-19 06:53:35 +01:00
|
|
|
return {'channel': channel, 'setter': setter, 'ts': ts, 'text': topic}
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2015-11-01 03:15:03 +01:00
|
|
|
# SVSTOPIC is used by InspIRCd module m_topiclock - its arguments are the same as FTOPIC
|
|
|
|
handle_svstopic = handle_ftopic
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
def handle_invite(self, numeric, command, args):
|
|
|
|
"""Handles incoming INVITEs."""
|
|
|
|
# <- :70MAAAAAC INVITE 0ALAAAAAA #blah 0
|
|
|
|
target = args[0]
|
|
|
|
channel = utils.toLower(self.irc, args[1])
|
|
|
|
# We don't actually need to process this; just send the hook so plugins can use it
|
|
|
|
return {'target': target, 'channel': channel}
|
|
|
|
|
|
|
|
def handle_encap(self, numeric, command, args):
|
|
|
|
"""Handles incoming encapsulated commands (ENCAP). Hook arguments
|
|
|
|
returned by this should have a parse_as field, that sets the correct
|
|
|
|
hook name for the message.
|
|
|
|
|
|
|
|
For InspIRCd, the only ENCAP command we handle right now is KNOCK."""
|
|
|
|
# <- :70MAAAAAA ENCAP * KNOCK #blah :agsdfas
|
2015-12-18 06:19:40 +01:00
|
|
|
# From charybdis TS6 docs: https://github.com/grawity/irc-docs/blob/03ba884a54f1cef2193cd62b6a86803d89c1ac41/server/ts6.txt
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
# ENCAP
|
|
|
|
# source: any
|
|
|
|
# parameters: target server mask, subcommand, opt. parameters...
|
|
|
|
|
|
|
|
# Sends a command to matching servers. Propagation is independent of
|
|
|
|
# understanding the subcommand.
|
|
|
|
|
|
|
|
targetmask = args[0]
|
|
|
|
real_command = args[1]
|
|
|
|
if targetmask == '*' and real_command == 'KNOCK':
|
|
|
|
channel = utils.toLower(self.irc, args[2])
|
|
|
|
text = args[3]
|
|
|
|
return {'parse_as': real_command, 'channel': channel,
|
|
|
|
'text': text}
|
|
|
|
|
|
|
|
def handle_opertype(self, numeric, command, args):
|
|
|
|
"""Handles incoming OPERTYPE, which is used to denote an oper up.
|
|
|
|
|
2015-12-27 00:41:22 +01:00
|
|
|
This calls the internal hook CLIENT_OPERED, sets the internal
|
2015-09-06 03:00:57 +02:00
|
|
|
opertype of the client, and assumes setting user mode +o on the caller."""
|
|
|
|
# This is used by InspIRCd to denote an oper up; there is no MODE
|
|
|
|
# command sent for it.
|
|
|
|
# <- :70MAAAAAB OPERTYPE Network_Owner
|
|
|
|
omode = [('+o', None)]
|
2015-09-20 20:25:45 +02:00
|
|
|
self.irc.users[numeric].opertype = opertype = args[0].replace("_", " ")
|
2015-09-06 03:00:57 +02:00
|
|
|
utils.applyModes(self.irc, numeric, omode)
|
|
|
|
# OPERTYPE is essentially umode +o and metadata in one command;
|
|
|
|
# we'll call that too.
|
2015-12-27 00:41:22 +01:00
|
|
|
self.irc.callHooks([numeric, 'CLIENT_OPERED', {'text': opertype}])
|
2015-09-06 03:00:57 +02:00
|
|
|
return {'target': numeric, 'modes': omode}
|
|
|
|
|
|
|
|
def handle_fident(self, numeric, command, args):
|
|
|
|
"""Handles FIDENT, used for denoting ident changes."""
|
|
|
|
# <- :70MAAAAAB FIDENT test
|
|
|
|
self.irc.users[numeric].ident = newident = args[0]
|
|
|
|
return {'target': numeric, 'newident': newident}
|
|
|
|
|
|
|
|
def handle_fhost(self, numeric, command, args):
|
|
|
|
"""Handles FHOST, used for denoting hostname changes."""
|
|
|
|
# <- :70MAAAAAB FIDENT some.host
|
|
|
|
self.irc.users[numeric].host = newhost = args[0]
|
|
|
|
return {'target': numeric, 'newhost': newhost}
|
|
|
|
|
|
|
|
def handle_fname(self, numeric, command, args):
|
|
|
|
"""Handles FNAME, used for denoting real name/gecos changes."""
|
|
|
|
# <- :70MAAAAAB FNAME :afdsafasf
|
|
|
|
self.irc.users[numeric].realname = newgecos = args[0]
|
|
|
|
return {'target': numeric, 'newgecos': newgecos}
|
|
|
|
|
|
|
|
def handle_endburst(self, numeric, command, args):
|
|
|
|
"""ENDBURST handler; sends a hook with empty contents."""
|
|
|
|
return {}
|
|
|
|
|
|
|
|
def handle_away(self, numeric, command, args):
|
|
|
|
"""Handles incoming AWAY messages."""
|
|
|
|
# <- :1MLAAAAIG AWAY 1439371390 :Auto-away
|
|
|
|
try:
|
|
|
|
ts = args[0]
|
|
|
|
self.irc.users[numeric].away = text = args[1]
|
|
|
|
return {'text': text, 'ts': ts}
|
|
|
|
except IndexError: # User is unsetting away status
|
|
|
|
self.irc.users[numeric].away = ''
|
|
|
|
return {'text': ''}
|
|
|
|
|
2015-12-25 04:52:52 +01:00
|
|
|
def handle_rsquit(self, numeric, command, args):
|
|
|
|
"""
|
|
|
|
Handles the RSQUIT command, which is sent by opers to SQUIT remote
|
|
|
|
servers.
|
|
|
|
"""
|
|
|
|
# <- :1MLAAAAIG RSQUIT :ayy.lmao
|
|
|
|
# <- :1MLAAAAIG RSQUIT ayy.lmao :some reason
|
|
|
|
|
|
|
|
# RSQUIT is sent by opers to SQUIT remote servers. However, it differs from
|
|
|
|
# a regular SQUIT in that:
|
|
|
|
# 1) It takes a server name instead of a SID,
|
|
|
|
# 2) Responses have to be be explicitly sent; i.e. The target server has
|
|
|
|
# to agree with splitting the target, and could ignore such requests
|
|
|
|
# entirely.
|
|
|
|
|
|
|
|
# If we receive such a remote SQUIT, just forward it as a regular
|
|
|
|
# SQUIT, in order to be consistent with other IRCds which make SQUITs
|
|
|
|
# implicit.
|
|
|
|
target = self._getSid(args[0])
|
2016-01-01 02:28:47 +01:00
|
|
|
if self.irc.isInternalServer(target):
|
2015-12-25 04:52:52 +01:00
|
|
|
# The target has to be one of our servers in order to work...
|
|
|
|
uplink = self.irc.servers[target].uplink
|
|
|
|
reason = 'Requested by %s' % utils.getHostmask(self.irc, numeric)
|
|
|
|
self._send(uplink, 'SQUIT %s :%s' % (target, reason))
|
|
|
|
return self.handle_squit(numeric, 'SQUIT', [target, reason])
|
|
|
|
else:
|
|
|
|
log.debug("(%s) Got RSQUIT for '%s', which is either invalid or not "
|
|
|
|
"a server of ours!", self.irc.name, args[0])
|
|
|
|
|
2016-02-21 02:54:46 +01:00
|
|
|
def handle_metadata(self, numeric, command, args):
|
|
|
|
"""
|
|
|
|
Handles the METADATA command, used by servers to send metadata (services
|
|
|
|
login name, certfp data, etc.) for clients.
|
|
|
|
"""
|
|
|
|
uid = args[0]
|
|
|
|
|
|
|
|
if args[1] == 'accountname':
|
|
|
|
# <- :00A METADATA 1MLAAAJET accountname :
|
|
|
|
# <- :00A METADATA 1MLAAAJET accountname :tester
|
|
|
|
# Sets the services login name of the client.
|
|
|
|
|
|
|
|
self.irc.callHooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': args[-1]}])
|
|
|
|
|
2016-03-26 19:27:07 +01:00
|
|
|
def handle_version(self, numeric, command, args):
|
|
|
|
"""
|
|
|
|
Stub VERSION handler (does nothing) to override the one in ts6_common.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
Class = InspIRCdProtocol
|