2015-12-26 23:45:28 +01:00
|
|
|
"""
|
2019-05-03 01:51:06 +02:00
|
|
|
inspircd.py: InspIRCd 2.0, 3.0 protocol module for PyLink.
|
2015-12-26 23:45:28 +01:00
|
|
|
"""
|
|
|
|
|
2015-03-20 00:21:49 +01:00
|
|
|
import time
|
2015-12-18 06:18:11 +01:00
|
|
|
import threading
|
2015-07-05 22:22:17 +02:00
|
|
|
|
2017-03-05 09:06:19 +01:00
|
|
|
from pylinkirc import utils, conf
|
2016-06-21 03:18:54 +02:00
|
|
|
from pylinkirc.classes import *
|
|
|
|
from pylinkirc.log import log
|
|
|
|
from pylinkirc.protocols.ts6_common import *
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
class InspIRCdProtocol(TS6BaseProtocol):
|
2017-07-17 03:46:56 +02:00
|
|
|
|
|
|
|
S2S_BUFSIZE = 0 # InspIRCd allows infinitely long S2S messages, so set bufsize to infinite
|
2019-05-03 01:11:21 +02:00
|
|
|
SUPPORTED_IRCDS = ['insp20', 'insp3']
|
|
|
|
DEFAULT_IRCD = SUPPORTED_IRCDS[0]
|
2017-07-17 03:46:56 +02:00
|
|
|
|
2019-05-03 02:23:20 +02:00
|
|
|
MAX_PROTO_VER = 1205 # anything above this warns (not officially supported)
|
2019-05-03 00:47:03 +02:00
|
|
|
|
2017-06-25 10:12:22 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
2017-03-16 07:58:51 +01:00
|
|
|
|
2019-02-13 00:53:58 +01:00
|
|
|
self.protocol_caps |= {'slash-in-nicks', 'slash-in-hosts'}
|
2017-03-16 07:58:51 +01:00
|
|
|
|
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',
|
2019-05-03 02:27:48 +02:00
|
|
|
'FTOPIC': 'TOPIC', 'OPERTYPE': 'MODE', 'FHOST': 'CHGHOST',
|
|
|
|
'FIDENT': 'CHGIDENT', 'FNAME': 'CHGNAME', 'SVSTOPIC': 'TOPIC',
|
|
|
|
'SAKICK': 'KICK', 'IJOIN': 'JOIN'}
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2019-05-03 02:23:00 +02:00
|
|
|
ircd_target = self.serverdata.get('target_version', self.DEFAULT_IRCD).lower()
|
2019-05-03 01:11:21 +02:00
|
|
|
if ircd_target == 'insp20':
|
|
|
|
self.proto_ver = 1202
|
|
|
|
elif ircd_target == 'insp3':
|
|
|
|
self.proto_ver = 1205
|
|
|
|
else:
|
|
|
|
raise ProtocolError("Unsupported target_version %r: supported values include %s" % (ircd_target, self.SUPPORTED_IRCDS))
|
|
|
|
log.debug('(%s) inspircd: using protocol version %s for target_version %r', self.name, self.proto_ver, ircd_target)
|
2016-03-27 00:23:22 +01:00
|
|
|
|
2019-05-03 01:51:06 +02:00
|
|
|
# Track prefix mode levels on InspIRCd 3
|
|
|
|
self._prefix_levels = {}
|
|
|
|
|
2017-12-27 20:48:00 +01:00
|
|
|
# Track the modules supported by the uplink.
|
|
|
|
self._modsupport = set()
|
|
|
|
|
2018-02-11 00:31:12 +01:00
|
|
|
# Settable by plugins (e.g. relay) as needed, used to work around +j being triggered
|
|
|
|
# by bursting users.
|
|
|
|
self._endburst_delay = 0
|
|
|
|
|
2016-01-18 06:02:30 +01:00
|
|
|
### Outgoing commands
|
|
|
|
|
2017-07-01 06:25:58 +02:00
|
|
|
def spawn_client(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):
|
2016-04-25 06:17:56 +02:00
|
|
|
"""
|
|
|
|
Spawns a new client with the given options.
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
Note: No nick collision / valid nickname checks are done here; it is
|
2016-04-25 06:17:56 +02:00
|
|
|
up to plugins to make sure they don't introduce anything invalid.
|
|
|
|
"""
|
2017-06-25 11:03:12 +02:00
|
|
|
server = server or self.sid
|
2016-04-25 06:16:41 +02:00
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
if not self.is_internal_server(server):
|
2016-01-10 02:44:05 +01:00
|
|
|
raise ValueError('Server %r is not a PyLink server!' % server)
|
2016-04-25 06:16:41 +02:00
|
|
|
|
|
|
|
uid = self.uidgen[server].next_uid()
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
ts = ts or int(time.time())
|
2018-02-19 08:26:39 +01:00
|
|
|
realname = realname or conf.conf['pylink']['realname']
|
2015-09-06 03:00:57 +02:00
|
|
|
realhost = realhost or host
|
2017-06-30 07:56:14 +02:00
|
|
|
raw_modes = self.join_modes(modes)
|
2018-05-27 01:22:36 +02:00
|
|
|
u = self.users[uid] = User(self, nick, ts, uid, server, ident=ident, host=host,
|
|
|
|
realname=realname, realhost=realhost, ip=ip,
|
|
|
|
manipulatable=manipulatable, opertype=opertype)
|
2016-04-25 06:16:41 +02:00
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
self.apply_modes(uid, modes)
|
2017-06-25 11:03:12 +02:00
|
|
|
self.servers[server].users.add(uid)
|
2016-04-25 06:16:41 +02:00
|
|
|
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(server, "UID {uid} {ts} {nick} {realhost} {host} {ident} {ip}"
|
2017-09-24 07:36:16 +02:00
|
|
|
" {ts} {modes} + :{realname}".format(ts=ts, host=host,
|
|
|
|
nick=nick, ident=ident, uid=uid,
|
|
|
|
modes=raw_modes, ip=ip, realname=realname,
|
|
|
|
realhost=realhost))
|
2015-09-06 03:00:57 +02:00
|
|
|
if ('o', None) in modes or ('+o', None) in modes:
|
2017-07-07 22:27:45 +02:00
|
|
|
self._oper_up(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.
|
2016-11-10 03:55:13 +01:00
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
server = self.get_server(client)
|
|
|
|
if not self.is_internal_server(server):
|
2017-06-25 11:03:12 +02:00
|
|
|
log.error('(%s) Error trying to join %r to %r (no such client exists)', self.name, client, channel)
|
2016-01-10 02:44:05 +01:00
|
|
|
raise LookupError('No such PyLink client exists.')
|
2016-11-10 03:55:13 +01:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
# Strip out list-modes, they shouldn't be ever sent in FJOIN.
|
2017-08-25 11:11:48 +02:00
|
|
|
modes = [m for m in self._channels[channel].modes if m[0] not in self.cmodes['*A']]
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(server, "FJOIN {channel} {ts} {modes} :,{uid}".format(
|
2017-08-25 11:11:48 +02:00
|
|
|
ts=self._channels[channel].ts, uid=client, channel=channel,
|
2017-06-30 07:56:14 +02:00
|
|
|
modes=self.join_modes(modes)))
|
2017-08-25 11:11:48 +02:00
|
|
|
self._channels[channel].users.add(client)
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[client].channels.add(channel)
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2016-06-23 06:34:16 +02:00
|
|
|
def sjoin(self, server, channel, users, ts=None, modes=set()):
|
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')])
|
2017-06-25 11:03:12 +02:00
|
|
|
sjoin(self.sid, '#test', [('o', self.pseudoclient.uid)])
|
2015-09-06 03:00:57 +02:00
|
|
|
"""
|
2017-06-25 11:03:12 +02:00
|
|
|
server = server or self.sid
|
2016-01-17 01:53:46 +01:00
|
|
|
assert users, "sjoin: No users sent?"
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug('(%s) sjoin: got %r for users', self.name, users)
|
2016-06-23 06:34:16 +02:00
|
|
|
|
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
|
|
|
# Strip out list-modes, they shouldn't ever be sent in FJOIN (protocol rules).
|
2017-08-25 11:11:48 +02:00
|
|
|
modes = modes or self._channels[channel].modes
|
|
|
|
orig_ts = self._channels[channel].ts
|
2016-06-25 22:56:24 +02:00
|
|
|
ts = ts or orig_ts
|
2016-06-23 06:34:16 +02:00
|
|
|
|
|
|
|
banmodes = []
|
|
|
|
regularmodes = []
|
|
|
|
for mode in modes:
|
|
|
|
modechar = mode[0][-1]
|
2017-06-25 11:03:12 +02:00
|
|
|
if modechar in self.cmodes['*A']:
|
2016-06-24 07:33:14 +02:00
|
|
|
# Track bans separately (they are sent as a normal FMODE instead of in FJOIN.
|
|
|
|
# However, don't reset bans that have already been set.
|
2017-08-25 11:11:48 +02:00
|
|
|
if (modechar, mode[1]) not in self._channels[channel].modes:
|
2016-06-24 07:33:14 +02:00
|
|
|
banmodes.append(mode)
|
2016-06-23 06:34:16 +02:00
|
|
|
else:
|
|
|
|
regularmodes.append(mode)
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
uids = []
|
2016-06-23 06:34:16 +02:00
|
|
|
changedmodes = set(modes)
|
2015-09-06 03:00:57 +02:00
|
|
|
namelist = []
|
2016-06-23 06:34:16 +02:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
# 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:
|
2016-06-23 06:34:16 +02:00
|
|
|
changedmodes.add(('+%s' % m, user))
|
2015-09-06 03:00:57 +02:00
|
|
|
try:
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[user].channels.add(channel)
|
2015-09-06 03:00:57 +02:00
|
|
|
except KeyError: # Not initialized yet?
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug("(%s) sjoin: KeyError trying to add %r to %r's channel list?", self.name, channel, user)
|
2016-06-23 06:34:16 +02:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
namelist = ' '.join(namelist)
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(server, "FJOIN {channel} {ts} {modes} :{users}".format(
|
2015-09-06 03:00:57 +02:00
|
|
|
ts=ts, users=namelist, channel=channel,
|
2017-06-30 07:56:14 +02:00
|
|
|
modes=self.join_modes(modes)))
|
2017-08-25 11:11:48 +02:00
|
|
|
self._channels[channel].users.update(uids)
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2016-06-23 06:34:16 +02:00
|
|
|
if banmodes:
|
|
|
|
# Burst ban modes if there are any.
|
|
|
|
# <- :1ML FMODE #test 1461201525 +bb *!*@bad.user *!*@rly.bad.user
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(server, "FMODE {channel} {ts} {modes} ".format(
|
2017-06-30 07:56:14 +02:00
|
|
|
ts=ts, channel=channel, modes=self.join_modes(banmodes)))
|
2016-06-23 06:34:16 +02:00
|
|
|
|
2016-07-11 06:35:17 +02:00
|
|
|
self.updateTS(server, channel, ts, changedmodes)
|
2016-06-23 06:34:16 +02:00
|
|
|
|
2017-07-07 22:27:45 +02:00
|
|
|
def _oper_up(self, target, opertype=None):
|
2015-09-06 03:00:57 +02:00
|
|
|
"""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
|
2017-07-01 06:44:31 +02:00
|
|
|
set the opertype attribute of an User object (in self.users),
|
2015-09-06 03:00:57 +02:00
|
|
|
and the change will be reflected here."""
|
2017-06-25 11:03:12 +02:00
|
|
|
userobj = self.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!',
|
2017-06-25 11:03:12 +02:00
|
|
|
self.name, target, userobj.nick)
|
2015-09-06 03:00:57 +02:00
|
|
|
# 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.',
|
2017-06-25 11:03:12 +02:00
|
|
|
self.name, target)
|
2015-09-06 03:00:57 +02:00
|
|
|
userobj.opertype = otype
|
2017-02-18 23:28:28 +01:00
|
|
|
|
2019-06-01 02:31:11 +02:00
|
|
|
# InspIRCd 2.x uses _ in OPERTYPE to denote spaces, while InspIRCd 3.x does not.
|
|
|
|
# This is one of the few things not fixed by 2.0/3.0 link compat, so here's a workaround
|
2017-02-18 23:28:28 +01:00
|
|
|
if self.remote_proto_ver < 1205:
|
|
|
|
otype = otype.replace(" ", "_")
|
|
|
|
else:
|
|
|
|
otype = ':' + otype
|
|
|
|
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(target, 'OPERTYPE %s' % otype)
|
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
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
if (not self.is_internal_client(numeric)) and \
|
|
|
|
(not self.is_internal_server(numeric)):
|
2016-01-17 02:08:17 +01:00
|
|
|
raise LookupError('No such PyLink client/server exists.')
|
|
|
|
|
2017-08-29 05:07:12 +02:00
|
|
|
if ('+o', None) in modes and not self.is_channel(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.
|
2017-07-07 22:27:45 +02:00
|
|
|
self._oper_up(target)
|
2017-08-25 11:13:15 +02:00
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
self.apply_modes(target, modes)
|
|
|
|
joinedmodes = self.join_modes(modes)
|
2017-08-25 11:13:15 +02:00
|
|
|
|
2017-08-29 05:07:12 +02:00
|
|
|
if self.is_channel(target):
|
2017-08-25 11:11:48 +02:00
|
|
|
ts = ts or self._channels[target].ts
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(numeric, 'FMODE %s %s %s' % (target, ts, joinedmodes))
|
2015-09-06 03:00:57 +02:00
|
|
|
else:
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(numeric, 'MODE %s %s' % (target, joinedmodes))
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2016-01-17 02:03:22 +01:00
|
|
|
def kill(self, numeric, target, reason):
|
|
|
|
"""Sends a kill from a PyLink client/server."""
|
2017-06-30 07:56:14 +02:00
|
|
|
if (not self.is_internal_client(numeric)) and \
|
|
|
|
(not self.is_internal_server(numeric)):
|
2016-01-17 02:03:22 +01:00
|
|
|
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.
|
2017-06-25 11:03:12 +02:00
|
|
|
if numeric in self.servers:
|
|
|
|
sourcenick = self.servers[numeric].name
|
2016-02-26 06:11:42 +01:00
|
|
|
else:
|
2017-06-25 11:03:12 +02:00
|
|
|
sourcenick = self.users[numeric].nick
|
2016-02-26 06:11:42 +01:00
|
|
|
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(numeric, 'KILL %s :Killed (%s (%s))' % (target, sourcenick, reason))
|
2016-01-17 02:03:22 +01:00
|
|
|
|
2018-05-21 09:28:48 +02:00
|
|
|
self._remove_client(target)
|
2015-10-09 05:12:52 +02:00
|
|
|
|
2019-05-03 03:05:38 +02:00
|
|
|
def topic(self, source, target, text):
|
|
|
|
"""Sends a topic change from a PyLink client."""
|
|
|
|
if not self.is_internal_client(source):
|
|
|
|
raise LookupError('No such PyLink client exists.')
|
|
|
|
|
2019-06-01 02:31:11 +02:00
|
|
|
if self.proto_ver >= 1205:
|
2019-05-03 03:05:38 +02:00
|
|
|
self._send_with_prefix(source, 'FTOPIC %s %s %s :%s' % (target, self._channels[target].ts, int(time.time()), text))
|
|
|
|
else:
|
|
|
|
return super().topic(source, target, text)
|
|
|
|
|
|
|
|
def topic_burst(self, source, target, text):
|
2015-09-25 03:36:54 +02:00
|
|
|
"""Sends a topic change from a PyLink server. This is usually used on burst."""
|
2019-05-03 03:05:38 +02:00
|
|
|
if not self.is_internal_server(source):
|
2016-01-10 02:44:05 +01:00
|
|
|
raise LookupError('No such PyLink server exists.')
|
2019-05-03 03:05:38 +02:00
|
|
|
|
|
|
|
topic_ts = int(time.time())
|
|
|
|
servername = self.servers[source].name
|
|
|
|
|
2019-06-01 02:31:11 +02:00
|
|
|
if self.proto_ver >= 1205:
|
2019-05-03 03:05:38 +02:00
|
|
|
self._send_with_prefix(source, 'FTOPIC %s %s %s %s :%s' % (target, self._channels[target].ts, topic_ts, servername, text))
|
|
|
|
else:
|
|
|
|
self._send_with_prefix(source, 'FTOPIC %s %s %s :%s' % (target, topic_ts, servername, text))
|
|
|
|
|
2017-08-25 11:11:48 +02:00
|
|
|
self._channels[target].topic = text
|
|
|
|
self._channels[target].topicset = True
|
2015-09-06 03:00:57 +02:00
|
|
|
|
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."""
|
2017-06-30 07:56:14 +02:00
|
|
|
if not self.is_internal_client(numeric):
|
2016-01-10 02:44:05 +01:00
|
|
|
raise LookupError('No such PyLink client exists.')
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(numeric, 'ENCAP * KNOCK %s :%s' % (target, text))
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2017-07-01 06:29:38 +02:00
|
|
|
def update_client(self, target, field, text):
|
2015-12-31 00:54:09 +01:00
|
|
|
"""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)
|
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
if self.is_internal_client(target):
|
2015-12-31 00:54:09 +01:00
|
|
|
# It is one of our clients, use FIDENT/HOST/NAME.
|
|
|
|
if field == 'IDENT':
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[target].ident = text
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(target, 'FIDENT %s' % text)
|
2015-12-31 00:54:09 +01:00
|
|
|
elif field == 'HOST':
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[target].host = text
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(target, 'FHOST %s' % text)
|
2015-12-31 00:54:09 +01:00
|
|
|
elif field in ('REALNAME', 'GECOS'):
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[target].realname = text
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(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':
|
2017-12-22 21:38:48 +01:00
|
|
|
if 'm_chgident.so' not in self._modsupport:
|
2017-12-22 21:41:48 +01:00
|
|
|
raise NotImplementedError('Cannot change idents as m_chgident.so is not loaded')
|
2016-08-09 08:40:48 +02:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[target].ident = text
|
|
|
|
self._send_with_prefix(self.sid, 'CHGIDENT %s %s' % (target, text))
|
2015-12-31 00:54:09 +01:00
|
|
|
|
|
|
|
# Send hook payloads for other plugins to listen to.
|
2017-06-30 07:56:14 +02:00
|
|
|
self.call_hooks([self.sid, 'CHGIDENT',
|
2015-12-31 00:54:09 +01:00
|
|
|
{'target': target, 'newident': text}])
|
|
|
|
elif field == 'HOST':
|
2017-12-22 21:38:48 +01:00
|
|
|
if 'm_chghost.so' not in self._modsupport:
|
2017-12-22 21:41:48 +01:00
|
|
|
raise NotImplementedError('Cannot change hosts as m_chghost.so is not loaded')
|
2016-08-09 08:40:48 +02:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[target].host = text
|
|
|
|
self._send_with_prefix(self.sid, 'CHGHOST %s %s' % (target, text))
|
2015-12-31 00:54:09 +01:00
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
self.call_hooks([self.sid, 'CHGHOST',
|
2015-12-31 00:54:09 +01:00
|
|
|
{'target': target, 'newhost': text}])
|
|
|
|
|
|
|
|
elif field in ('REALNAME', 'GECOS'):
|
2017-12-22 21:38:48 +01:00
|
|
|
if 'm_chgname.so' not in self._modsupport:
|
2017-12-22 21:41:48 +01:00
|
|
|
raise NotImplementedError('Cannot change real names as m_chgname.so is not loaded')
|
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[target].realname = text
|
|
|
|
self._send_with_prefix(self.sid, 'CHGNAME %s :%s' % (target, text))
|
2015-12-31 00:54:09 +01:00
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
self.call_hooks([self.sid, 'CHGNAME',
|
2015-12-31 00:54:09 +01:00
|
|
|
{'target': target, 'newgecos': text}])
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2016-01-17 01:47:35 +01:00
|
|
|
def numeric(self, source, numeric, target, text):
|
2016-06-28 07:28:00 +02:00
|
|
|
"""Sends raw numerics from a server to a remote client."""
|
|
|
|
# InspIRCd 2.0 syntax (undocumented):
|
|
|
|
# Essentially what this does is push the raw numeric text after the first ":" towards the
|
|
|
|
# given user.
|
|
|
|
# <- :70M PUSH 0ALAAAAAA ::midnight.vpn 422 PyLink-devel :Message of the day file is missing.
|
|
|
|
|
2019-05-03 02:06:04 +02:00
|
|
|
# InspIRCd 3 uses a new NUM command in this format:
|
|
|
|
# -> NUM <numeric source sid> <target uuid> <numeric ID> <params>
|
2019-06-01 02:31:11 +02:00
|
|
|
if self.proto_ver >= 1205:
|
2019-05-03 02:06:04 +02:00
|
|
|
self._send('NUM %s %s %s %s' % (source, target, numeric, text))
|
|
|
|
else:
|
|
|
|
self._send_with_prefix(self.sid, 'PUSH %s ::%s %s %s %s' % (target, source, numeric, target, text))
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2019-06-01 03:28:28 +02:00
|
|
|
def invite(self, source, target, channel):
|
|
|
|
"""Sends an INVITE from a PyLink client."""
|
|
|
|
if not self.is_internal_client(source):
|
|
|
|
raise LookupError('No such PyLink client exists.')
|
|
|
|
|
|
|
|
if self.proto_ver >= 1205: # insp3
|
|
|
|
# Note: insp3 supports optionally sending an invite expiration (after the TS argument),
|
|
|
|
# but we don't use / expose that feature yet.
|
|
|
|
self._send_with_prefix(source, 'INVITE %s %s %d' % (target, channel, self._channels[channel].ts))
|
|
|
|
else: # insp2
|
|
|
|
self._send_with_prefix(source, 'INVITE %s %s' % (target, channel))
|
|
|
|
|
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:
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(source, 'AWAY %s :%s' % (int(time.time()), text))
|
2015-09-06 03:00:57 +02:00
|
|
|
else:
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(source, 'AWAY')
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[source].away = text
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2018-02-11 00:39:01 +01:00
|
|
|
def spawn_server(self, name, sid=None, uplink=None, desc=None):
|
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
|
|
|
|
2018-02-11 00:39:01 +01:00
|
|
|
Endburst delay can be tweaked by setting the _endburst_delay variable
|
|
|
|
to a positive value before calling spawn_server(). This can be used to
|
|
|
|
prevent PyLink bursts from filling up snomasks and triggering InspIRCd +j.
|
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
|
2017-06-25 11:03:12 +02:00
|
|
|
uplink = uplink or self.sid
|
2015-09-06 03:00:57 +02:00
|
|
|
name = name.lower()
|
2018-02-11 00:39:01 +01:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
# "desc" defaults to the configured server description.
|
2018-02-19 08:26:39 +01:00
|
|
|
desc = desc or self.serverdata.get('serverdesc') or conf.conf['pylink']['serverdesc']
|
2018-02-11 00:39:01 +01:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
if sid is None: # No sid given; generate one!
|
2015-09-12 21:05:53 +02:00
|
|
|
sid = self.sidgen.next_sid()
|
2018-02-11 00:39:01 +01:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
assert len(sid) == 3, "Incorrect SID length"
|
2017-06-25 11:03:12 +02:00
|
|
|
if sid in self.servers:
|
2015-09-06 03:00:57 +02:00
|
|
|
raise ValueError('A server with SID %r already exists!' % sid)
|
2018-02-11 00:39:01 +01:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
for server in self.servers.values():
|
2015-09-06 03:00:57 +02:00
|
|
|
if name == server.name:
|
|
|
|
raise ValueError('A server named %r already exists!' % name)
|
2018-02-11 00:39:01 +01:00
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
if not self.is_internal_server(uplink):
|
2016-01-10 02:44:05 +01:00
|
|
|
raise ValueError('Server %r is not a PyLink server!' % uplink)
|
2018-02-11 00:39:01 +01:00
|
|
|
|
2017-08-29 05:07:12 +02:00
|
|
|
if not self.is_server_name(name):
|
2015-09-06 03:00:57 +02:00
|
|
|
raise ValueError('Invalid server name %r' % name)
|
2017-09-24 07:36:16 +02:00
|
|
|
|
2017-08-25 22:53:45 +02:00
|
|
|
self.servers[sid] = Server(self, uplink, name, internal=True, desc=desc)
|
2017-09-24 07:36:16 +02:00
|
|
|
self._send_with_prefix(uplink, 'SERVER %s * %s %s :%s' % (name, self.servers[sid].hopcount, sid, desc))
|
2015-12-18 06:18:11 +01:00
|
|
|
|
2018-02-11 00:31:12 +01:00
|
|
|
# Endburst delay clutter
|
|
|
|
|
2017-05-07 22:56:55 +02:00
|
|
|
def endburstf():
|
2015-12-18 06:18:11 +01:00
|
|
|
# Delay ENDBURST by X seconds if requested.
|
2018-02-11 00:31:12 +01:00
|
|
|
if self._aborted.wait(self._endburst_delay):
|
2017-05-07 22:56:55 +02:00
|
|
|
# We managed to catch the abort flag before sending ENDBURST, so break
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug('(%s) stopping endburstf() for %s as aborted was set', self.name, sid)
|
2017-05-07 22:56:55 +02:00
|
|
|
return
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(sid, 'ENDBURST')
|
2017-05-07 22:56:55 +02:00
|
|
|
|
2018-02-11 00:31:12 +01:00
|
|
|
if self._endburst_delay:
|
2017-08-08 09:27:05 +02:00
|
|
|
t = threading.Thread(target=endburstf, name="protocols/inspircd delayed ENDBURST thread for %s@%s" % (sid, self.name))
|
|
|
|
t.daemon = True
|
|
|
|
t.start()
|
2015-12-18 06:18:11 +01:00
|
|
|
else: # Else, send burst immediately
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(sid, 'ENDBURST')
|
2015-09-06 03:00:57 +02:00
|
|
|
return sid
|
|
|
|
|
2017-07-17 14:24:07 +02:00
|
|
|
def set_server_ban(self, source, duration, user='*', host='*', reason='User banned'):
|
|
|
|
"""
|
|
|
|
Sets a server ban.
|
|
|
|
"""
|
|
|
|
# <- :70M ADDLINE G *@10.9.8.7 midnight.local 1433704565 0 :gib reason pls kthx
|
|
|
|
|
|
|
|
assert not (user == host == '*'), "Refusing to set ridiculous ban on *@*"
|
|
|
|
|
|
|
|
# Per https://wiki.inspircd.org/InspIRCd_Spanning_Tree_1.2/ADDLINE, the setter argument can
|
|
|
|
# be a max of 64 characters
|
|
|
|
self._send_with_prefix(source, 'ADDLINE G %s@%s %s %s %s :%s' % (user, host, self.get_friendly_name(source)[:64],
|
|
|
|
int(time.time()), duration, reason))
|
|
|
|
|
2016-01-18 06:02:30 +01:00
|
|
|
### Core / command handlers
|
|
|
|
|
2018-01-21 22:27:59 +01:00
|
|
|
def _post_disconnect(self):
|
|
|
|
super()._post_disconnect()
|
|
|
|
log.debug('(%s) _post_disconnect: clearing _modsupport entries. Last: %s', self.name, self._modsupport)
|
|
|
|
self._modsupport.clear()
|
|
|
|
|
2017-06-25 10:12:22 +02:00
|
|
|
def post_connect(self):
|
2015-09-06 03:00:57 +02:00
|
|
|
"""Initializes a connection to a server."""
|
2017-06-25 11:03:12 +02:00
|
|
|
ts = self.start_ts
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
f = self.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
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
host = self.serverdata["hostname"]
|
2016-03-26 19:35:29 +01:00
|
|
|
f('SERVER {host} {Pass} 0 {sid} :{sdesc}'.format(host=host,
|
2017-06-25 11:03:12 +02:00
|
|
|
Pass=self.serverdata["sendpass"], sid=self.sid,
|
2018-02-19 08:26:39 +01:00
|
|
|
sdesc=self.serverdata.get('serverdesc') or conf.conf['pylink']['serverdesc']))
|
2016-03-26 19:35:29 +01:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
self._send_with_prefix(self.sid, 'BURST %s' % ts)
|
2019-06-01 03:12:26 +02:00
|
|
|
|
|
|
|
# InspIRCd sends VERSION data on link, instead of when requested by a client.
|
2019-05-03 02:42:45 +02:00
|
|
|
if self.proto_ver >= 1205:
|
2019-06-01 03:12:26 +02:00
|
|
|
verstr = self.version()
|
|
|
|
for version_type in {'version', 'rawversion'}:
|
|
|
|
self._send_with_prefix(self.sid, 'SINFO %s :%s' % (version_type, verstr.split(' ', 1)[0]))
|
|
|
|
self._send_with_prefix(self.sid, 'SINFO fullversion :%s' % verstr)
|
2019-05-03 02:42:45 +02:00
|
|
|
else:
|
|
|
|
self._send_with_prefix(self.sid, 'VERSION :%s' % self.version())
|
2017-06-25 11:03:12 +02:00
|
|
|
self._send_with_prefix(self.sid, 'ENDBURST')
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2017-08-06 06:52:34 +02:00
|
|
|
# Extban definitions
|
2017-08-24 06:47:30 +02:00
|
|
|
self.extbans_acting = {'quiet': 'm:', 'ban_nonick': 'N:', 'ban_blockcolor': 'c:',
|
|
|
|
'ban_partmsgs': 'p:', 'ban_invites': 'A:', 'ban_blockcaps': 'B:',
|
|
|
|
'ban_noctcp': 'C:', 'ban_nokicks': 'Q:', 'ban_stripcolor': 'S:',
|
|
|
|
'ban_nonotice': 'T:'}
|
2017-08-24 06:18:44 +02:00
|
|
|
self.extbans_matching = {'ban_inchannel': 'j:', 'ban_realname': 'r:', 'ban_server': 's:',
|
2017-08-24 06:47:30 +02:00
|
|
|
'ban_certfp': 'z:', 'ban_opertype': 'O:', 'ban_account': 'R:',
|
|
|
|
# Note: InspIRCd /helpop refers to this as an acting extban, but
|
|
|
|
# it actually behaves as a matching one...
|
|
|
|
'ban_unregistered_matching': 'U:'}
|
2017-08-06 06:52:34 +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.
|
2019-05-03 01:11:53 +02:00
|
|
|
# We check just about everything except MODULES
|
|
|
|
|
|
|
|
if args[0] == 'START':
|
|
|
|
# Check the protocol version
|
|
|
|
# insp20:
|
|
|
|
# <- CAPAB START 1202
|
|
|
|
# insp3:
|
|
|
|
# <- CAPAB START 1205
|
|
|
|
self.remote_proto_ver = protocol_version = int(args[1])
|
|
|
|
|
2019-05-03 02:23:20 +02:00
|
|
|
if protocol_version < self.proto_ver:
|
2019-05-03 01:11:53 +02:00
|
|
|
raise ProtocolError("Remote protocol version is too old! "
|
2019-05-03 02:23:20 +02:00
|
|
|
"At least %s is needed. (got %s)" %
|
|
|
|
(self.proto_ver, protocol_version))
|
2019-05-03 01:11:53 +02:00
|
|
|
elif protocol_version > self.MAX_PROTO_VER:
|
2019-06-07 08:50:08 +02:00
|
|
|
log.warning("(%s) PyLink support for InspIRCd > 3.x is experimental, "
|
2019-05-03 01:11:53 +02:00
|
|
|
"and should not be relied upon for anything important.",
|
|
|
|
self.name)
|
2019-06-07 08:50:08 +02:00
|
|
|
elif protocol_version >= 1205 > self.proto_ver:
|
|
|
|
log.info("(%s) PyLink 2.1 introduces native support for InspIRCd 3.0. "
|
|
|
|
"You can enable this by setting the 'target_version' option in your "
|
|
|
|
"InspIRCd server block to 'insp3'.", self.name)
|
|
|
|
log.info("(%s) Falling back to InspIRCd 2.0 (compatibility) mode.", self.name)
|
2019-05-03 01:11:53 +02:00
|
|
|
log.debug("(%s) inspircd: got remote protocol version %s", self.name, protocol_version)
|
2016-01-18 06:02:30 +01:00
|
|
|
|
2019-06-01 02:31:11 +02:00
|
|
|
if self.proto_ver >= 1205:
|
2019-05-03 01:51:06 +02:00
|
|
|
# Clear mode lists, they will be negotiated during burst
|
|
|
|
self.cmodes = {'*A': '', '*B': '', '*C': '', '*D': ''}
|
|
|
|
self.umodes = {'*A': '', '*B': '', '*C': '', '*D': ''}
|
|
|
|
self.prefixmodes.clear()
|
|
|
|
|
|
|
|
if args[0] in {'CHANMODES', 'USERMODES'}:
|
|
|
|
# insp20:
|
2016-01-18 06:02:30 +01:00
|
|
|
# <- CAPAB CHANMODES :admin=&a allowinvite=A autoop=w ban=b
|
2019-05-03 01:51:06 +02:00
|
|
|
# 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
|
|
|
|
# <- 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
|
|
|
|
|
|
|
|
# insp3:
|
|
|
|
# <- CAPAB CHANMODES :list:autoop=w list:ban=b list:banexception=e list:filter=g list:invex=I
|
|
|
|
# list:namebase=Z param-set:anticaps=B param-set:flood=f param-set:joinflood=j param-set:kicknorejoin=J
|
|
|
|
# param-set:limit=l param-set:nickflood=F param-set:redirect=L param:key=k prefix:10000:voice=+v
|
|
|
|
# prefix:20000:halfop=%h prefix:30000:op=@o prefix:40000:admin=&a prefix:50000:founder=~q
|
|
|
|
# prefix:9000000:official-join=!Y simple:allowinvite=A simple:auditorium=u simple:blockcolor=c
|
|
|
|
# simple:c_registered=r simple:censor=G simple:inviteonly=i simple:moderated=m simple:noctcp=C
|
|
|
|
# simple:noextmsg=n simple:nokick=Q simple:noknock=K simple:nonick=N simple:nonotice=T
|
|
|
|
# simple:operonly=O simple:permanent=P simple:private=p simple:reginvite=R simple:regmoderated=M
|
|
|
|
# simple:secret=s simple:sslonly=z simple:stripcolor=S simple:topiclock=t
|
|
|
|
# <- CAPAB USERMODES :param-set:snomask=s simple:antiredirect=L simple:bot=B simple:callerid=g simple:cloak=x
|
|
|
|
# simple:deaf_commonchan=c simple:helpop=h simple:hidechans=I simple:hideoper=H simple:invisible=i
|
|
|
|
# simple:oper=o simple:regdeaf=R simple:u_censor=G simple:u_registered=r simple:u_stripcolor=S
|
|
|
|
# simple:wallops=w
|
|
|
|
|
|
|
|
mydict = self.cmodes if args[0] == 'CHANMODES' else self.umodes
|
2016-01-18 06:02:30 +01:00
|
|
|
|
|
|
|
# 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():
|
2019-05-03 01:51:06 +02:00
|
|
|
name, char = modepair.rsplit('=', 1)
|
|
|
|
|
2019-06-01 02:31:11 +02:00
|
|
|
if self.proto_ver >= 1205:
|
2019-05-03 01:51:06 +02:00
|
|
|
# Detect mode types from the mode type tag
|
|
|
|
parts = name.split(':')
|
|
|
|
modetype = parts[0]
|
|
|
|
name = parts[-1]
|
|
|
|
|
|
|
|
# Modes are divided into A, B, C, and D classes
|
|
|
|
# See http://www.irc.org/tech_docs/005.html
|
|
|
|
if modetype == 'simple': # No parameter
|
|
|
|
mydict['*D'] += char
|
|
|
|
elif modetype == 'param-set': # Only parameter when setting (e.g. cmode +l)
|
|
|
|
mydict['*C'] += char
|
|
|
|
elif modetype == 'param': # Always has parameter (e.g. cmode +k)
|
|
|
|
mydict['*B'] += char
|
|
|
|
elif modetype == 'list': # List modes like ban, except, invex, ...
|
|
|
|
mydict['*A'] += char
|
|
|
|
elif modetype == 'prefix': # prefix:30000:op=@o
|
|
|
|
if args[0] != 'CHANMODES': # This should never happen...
|
|
|
|
log.warning("(%s) Possible desync? Got a prefix type modepair %r but not for channel modes", self.name, modepair)
|
|
|
|
else:
|
|
|
|
# We don't do anything with prefix levels yet, let's just store them for future use
|
|
|
|
self._prefix_levels[name] = int(parts[1])
|
|
|
|
|
|
|
|
# Map mode names to their prefixes
|
|
|
|
self.prefixmodes[char[-1]] = char[0]
|
|
|
|
|
|
|
|
# Strip c_, u_ prefixes to be consistent with other protocols.
|
2019-06-01 03:13:21 +02:00
|
|
|
if name.startswith(('c_', 'u_')):
|
|
|
|
name = name[2:]
|
2016-05-15 20:05:02 +02:00
|
|
|
|
2017-12-18 22:05:12 +01:00
|
|
|
if name == 'reginvite': # Reginvite? That's an odd name.
|
2016-01-18 06:02:30 +01:00
|
|
|
name = 'regonly'
|
|
|
|
|
|
|
|
if name == 'founder': # Channel mode +q
|
2019-05-03 01:51:06 +02:00
|
|
|
# Founder, owner; same thing. m_customprefix allows you to name it anything you like,
|
|
|
|
# but PyLink uses the latter in its definitions
|
2016-01-18 06:02:30 +01:00
|
|
|
name = 'owner'
|
2016-04-25 06:08:07 +02:00
|
|
|
|
2017-12-18 22:05:12 +01:00
|
|
|
if name in ('repeat', 'kicknorejoin'):
|
|
|
|
# Suffix modes using inspircd-specific arguments so that it can
|
|
|
|
# be safely relayed.
|
|
|
|
name += '_insp'
|
|
|
|
|
2019-05-03 01:51:06 +02:00
|
|
|
# Add the mode char to our table
|
|
|
|
mydict[name] = char[-1]
|
2016-01-18 06:02:30 +01:00
|
|
|
|
|
|
|
elif args[0] == 'CAPABILITIES':
|
2019-05-03 02:06:04 +02:00
|
|
|
# insp20:
|
2016-01-18 06:02:30 +01:00
|
|
|
# <- 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
|
|
|
|
|
2019-05-03 02:06:04 +02:00
|
|
|
# insp3:
|
2019-05-03 01:51:06 +02:00
|
|
|
# CAPAB CAPABILITIES :NICKMAX=30 CHANMAX=64 MAXMODES=20 IDENTMAX=10 MAXQUIT=255 MAXTOPIC=307
|
|
|
|
# MAXKICK=255 MAXREAL=128 MAXAWAY=200 MAXHOST=64 CHALLENGE=xxxxxxxxx CASEMAPPING=ascii GLOBOPS=1
|
|
|
|
|
2016-01-18 06:02:30 +01:00
|
|
|
# First, turn the arguments into a dict
|
2017-06-28 02:15:27 +02:00
|
|
|
caps = self.parse_isupport(args[-1])
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug("(%s) capabilities list: %s", self.name, caps)
|
2016-01-18 06:02:30 +01:00
|
|
|
|
|
|
|
# Store the max nick and channel lengths
|
2019-05-03 01:51:06 +02:00
|
|
|
if 'NICKMAX' in caps:
|
|
|
|
self.maxnicklen = int(caps['NICKMAX'])
|
|
|
|
if 'CHANMAX' in caps:
|
|
|
|
self.maxchanlen = int(caps['CHANMAX'])
|
|
|
|
|
|
|
|
# InspIRCd 2 only: mode & prefix definitions are sent as CAPAB CAPABILITIES CHANMODES/USERMODES/PREFIX
|
2019-06-01 02:31:11 +02:00
|
|
|
if self.proto_ver < 1205:
|
2019-05-03 01:51:06 +02:00
|
|
|
if 'CHANMODES' in caps:
|
|
|
|
self.cmodes['*A'], self.cmodes['*B'], self.cmodes['*C'], self.cmodes['*D'] \
|
|
|
|
= caps['CHANMODES'].split(',')
|
|
|
|
if 'USERMODES' in caps:
|
|
|
|
self.umodes['*A'], self.umodes['*B'], self.umodes['*C'], self.umodes['*D'] \
|
|
|
|
= caps['USERMODES'].split(',')
|
|
|
|
if 'PREFIX' in caps:
|
|
|
|
# Separate the prefixes field (e.g. "(Yqaohv)!~&@%+") into a
|
|
|
|
# dict mapping mode characters to mode prefixes.
|
|
|
|
self.prefixmodes = self.parse_isupport_prefixes(caps['PREFIX'])
|
|
|
|
log.debug('(%s) self.prefixmodes set to %r', self.name,
|
|
|
|
self.prefixmodes)
|
2016-01-18 06:02:30 +01:00
|
|
|
|
2016-08-09 08:40:48 +02:00
|
|
|
elif args[0] == 'MODSUPPORT':
|
|
|
|
# <- CAPAB MODSUPPORT :m_alltime.so m_check.so m_chghost.so m_chgident.so m_chgname.so m_fullversion.so m_gecosban.so m_knock.so m_muteban.so m_nicklock.so m_nopartmsg.so m_opmoderated.so m_sajoin.so m_sanick.so m_sapart.so m_serverban.so m_services_account.so m_showwhois.so m_silence.so m_swhois.so m_uninvite.so m_watch.so
|
2017-12-22 21:38:48 +01:00
|
|
|
self._modsupport |= set(args[-1].split())
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2019-05-03 02:27:48 +02:00
|
|
|
def handle_kick(self, source, command, args):
|
|
|
|
"""Handles incoming KICKs."""
|
|
|
|
# InspIRCD 3 adds membership IDs to KICK messages when forwarding across servers
|
|
|
|
# <- :3INAAAAAA KICK #endlessvoid 3INAAAAAA :test (local)
|
|
|
|
# <- :3INAAAAAA KICK #endlessvoid 7PYAAAAAA 0 :test (remote)
|
2019-06-01 02:31:11 +02:00
|
|
|
if self.proto_ver >= 1205 and len(args) > 3:
|
2019-05-03 02:27:48 +02:00
|
|
|
del args[2]
|
|
|
|
|
|
|
|
return super().handle_kick(source, command, args)
|
|
|
|
|
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
|
2017-08-10 01:55:02 +02:00
|
|
|
if len(args) >= 2:
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(args[1], 'PONG %s %s' % (args[1], source), queue=False)
|
2017-08-10 01:55:02 +02:00
|
|
|
else:
|
|
|
|
self._send_with_prefix(self.sid, 'PONG %s' % source, queue=False)
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
def handle_fjoin(self, servernumeric, command, args):
|
|
|
|
"""Handles incoming FJOIN commands (InspIRCd equivalent of JOIN/SJOIN)."""
|
2019-05-03 02:27:48 +02:00
|
|
|
# insp2:
|
|
|
|
# <- :70M FJOIN #chat 1423790411 +AFPfjnt 6:5 7:5 9:5 :o,1SRAABIT4 v,1IOAAF53R <...>
|
|
|
|
# insp3:
|
|
|
|
# <- :3IN FJOIN #test 1556842195 +nt :o,3INAAAAAA:4
|
2017-08-08 06:54:33 +02:00
|
|
|
channel = args[0]
|
2017-08-25 11:11:48 +02:00
|
|
|
chandata = self._channels[channel].deepcopy()
|
2015-09-06 03:00:57 +02:00
|
|
|
# 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
|
|
|
modestring = args[2:-1] or args[2]
|
2017-06-30 07:56:14 +02:00
|
|
|
parsedmodes = self.parse_modes(channel, modestring)
|
2015-09-06 03:00:57 +02:00
|
|
|
namelist = []
|
2016-06-23 07:26:25 +02:00
|
|
|
|
|
|
|
# Keep track of other modes that are added due to prefix modes being joined too.
|
|
|
|
changedmodes = set(parsedmodes)
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
for user in userlist:
|
|
|
|
modeprefix, user = user.split(',', 1)
|
2016-01-28 02:49:00 +01:00
|
|
|
|
2019-06-01 02:31:11 +02:00
|
|
|
if self.proto_ver >= 1205:
|
2019-05-03 02:27:48 +02:00
|
|
|
# XXX: we don't handle membership IDs yet
|
|
|
|
user = user.split(':', 1)[0]
|
|
|
|
|
2016-01-28 02:49:00 +01:00
|
|
|
# Don't crash when we get an invalid UID.
|
2017-06-25 11:03:12 +02:00
|
|
|
if user not in self.users:
|
2016-01-28 02:49:00 +01:00
|
|
|
log.debug('(%s) handle_fjoin: tried to introduce user %s not in our user list, ignoring...',
|
2017-06-25 11:03:12 +02:00
|
|
|
self.name, user)
|
2016-01-28 02:49:00 +01:00
|
|
|
continue
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
namelist.append(user)
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[user].channels.add(channel)
|
2016-06-23 07:26:25 +02:00
|
|
|
|
|
|
|
# Only save mode changes if the remote has lower TS than us.
|
|
|
|
changedmodes |= {('+%s' % mode, user) for mode in modeprefix}
|
|
|
|
|
2017-08-25 11:11:48 +02:00
|
|
|
self._channels[channel].users.add(user)
|
2016-06-23 07:26:25 +02:00
|
|
|
|
2017-02-06 06:05:50 +01:00
|
|
|
# Statekeeping with timestamps. Note: some service packages (Anope 1.8) send a trailing
|
|
|
|
# 'd' after the timestamp, which we should strip out to prevent int() from erroring.
|
|
|
|
# This is technically valid in InspIRCd S2S because atoi() ignores non-digit characters,
|
|
|
|
# but it's strange behaviour either way...
|
|
|
|
# <- :3AX FJOIN #monitor 1485462109d + :,3AXAAAAAK
|
|
|
|
their_ts = int(''.join(char for char in args[1] if char.isdigit()))
|
|
|
|
|
2017-08-25 11:11:48 +02:00
|
|
|
our_ts = self._channels[channel].ts
|
2016-07-11 06:35:17 +02:00
|
|
|
self.updateTS(servernumeric, channel, their_ts, changedmodes)
|
2016-06-23 07:26:25 +02:00
|
|
|
|
2016-08-28 03:56:36 +02:00
|
|
|
return {'channel': channel, 'users': namelist, 'modes': parsedmodes, 'ts': their_ts,
|
2016-09-03 02:52:19 +02:00
|
|
|
'channeldata': chandata}
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2019-05-03 02:27:48 +02:00
|
|
|
def handle_ijoin(self, source, command, args):
|
|
|
|
"""Handles InspIRCd 3 joins with membership ID."""
|
|
|
|
# insp3:
|
2019-06-01 02:46:36 +02:00
|
|
|
# EX: regular /join on an existing channel
|
2019-05-03 02:27:48 +02:00
|
|
|
# <- :3INAAAAAA IJOIN #valhalla 6
|
2019-06-01 02:46:36 +02:00
|
|
|
|
|
|
|
# EX: /ojoin on an existing channel
|
|
|
|
# <- :3INAAAAAA IJOIN #valhalla 7 1559348434 Yo
|
|
|
|
|
|
|
|
# From insp3 source:
|
|
|
|
# <- :<uid> IJOIN <chan> <membid> [<ts> [<flags>]]
|
|
|
|
# args idx: 0 1 2 3
|
|
|
|
|
2019-05-03 02:27:48 +02:00
|
|
|
# For now we don't care about the membership ID
|
|
|
|
channel = args[0]
|
|
|
|
self.users[source].channels.add(channel)
|
|
|
|
self._channels[channel].users.add(source)
|
|
|
|
|
2019-06-01 02:46:36 +02:00
|
|
|
# Apply prefix modes if they exist and the TS check passes
|
|
|
|
if len(args) >= 4 and int(args[2]) <= self._channels[channel].ts:
|
|
|
|
self.apply_modes(source, {('+%s' % mode, source) for mode in args[3]})
|
|
|
|
|
2019-05-03 02:27:48 +02:00
|
|
|
return {'channel': channel, 'users': [source], 'modes':
|
|
|
|
self._channels[channel].modes}
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
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]
|
2018-05-27 01:22:36 +02:00
|
|
|
|
|
|
|
ts = int(ts)
|
|
|
|
|
2017-07-07 12:18:40 +02:00
|
|
|
self._check_nick_collision(nick)
|
2015-09-06 03:00:57 +02:00
|
|
|
realname = args[-1]
|
2018-05-27 01:22:36 +02:00
|
|
|
self.users[uid] = userobj = User(self, nick, ts, uid, numeric, ident, host, realname, realhost, ip)
|
2016-07-02 06:01:59 +02:00
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
parsedmodes = self.parse_modes(uid, [args[8], args[9]])
|
|
|
|
self.apply_modes(uid, parsedmodes)
|
2016-07-02 06:01:59 +02:00
|
|
|
|
2017-07-08 05:02:37 +02:00
|
|
|
self._check_oper_status_change(uid, parsedmodes)
|
2016-07-02 06:01:59 +02:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
self.servers[numeric].users.add(uid)
|
2015-09-06 03:00:57 +02:00
|
|
|
return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip}
|
|
|
|
|
2019-06-01 03:12:06 +02:00
|
|
|
def handle_server(self, source, command, args):
|
2015-09-06 03:00:57 +02:00
|
|
|
"""Handles incoming SERVER commands (introduction of servers)."""
|
2016-01-18 06:02:30 +01:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
if self.uplink is None:
|
2016-01-18 06:02:30 +01:00
|
|
|
# <- SERVER whatever.net abcdefgh 0 10X :some server description
|
|
|
|
servername = args[0].lower()
|
2019-06-01 03:12:06 +02:00
|
|
|
source = args[3]
|
2016-01-18 06:02:30 +01:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
if args[1] != self.serverdata['recvpass']:
|
2016-01-18 06:02:30 +01:00
|
|
|
# Check if recvpass is correct
|
2017-07-03 07:52:46 +02:00
|
|
|
raise ProtocolError('recvpass from uplink server %s does not match configuration!' % servername)
|
2016-01-18 06:02:30 +01:00
|
|
|
|
|
|
|
sdesc = args[-1]
|
2019-06-01 03:12:06 +02:00
|
|
|
self.servers[source] = Server(self, None, servername, desc=sdesc)
|
|
|
|
self.uplink = source
|
|
|
|
log.debug('(%s) inspircd: found uplink %s', self.name, self.uplink)
|
2016-01-18 06:02:30 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
# Other server introductions.
|
2019-06-01 03:12:06 +02:00
|
|
|
# insp20:
|
2015-09-06 03:00:57 +02:00
|
|
|
# <- :00A SERVER test.server * 1 00C :testing raw message syntax
|
2019-06-01 03:12:06 +02:00
|
|
|
# insp3:
|
|
|
|
# <- :3IN SERVER services.abc.local 0SV :Some server
|
2015-09-06 03:00:57 +02:00
|
|
|
servername = args[0].lower()
|
2019-06-01 03:12:06 +02:00
|
|
|
if self.proto_ver >= 1205:
|
|
|
|
sid = args[1] # insp3
|
|
|
|
else:
|
|
|
|
sid = args[3] # insp20
|
2015-09-06 03:00:57 +02:00
|
|
|
sdesc = args[-1]
|
2019-06-01 03:12:06 +02:00
|
|
|
self.servers[sid] = Server(self, source, servername, desc=sdesc)
|
2016-01-18 06:02:30 +01:00
|
|
|
|
2019-06-01 03:12:06 +02:00
|
|
|
return {'name': servername, 'sid': sid, 'text': sdesc}
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
def handle_fmode(self, numeric, command, args):
|
|
|
|
"""Handles the FMODE command, used for channel mode changes."""
|
|
|
|
# <- :70MAAAAAA FMODE #chat 1433653462 +hhT 70MAAAAAA 70MAAAAAD
|
2017-08-08 06:54:33 +02:00
|
|
|
channel = args[0]
|
2017-08-25 11:11:48 +02:00
|
|
|
oldobj = self._channels[channel].deepcopy()
|
2015-09-06 03:00:57 +02:00
|
|
|
modes = args[2:]
|
2017-06-30 07:56:14 +02:00
|
|
|
changedmodes = self.parse_modes(channel, modes)
|
|
|
|
self.apply_modes(channel, changedmodes)
|
2015-09-06 03:00:57 +02:00
|
|
|
ts = int(args[1])
|
2015-09-13 22:47:18 +02:00
|
|
|
return {'target': channel, 'modes': changedmodes, 'ts': ts,
|
2016-09-13 05:12:21 +02:00
|
|
|
'channeldata': oldobj}
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2017-07-12 16:23:00 +02:00
|
|
|
def handle_idle(self, source, command, args):
|
2016-07-11 06:55:16 +02:00
|
|
|
"""
|
|
|
|
Handles the IDLE command, sent between servers in remote WHOIS queries.
|
|
|
|
"""
|
2015-09-06 03:00:57 +02:00
|
|
|
# <- :70MAAAAAA IDLE 1MLAAAAIG
|
|
|
|
# -> :1MLAAAAIG IDLE 70MAAAAAA 1433036797 319
|
2017-07-12 16:23:00 +02:00
|
|
|
|
2017-07-12 17:28:32 +02:00
|
|
|
if self.serverdata.get('force_whois_extensions', True):
|
|
|
|
return {'target': args[0], 'parse_as': 'WHOIS'}
|
|
|
|
|
2017-07-12 16:44:18 +02:00
|
|
|
# Allow hiding the startup time if set to do so (if both idle and signon time is 0, InspIRCd omits
|
|
|
|
# showing this line).
|
2017-07-12 16:49:19 +02:00
|
|
|
target = args[0]
|
|
|
|
start_time = self.start_ts if (conf.conf['pylink'].get('whois_show_startup_time', True) and
|
|
|
|
self.get_service_bot(target)) else 0
|
2017-07-12 16:44:18 +02:00
|
|
|
|
2017-07-12 16:23:00 +02:00
|
|
|
# First arg = source, second = signon time, third = idle time
|
2017-07-12 16:49:19 +02:00
|
|
|
self._send_with_prefix(target, 'IDLE %s %s 0' % (source, start_time))
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2019-05-03 03:05:38 +02:00
|
|
|
def handle_ftopic(self, source, command, args):
|
2015-09-06 03:00:57 +02:00
|
|
|
"""Handles incoming FTOPIC (sets topic on burst)."""
|
2019-05-03 03:05:38 +02:00
|
|
|
# insp2 (only used for server senders):
|
2015-09-06 03:00:57 +02:00
|
|
|
# <- :70M FTOPIC #channel 1434510754 GLo|o|!GLolol@escape.the.dreamland.ca :Some channel topic
|
2019-05-03 03:05:38 +02:00
|
|
|
|
|
|
|
# insp3 (used for server AND user senders):
|
|
|
|
# <- :3IN FTOPIC #qwerty 1556828864 1556844505 GL!gl@midnight-umk.of4.0.127.IP :1234abcd
|
|
|
|
# <- :3INAAAAAA FTOPIC #qwerty 1556828864 1556844248 :topic text
|
|
|
|
# chan creation time ^ ^ topic set time (the one we want)
|
2017-08-08 06:54:33 +02:00
|
|
|
channel = args[0]
|
2019-05-03 03:05:38 +02:00
|
|
|
|
2019-06-01 02:31:11 +02:00
|
|
|
if self.proto_ver >= 1205:
|
2019-05-03 03:05:38 +02:00
|
|
|
ts = args[2]
|
|
|
|
if source in self.users:
|
|
|
|
setter = source
|
|
|
|
else:
|
|
|
|
setter = args[3]
|
|
|
|
else:
|
|
|
|
ts = args[1]
|
|
|
|
setter = args[2]
|
|
|
|
ts = int(ts)
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
topic = args[-1]
|
2017-08-25 11:11:48 +02:00
|
|
|
self._channels[channel].topic = topic
|
|
|
|
self._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
|
|
|
|
|
2016-07-02 06:01:59 +02:00
|
|
|
def handle_opertype(self, target, command, args):
|
2015-09-06 03:00:57 +02:00
|
|
|
"""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
|
2016-07-02 06:01:59 +02:00
|
|
|
# Replace escaped _ in opertypes with spaces for InspIRCd 2.0.
|
|
|
|
opertype = args[0].replace("_", " ")
|
|
|
|
|
|
|
|
# Set umode +o on the target.
|
2015-09-06 03:00:57 +02:00
|
|
|
omode = [('+o', None)]
|
2017-06-30 07:56:14 +02:00
|
|
|
self.apply_modes(target, omode)
|
2016-07-02 06:01:59 +02:00
|
|
|
|
|
|
|
# Call the CLIENT_OPERED hook that protocols use. The MODE hook
|
|
|
|
# payload is returned below.
|
2017-06-30 07:56:14 +02:00
|
|
|
self.call_hooks([target, 'CLIENT_OPERED', {'text': opertype}])
|
2016-07-02 06:01:59 +02:00
|
|
|
return {'target': target, 'modes': omode}
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
def handle_fident(self, numeric, command, args):
|
|
|
|
"""Handles FIDENT, used for denoting ident changes."""
|
|
|
|
# <- :70MAAAAAB FIDENT test
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[numeric].ident = newident = args[0]
|
2015-09-06 03:00:57 +02:00
|
|
|
return {'target': numeric, 'newident': newident}
|
|
|
|
|
|
|
|
def handle_fhost(self, numeric, command, args):
|
|
|
|
"""Handles FHOST, used for denoting hostname changes."""
|
2017-01-13 06:00:24 +01:00
|
|
|
# <- :70MAAAAAB FHOST some.host
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[numeric].host = newhost = args[0]
|
2015-09-06 03:00:57 +02:00
|
|
|
return {'target': numeric, 'newhost': newhost}
|
|
|
|
|
|
|
|
def handle_fname(self, numeric, command, args):
|
|
|
|
"""Handles FNAME, used for denoting real name/gecos changes."""
|
|
|
|
# <- :70MAAAAAB FNAME :afdsafasf
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[numeric].realname = newgecos = args[0]
|
2015-09-06 03:00:57 +02:00
|
|
|
return {'target': numeric, 'newgecos': newgecos}
|
|
|
|
|
|
|
|
def handle_endburst(self, numeric, command, args):
|
|
|
|
"""ENDBURST handler; sends a hook with empty contents."""
|
2017-08-31 04:18:39 +02:00
|
|
|
self.servers[numeric].has_eob = True
|
2017-08-31 04:39:57 +02:00
|
|
|
if numeric == self.uplink:
|
|
|
|
self.connected.set()
|
2015-09-06 03:00:57 +02:00
|
|
|
return {}
|
|
|
|
|
|
|
|
def handle_away(self, numeric, command, args):
|
|
|
|
"""Handles incoming AWAY messages."""
|
|
|
|
# <- :1MLAAAAIG AWAY 1439371390 :Auto-away
|
|
|
|
try:
|
|
|
|
ts = args[0]
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[numeric].away = text = args[1]
|
2015-09-06 03:00:57 +02:00
|
|
|
return {'text': text, 'ts': ts}
|
|
|
|
except IndexError: # User is unsetting away status
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[numeric].away = ''
|
2015-09-06 03:00:57 +02:00
|
|
|
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.
|
2017-06-17 02:13:04 +02:00
|
|
|
target = self._get_SID(args[0])
|
2017-06-30 07:56:14 +02:00
|
|
|
if self.is_internal_server(target):
|
2015-12-25 04:52:52 +01:00
|
|
|
# The target has to be one of our servers in order to work...
|
2017-06-25 11:03:12 +02:00
|
|
|
uplink = self.servers[target].uplink
|
2017-06-30 07:56:14 +02:00
|
|
|
reason = 'Requested by %s' % self.get_hostmask(numeric)
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(uplink, 'SQUIT %s :%s' % (target, reason))
|
2015-12-25 04:52:52 +01:00
|
|
|
return self.handle_squit(numeric, 'SQUIT', [target, reason])
|
|
|
|
else:
|
|
|
|
log.debug("(%s) Got RSQUIT for '%s', which is either invalid or not "
|
2017-06-25 11:03:12 +02:00
|
|
|
"a server of ours!", self.name, args[0])
|
2015-12-25 04:52:52 +01:00
|
|
|
|
2016-02-21 02:54:46 +01:00
|
|
|
def handle_metadata(self, numeric, command, args):
|
|
|
|
"""
|
2019-06-01 04:01:25 +02:00
|
|
|
Handles the METADATA command, used by servers to send metadata for various objects.
|
2016-02-21 02:54:46 +01:00
|
|
|
"""
|
|
|
|
uid = args[0]
|
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
if args[1] == 'accountname' and uid in self.users:
|
2016-02-21 02:54:46 +01:00
|
|
|
# <- :00A METADATA 1MLAAAJET accountname :
|
|
|
|
# <- :00A METADATA 1MLAAAJET accountname :tester
|
|
|
|
# Sets the services login name of the client.
|
2017-06-30 07:56:14 +02:00
|
|
|
self.call_hooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': args[-1]}])
|
2019-06-01 04:01:25 +02:00
|
|
|
|
2018-01-25 18:52:29 +01:00
|
|
|
elif args[1] == 'modules' and numeric == self.uplink:
|
|
|
|
# Note: only handle METADATA from our uplink; otherwise leaf servers unloading modules
|
|
|
|
# while shutting down will corrupt the state.
|
2017-12-22 21:38:48 +01:00
|
|
|
# <- :70M METADATA * modules :-m_chghost.so
|
|
|
|
# <- :70M METADATA * modules :+m_chghost.so
|
|
|
|
for module in args[-1].split():
|
|
|
|
if module.startswith('-'):
|
|
|
|
log.debug('(%s) Removing module %s', self.name, module[1:])
|
|
|
|
self._modsupport.discard(module[1:])
|
|
|
|
elif module.startswith('+'):
|
|
|
|
log.debug('(%s) Adding module %s', self.name, module[1:])
|
|
|
|
self._modsupport.add(module[1:])
|
|
|
|
else:
|
|
|
|
log.warning('(%s) Got unknown METADATA modules string: %r', self.name, args[-1])
|
2016-02-21 02:54:46 +01:00
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
2016-07-29 06:05:59 +02:00
|
|
|
def handle_sakick(self, source, command, args):
|
|
|
|
"""Handles forced kicks (SAKICK)."""
|
|
|
|
# <- :1MLAAAAAD ENCAP 0AL SAKICK #test 0ALAAAAAB :test
|
|
|
|
# ENCAP -> SAKICK args: ['#test', '0ALAAAAAB', 'test']
|
|
|
|
|
|
|
|
target = args[1]
|
2017-08-08 06:54:33 +02:00
|
|
|
channel = args[0]
|
2016-07-29 06:05:59 +02:00
|
|
|
try:
|
|
|
|
reason = args[2]
|
|
|
|
except IndexError:
|
|
|
|
# Kick reason is optional, strange...
|
2017-06-30 07:56:14 +02:00
|
|
|
reason = self.get_friendly_name(source)
|
2016-07-29 06:05:59 +02:00
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
if not self.is_internal_client(target):
|
2017-06-25 11:03:12 +02:00
|
|
|
log.warning("(%s) Got SAKICK for client that not one of ours: %s", self.name, target)
|
2016-07-29 06:05:59 +02:00
|
|
|
return
|
|
|
|
else:
|
|
|
|
# Like RSQUIT, SAKICK requires that the receiving server acknowledge that a kick has
|
|
|
|
# happened. This comes from the server hosting the target client.
|
2017-06-30 07:56:14 +02:00
|
|
|
server = self.get_server(target)
|
2016-07-29 06:05:59 +02:00
|
|
|
|
|
|
|
self.kick(server, channel, target, reason)
|
|
|
|
return {'channel': channel, 'target': target, 'text': reason}
|
2016-07-12 08:21:08 +02:00
|
|
|
|
2016-08-13 04:36:40 +02:00
|
|
|
def handle_alltime(self, source, command, args):
|
|
|
|
"""Handles /ALLTIME requests."""
|
|
|
|
# -> :9PYAAAAAA ENCAP * ALLTIME
|
|
|
|
# <- :70M PUSH 0ALAAAAAC ::midnight.vpn NOTICE PyLink-devel :System time is 2016-08-13 02:23:06 (1471054986) on midnight.vpn
|
|
|
|
|
|
|
|
# XXX: We override notice() here because that abstraction doesn't allow messages from servers.
|
|
|
|
timestring = '%s (%s)' % (time.strftime('%Y-%m-%d %H:%M:%S'), int(time.time()))
|
2017-06-25 11:03:12 +02:00
|
|
|
self._send_with_prefix(self.sid, 'NOTICE %s :System time is %s on %s' % (source, timestring, self.hostname()))
|
2016-08-13 04:36:40 +02:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
Class = InspIRCdProtocol
|