2015-12-26 23:45:28 +01:00
|
|
|
"""
|
|
|
|
ts6.py: PyLink protocol module for TS6-based IRCds (charybdis, elemental-ircd).
|
|
|
|
"""
|
|
|
|
|
2015-07-21 02:36:43 +02:00
|
|
|
import time
|
|
|
|
import re
|
|
|
|
|
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 TS6Protocol(TS6BaseProtocol):
|
2017-07-13 06:23:42 +02:00
|
|
|
|
|
|
|
SUPPORTED_IRCDS = ('charybdis', 'elemental', 'chatircd')
|
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
|
|
|
self.protocol_caps |= {'slash-in-hosts'}
|
2015-09-06 03:00:57 +02:00
|
|
|
self.casemapping = 'rfc1459'
|
2015-12-31 01:53:35 +01:00
|
|
|
self.hook_map = {'SJOIN': 'JOIN', 'TB': 'TOPIC', 'TMODE': 'MODE', 'BMASK': 'MODE',
|
2016-08-01 05:25:17 +02:00
|
|
|
'EUID': 'UID', 'RSFNC': 'SVSNICK', 'ETB': 'TOPIC'}
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2016-01-23 22:11:31 +01:00
|
|
|
# Track whether we've received end-of-burst from the uplink.
|
|
|
|
self.has_eob = False
|
|
|
|
|
2016-10-01 08:33:04 +02:00
|
|
|
self.required_caps = {'EUID', 'SAVE', 'TB', 'ENCAP', 'QS', 'CHW'}
|
|
|
|
|
2016-01-17 03:14:46 +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-09 04:51:14 +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
|
|
|
# EUID:
|
|
|
|
# parameters: nickname, hopcount, nickTS, umodes, username,
|
|
|
|
# visible hostname, IP address, UID, real hostname, account name, gecos
|
|
|
|
ts = ts or int(time.time())
|
2017-03-05 09:06:19 +01:00
|
|
|
realname = realname or conf.conf['bot']['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)
|
2017-07-01 06:44:31 +02:00
|
|
|
u = self.users[uid] = User(nick, ts, uid, server, ident=ident, host=host, realname=realname,
|
2016-03-26 20:55:23 +01:00
|
|
|
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, "EUID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} "
|
2015-09-06 03:00:57 +02:00
|
|
|
"{realhost} * :{realname}".format(ts=ts, host=host,
|
|
|
|
nick=nick, ident=ident, uid=uid,
|
|
|
|
modes=raw_modes, ip=ip, realname=realname,
|
|
|
|
realhost=realhost))
|
2016-04-25 06:16:41 +02:00
|
|
|
|
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
|
|
|
# JOIN:
|
|
|
|
# parameters: channelTS, channel, '+' (a plus sign)
|
2017-06-30 07:56:14 +02:00
|
|
|
if not self.is_internal_client(client):
|
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.')
|
2017-06-25 11:03:12 +02:00
|
|
|
self._send_with_prefix(client, "JOIN {ts} {channel} +".format(ts=self.channels[channel].ts, channel=channel))
|
|
|
|
self.channels[channel].users.add(client)
|
|
|
|
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-09 04:51:14 +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'), ('o', 100AAABBB'), ('v', '100AAADDD')])
|
2017-06-25 11:03:12 +02:00
|
|
|
sjoin(self.sid, '#test', [('o', self.pseudoclient.uid)])
|
2015-09-09 04:51:14 +02:00
|
|
|
"""
|
2015-09-06 03:00:57 +02:00
|
|
|
# https://github.com/grawity/irc-docs/blob/master/server/ts6.txt#L821
|
|
|
|
# parameters: channelTS, channel, simple modes, opt. mode parameters..., nicklist
|
|
|
|
|
|
|
|
# Broadcasts a channel creation or bursts a channel.
|
|
|
|
|
|
|
|
# The nicklist consists of users joining the channel, with status prefixes for
|
|
|
|
# their status ('@+', '@', '+' or ''), for example:
|
|
|
|
# '@+1JJAAAAAB +2JJAAAA4C 1JJAAAADS'. All users must be behind the source server
|
|
|
|
# so it is not possible to use this message to force users to join a channel.
|
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)
|
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
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
modes = set(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
|
|
|
|
|
|
|
# Get all the ban modes in a separate list. These are bursted using a separate BMASK
|
|
|
|
# command.
|
2017-06-25 11:03:12 +02:00
|
|
|
banmodes = {k: [] for k in self.cmodes['*A']}
|
2016-06-23 06:34:16 +02:00
|
|
|
regularmodes = []
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug('(%s) Unfiltered SJOIN modes: %s', self.name, modes)
|
2016-06-23 06:34:16 +02:00
|
|
|
for mode in modes:
|
|
|
|
modechar = mode[0][-1]
|
2017-06-25 11:03:12 +02:00
|
|
|
if modechar in self.cmodes['*A']:
|
2016-06-23 06:34:16 +02:00
|
|
|
# Mode character is one of 'beIq'
|
2017-06-25 11:03:12 +02:00
|
|
|
if (modechar, mode[1]) in self.channels[channel].modes:
|
2017-01-01 09:28:55 +01:00
|
|
|
# Don't reset modes that are already set.
|
|
|
|
continue
|
|
|
|
|
2017-01-12 08:08:39 +01:00
|
|
|
banmodes[modechar].append(mode[1])
|
2016-06-23 06:34:16 +02:00
|
|
|
else:
|
|
|
|
regularmodes.append(mode)
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug('(%s) Filtered SJOIN modes to be regular modes: %s, banmodes: %s', self.name, regularmodes, banmodes)
|
2016-06-23 06:34:16 +02:00
|
|
|
|
|
|
|
changedmodes = modes
|
2016-06-28 08:13:39 +02:00
|
|
|
while users[:12]:
|
2015-09-06 03:00:57 +02:00
|
|
|
uids = []
|
|
|
|
namelist = []
|
|
|
|
# We take <users> as a list of (prefixmodes, uid) pairs.
|
2016-06-28 08:13:39 +02:00
|
|
|
for userpair in users[:12]:
|
2015-09-06 03:00:57 +02:00
|
|
|
assert len(userpair) == 2, "Incorrect format of userpair: %r" % userpair
|
|
|
|
prefixes, user = userpair
|
|
|
|
prefixchars = ''
|
|
|
|
for prefix in prefixes:
|
2017-06-25 11:03:12 +02:00
|
|
|
pr = self.prefixmodes.get(prefix)
|
2015-09-06 03:00:57 +02:00
|
|
|
if pr:
|
|
|
|
prefixchars += pr
|
2016-06-23 06:34:16 +02:00
|
|
|
changedmodes.add(('+%s' % prefix, user))
|
2015-09-06 03:00:57 +02:00
|
|
|
namelist.append(prefixchars+user)
|
|
|
|
uids.append(user)
|
|
|
|
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-28 08:13:39 +02:00
|
|
|
users = users[12:]
|
2015-09-06 03:00:57 +02:00
|
|
|
namelist = ' '.join(namelist)
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(server, "SJOIN {ts} {channel} {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(regularmodes)))
|
2017-06-25 11:03:12 +02:00
|
|
|
self.channels[channel].users.update(uids)
|
2016-06-23 06:34:16 +02:00
|
|
|
|
|
|
|
# Now, burst bans.
|
|
|
|
# <- :42X BMASK 1424222769 #dev b :*!test@*.isp.net *!badident@*
|
|
|
|
for bmode, bans in banmodes.items():
|
2016-06-28 08:35:56 +02:00
|
|
|
# Max 15-3 = 12 bans per line to prevent cut off. (TS6 allows a max of 15 parameters per
|
|
|
|
# line)
|
2016-06-23 06:34:16 +02:00
|
|
|
if bans:
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug('(%s) sjoin: bursting mode %s with bans %s, ts:%s', self.name, bmode, bans, ts)
|
2017-01-12 08:08:39 +01:00
|
|
|
msgprefix = ':{sid} BMASK {ts} {channel} {bmode} :'.format(sid=server, ts=ts,
|
|
|
|
channel=channel, bmode=bmode)
|
|
|
|
# Actually, we cut off at 17 arguments/line, since the prefix and command name don't count.
|
2017-07-08 05:13:52 +02:00
|
|
|
for msg in utils.wrapArguments(msgprefix, bans, self.S2S_BUFSIZE, max_args_per_line=17):
|
2017-06-25 11:03:12 +02:00
|
|
|
self.send(msg)
|
2016-06-23 06:34:16 +02:00
|
|
|
|
2016-07-11 06:35:17 +02:00
|
|
|
self.updateTS(server, channel, ts, changedmodes)
|
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."""
|
2016-04-08 03:23:21 +02:00
|
|
|
# c <- :0UYAAAAAA TMODE 0 #a +o 0T4AAAAAC
|
|
|
|
# u <- :0UYAAAAAA MODE 0UYAAAAAA :-Facdefklnou
|
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-06-30 07:56:14 +02:00
|
|
|
self.apply_modes(target, modes)
|
2015-09-13 08:35:20 +02:00
|
|
|
modes = list(modes)
|
2016-01-17 02:08:17 +01:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
if utils.isChannel(target):
|
2017-08-08 06:54:33 +02:00
|
|
|
ts = ts or self.channels[target].ts
|
2015-09-06 03:00:57 +02:00
|
|
|
# TMODE:
|
|
|
|
# parameters: channelTS, channel, cmode changes, opt. cmode parameters...
|
|
|
|
|
|
|
|
# On output, at most ten cmode parameters should be sent; if there are more,
|
|
|
|
# multiple TMODE messages should be sent.
|
2017-01-09 06:19:54 +01:00
|
|
|
msgprefix = ':%s TMODE %s %s ' % (numeric, ts, target)
|
2017-07-08 05:13:52 +02:00
|
|
|
bufsize = self.S2S_BUFSIZE - len(msgprefix)
|
2017-01-09 06:19:54 +01:00
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
for modestr in self.wrap_modes(modes, bufsize, max_modes_per_msg=10):
|
2017-06-25 11:03:12 +02:00
|
|
|
self.send(msgprefix + modestr)
|
2015-09-06 03:00:57 +02:00
|
|
|
else:
|
2017-06-30 07:56:14 +02:00
|
|
|
joinedmodes = self.join_modes(modes)
|
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
|
|
|
|
2017-07-01 06:29:11 +02:00
|
|
|
def topic_burst(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."""
|
2017-06-30 07:56:14 +02:00
|
|
|
if not self.is_internal_server(numeric):
|
2016-01-10 02:44:05 +01:00
|
|
|
raise LookupError('No such PyLink server exists.')
|
2015-09-06 03:00:57 +02:00
|
|
|
# TB
|
|
|
|
# capab: TB
|
|
|
|
# source: server
|
|
|
|
# propagation: broadcast
|
|
|
|
# parameters: channel, topicTS, opt. topic setter, topic
|
2017-06-25 11:03:12 +02:00
|
|
|
ts = self.channels[target].ts
|
|
|
|
servername = self.servers[numeric].name
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(numeric, 'TB %s %s %s :%s' % (target, ts, servername, text))
|
2017-06-25 11:03:12 +02:00
|
|
|
self.channels[target].topic = text
|
|
|
|
self.channels[target].topicset = True
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2016-01-17 01:38:27 +01:00
|
|
|
def invite(self, numeric, target, channel):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Sends an INVITE 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 11:03:12 +02:00
|
|
|
self._send_with_prefix(numeric, 'INVITE %s %s %s' % (target, channel, self.channels[channel].ts))
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2016-01-17 01:41:17 +01:00
|
|
|
def knock(self, numeric, target, text):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Sends a KNOCK from a PyLink client."""
|
2017-06-25 11:03:12 +02:00
|
|
|
if 'KNOCK' not in self.caps:
|
2016-01-17 01:41:17 +01:00
|
|
|
log.debug('(%s) knock: Dropping KNOCK to %r since the IRCd '
|
2017-06-25 11:03:12 +02:00
|
|
|
'doesn\'t support it.', self.name, target)
|
2015-09-06 03:00:57 +02:00
|
|
|
return
|
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.')
|
2015-09-06 03:00:57 +02:00
|
|
|
# No text value is supported here; drop it.
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(numeric, 'KNOCK %s' % target)
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2017-07-17 15:11:49 +02:00
|
|
|
def set_server_ban(self, source, duration, user='*', host='*', reason='User banned'):
|
|
|
|
"""
|
|
|
|
Sets a server ban.
|
|
|
|
"""
|
|
|
|
# source: user
|
|
|
|
# parameters: target server mask, duration, user mask, host mask, reason
|
|
|
|
assert not (user == host == '*'), "Refusing to set ridiculous ban on *@*"
|
|
|
|
|
|
|
|
if not source in self.users:
|
|
|
|
log.debug('(%s) Forcing KLINE sender to %s as TS6 does not allow KLINEs from servers', self.name, self.pseudoclient.uid)
|
|
|
|
source = self.pseudoclient.uid
|
|
|
|
|
|
|
|
self._send_with_prefix(source, 'ENCAP * KLINE %s %s %s :%s' % (duration, user, host, reason))
|
|
|
|
|
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 hostname of any connected client."""
|
2015-09-06 03:00:57 +02:00
|
|
|
field = field.upper()
|
|
|
|
if field == 'HOST':
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[target].host = text
|
|
|
|
self._send_with_prefix(self.sid, 'CHGHOST %s :%s' % (target, text))
|
2017-06-30 07:56:14 +02:00
|
|
|
if not self.is_internal_client(target):
|
2015-12-31 00:54:09 +01:00
|
|
|
# If the target isn't one of our clients, send hook payload
|
|
|
|
# for other plugins to listen to.
|
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}])
|
2015-09-06 03:00:57 +02:00
|
|
|
else:
|
2015-12-31 00:54:09 +01:00
|
|
|
raise NotImplementedError("Changing field %r of a client is "
|
|
|
|
"unsupported by this protocol." % field)
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2016-01-17 03:14:46 +01:00
|
|
|
### Core / handlers
|
|
|
|
|
2017-06-25 10:12:22 +02:00
|
|
|
def post_connect(self):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Initializes a connection to a server."""
|
2017-06-25 11:03:12 +02:00
|
|
|
ts = self.start_ts
|
2016-03-20 02:19:41 +01:00
|
|
|
self.has_eob = False
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
f = self.send
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
# https://github.com/grawity/irc-docs/blob/master/server/ts6.txt#L80
|
2016-04-18 20:22:54 +02:00
|
|
|
chary_cmodes = { # TS6 generic modes (note that +p is noknock instead of private):
|
2015-09-06 03:00:57 +02:00
|
|
|
'op': 'o', 'voice': 'v', 'ban': 'b', 'key': 'k', 'limit':
|
|
|
|
'l', 'moderated': 'm', 'noextmsg': 'n', 'noknock': 'p',
|
2016-06-20 06:13:14 +02:00
|
|
|
'secret': 's', 'topiclock': 't', 'inviteonly': 'i',
|
2015-09-06 03:00:57 +02:00
|
|
|
# charybdis-specific modes:
|
|
|
|
'quiet': 'q', 'redirect': 'f', 'freetarget': 'F',
|
|
|
|
'joinflood': 'j', 'largebanlist': 'L', 'permanent': 'P',
|
2016-05-15 20:05:02 +02:00
|
|
|
'noforwards': 'Q', 'stripcolor': 'c', 'allowinvite':
|
2017-07-13 06:06:11 +02:00
|
|
|
'g', 'opmoderated': 'z', 'noctcp': 'C', 'ssl': 'Z',
|
2015-09-06 03:00:57 +02:00
|
|
|
# charybdis-specific modes provided by EXTENSIONS
|
|
|
|
'operonly': 'O', 'adminonly': 'A', 'sslonly': 'S',
|
2016-03-08 06:38:57 +01:00
|
|
|
'nonotice': 'T',
|
2015-09-06 03:00:57 +02:00
|
|
|
# Now, map all the ABCD type modes:
|
2016-04-18 20:22:54 +02:00
|
|
|
'*A': 'beIq', '*B': 'k', '*C': 'lfj', '*D': 'mnprstFLPQcgzCOAST'}
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
if self.serverdata.get('use_owner'):
|
2015-09-06 03:00:57 +02:00
|
|
|
chary_cmodes['owner'] = 'y'
|
2017-06-25 11:03:12 +02:00
|
|
|
self.prefixmodes['y'] = '~'
|
|
|
|
if self.serverdata.get('use_admin'):
|
2015-09-06 03:00:57 +02:00
|
|
|
chary_cmodes['admin'] = 'a'
|
2017-06-25 11:03:12 +02:00
|
|
|
self.prefixmodes['a'] = '!'
|
|
|
|
if self.serverdata.get('use_halfop'):
|
2015-09-06 03:00:57 +02:00
|
|
|
chary_cmodes['halfop'] = 'h'
|
2017-06-25 11:03:12 +02:00
|
|
|
self.prefixmodes['h'] = '%'
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
self.cmodes = chary_cmodes
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2016-04-18 20:22:54 +02:00
|
|
|
# Define supported user modes
|
2016-05-15 20:05:02 +02:00
|
|
|
chary_umodes = {'deaf': 'D', 'servprotect': 'S', 'admin': 'a',
|
2015-09-06 03:00:57 +02:00
|
|
|
'invisible': 'i', 'oper': 'o', 'wallops': 'w',
|
2016-05-15 20:05:02 +02:00
|
|
|
'snomask': 's', 'noforward': 'Q', 'regdeaf': 'R',
|
2016-04-30 07:39:37 +02:00
|
|
|
'callerid': 'g', 'operwall': 'z', 'locops': 'l',
|
2016-06-01 05:46:09 +02:00
|
|
|
'cloak': 'x', 'override': 'p',
|
2016-04-30 07:39:37 +02:00
|
|
|
# Now, map all the ABCD type modes:
|
2016-06-01 05:46:09 +02:00
|
|
|
'*A': '', '*B': '', '*C': '', '*D': 'DSaiowsQRgzlxp'}
|
2017-06-25 11:03:12 +02:00
|
|
|
self.umodes = chary_umodes
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2017-07-13 06:23:42 +02:00
|
|
|
# Find the target IRCd and update the mode dictionaries as applicable.
|
|
|
|
target_ircd = self.serverdata.get('ircd', 'elemental' if self.serverdata.get('use_elemental_modes') else 'charybdis')
|
|
|
|
target_ircd = target_ircd.lower()
|
|
|
|
|
|
|
|
if target_ircd not in self.SUPPORTED_IRCDS:
|
|
|
|
log.warning("(%s) Unsupported IRCd %r; falling back to 'charybdis' instead", self.name, target_ircd)
|
|
|
|
target_ircd = 'charybdis'
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
# Toggles support of shadowircd/elemental-ircd specific channel modes:
|
|
|
|
# +T (no notice), +u (hidden ban list), +E (no kicks), +J (blocks kickrejoin),
|
|
|
|
# +K (no repeat messages), +d (no nick changes), and user modes:
|
2017-07-13 06:06:11 +02:00
|
|
|
# +B (bot), +C (blocks CTCP), +V (no invites), +I (hides channel list)
|
2017-07-13 06:23:42 +02:00
|
|
|
if target_ircd == 'elemental':
|
2016-03-08 06:38:57 +01:00
|
|
|
elemental_cmodes = {'hiddenbans': 'u', 'nokick': 'E',
|
2016-05-12 06:49:57 +02:00
|
|
|
'kicknorejoin': 'J', 'repeat': 'K', 'nonick': 'd',
|
|
|
|
'blockcaps': 'G'}
|
2017-06-25 11:03:12 +02:00
|
|
|
self.cmodes.update(elemental_cmodes)
|
|
|
|
self.cmodes['*D'] += ''.join(elemental_cmodes.values())
|
2016-04-18 20:22:54 +02:00
|
|
|
|
2017-07-13 06:06:11 +02:00
|
|
|
elemental_umodes = {'noctcp': 'C', 'bot': 'B', 'noinvite': 'V', 'hidechans': 'I'}
|
2017-06-25 11:03:12 +02:00
|
|
|
self.umodes.update(elemental_umodes)
|
|
|
|
self.umodes['*D'] += ''.join(elemental_umodes.values())
|
2017-07-13 06:23:42 +02:00
|
|
|
elif target_ircd == 'chatircd':
|
|
|
|
chatircd_cmodes = {'netadminonly': 'N'}
|
|
|
|
self.cmodes.update(chatircd_cmodes)
|
|
|
|
self.cmodes['*D'] += ''.join(chatircd_cmodes.values())
|
|
|
|
|
|
|
|
chatircd_umodes = {'netadmin': 'n', 'bot': 'B', 'callerid_sslonly': 't'}
|
|
|
|
self.umodes.update(chatircd_umodes)
|
|
|
|
self.umodes['*D'] += ''.join(chatircd_umodes.values())
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
# https://github.com/grawity/irc-docs/blob/master/server/ts6.txt#L55
|
2017-06-25 11:03:12 +02:00
|
|
|
f('PASS %s TS 6 %s' % (self.serverdata["sendpass"], self.sid))
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
# We request the following capabilities (for charybdis):
|
|
|
|
|
|
|
|
# QS: SQUIT doesn't send recursive quits for each users; required
|
|
|
|
# by charybdis (Source: https://github.com/grawity/irc-docs/blob/master/server/ts-capab.txt)
|
2016-08-01 05:25:17 +02:00
|
|
|
# ENCAP: message encapsulation for certain commands
|
2015-09-06 03:00:57 +02:00
|
|
|
# EX: Support for ban exemptions (+e)
|
|
|
|
# IE: Support for invite exemptions (+e)
|
|
|
|
# CHW: Allow sending messages to @#channel and the like.
|
|
|
|
# KNOCK: support for /knock
|
|
|
|
# SAVE: support for SAVE (forces user to UID in nick collision)
|
|
|
|
# SERVICES: adds mode +r (only registered users can join a channel)
|
2017-07-01 06:29:11 +02:00
|
|
|
# TB: topic burst command; we send this in topic_burst
|
2015-09-06 03:00:57 +02:00
|
|
|
# EUID: extended UID command, which includes real hostname + account data info,
|
|
|
|
# and allows sending CHGHOST without ENCAP.
|
2016-07-12 08:29:44 +02:00
|
|
|
# RSFNC: states that we support RSFNC (forced nick changed attempts). XXX: With atheme services,
|
|
|
|
# does this actually do anything?
|
2016-08-01 05:25:17 +02:00
|
|
|
# EOPMOD: supports ETB (extended TOPIC burst) and =#channel messages for opmoderated +z
|
2017-07-17 15:11:49 +02:00
|
|
|
# KLN: supports remote KLINEs
|
|
|
|
f('CAPAB :QS ENCAP EX CHW IE KNOCK SAVE SERVICES TB EUID RSFNC EOPMOD SAVETS_100 KLN')
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
f('SERVER %s 0 :%s' % (self.serverdata["hostname"],
|
|
|
|
self.serverdata.get('serverdesc') or conf.conf['bot']['serverdesc']))
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2016-01-23 22:11:31 +01:00
|
|
|
# Finally, end all the initialization with a PING - that's Charybdis'
|
|
|
|
# way of saying end-of-burst :)
|
2017-07-05 07:09:50 +02:00
|
|
|
self._ping_uplink()
|
2016-01-23 22:11:31 +01:00
|
|
|
|
2016-01-17 03:14:46 +01:00
|
|
|
def handle_pass(self, numeric, command, args):
|
|
|
|
"""
|
|
|
|
Handles the PASS command, used to send the server's SID and negotiate
|
|
|
|
passwords on connect.
|
|
|
|
"""
|
|
|
|
# <- PASS $somepassword TS 6 :42X
|
2015-09-09 04:51:14 +02:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
if args[0] != self.serverdata['recvpass']:
|
2016-01-17 03:14:46 +01:00
|
|
|
# Check if recvpass is correct
|
|
|
|
raise ProtocolError('Recvpass from uplink server %s does not match configuration!' % servername)
|
2015-09-09 04:51:14 +02:00
|
|
|
|
2016-01-17 03:14:46 +01:00
|
|
|
if args[1] != 'TS' and args[2] != '6':
|
|
|
|
raise ProtocolError("Remote protocol version is too old! Is this even TS6?")
|
|
|
|
|
|
|
|
numeric = args[-1]
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug('(%s) Found uplink SID as %r', self.name, numeric)
|
2016-01-17 03:14:46 +01:00
|
|
|
|
|
|
|
# Server name and SID are sent in different messages, so we fill this
|
|
|
|
# with dummy information until we get the actual sid.
|
2017-07-01 06:45:10 +02:00
|
|
|
self.servers[numeric] = Server(None, '')
|
2017-06-25 11:03:12 +02:00
|
|
|
self.uplink = numeric
|
2016-01-17 03:14:46 +01:00
|
|
|
|
|
|
|
def handle_capab(self, numeric, command, args):
|
|
|
|
"""
|
|
|
|
Handles the CAPAB command, used for TS6 capability negotiation.
|
|
|
|
"""
|
|
|
|
# We only get a list of keywords here. Charybdis obviously assumes that
|
|
|
|
# we know what modes it supports (indeed, this is a standard list).
|
|
|
|
# <- CAPAB :BAN CHW CLUSTER ENCAP EOPMOD EUID EX IE KLN KNOCK MLOCK QS RSFNC SAVE SERVICES TB UNKLN
|
2017-06-25 11:03:12 +02:00
|
|
|
self.caps = caps = args[0].split()
|
2016-01-17 03:14:46 +01:00
|
|
|
|
2016-10-01 08:33:04 +02:00
|
|
|
for required_cap in self.required_caps:
|
2016-01-17 03:14:46 +01:00
|
|
|
if required_cap not in caps:
|
|
|
|
raise ProtocolError('%s not found in TS6 capabilities list; this is required! (got %r)' % (required_cap, caps))
|
|
|
|
|
|
|
|
if 'EX' in caps:
|
2017-06-25 11:03:12 +02:00
|
|
|
self.cmodes['banexception'] = 'e'
|
2016-01-17 03:14:46 +01:00
|
|
|
if 'IE' in caps:
|
2017-06-25 11:03:12 +02:00
|
|
|
self.cmodes['invex'] = 'I'
|
2016-01-17 03:14:46 +01:00
|
|
|
if 'SERVICES' in caps:
|
2017-06-25 11:03:12 +02:00
|
|
|
self.cmodes['regonly'] = 'r'
|
2016-01-17 03:14:46 +01:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug('(%s) self.connected set!', self.name)
|
|
|
|
self.connected.set()
|
2016-01-17 03:14:46 +01:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
def handle_ping(self, source, command, args):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Handles incoming PING commands."""
|
2015-09-06 03:00:57 +02:00
|
|
|
# PING:
|
|
|
|
# source: any
|
|
|
|
# parameters: origin, opt. destination server
|
|
|
|
# PONG:
|
|
|
|
# source: server
|
|
|
|
# parameters: origin, destination
|
|
|
|
|
|
|
|
# Sends a PING to the destination server, which will reply with a PONG. If the
|
|
|
|
# destination server parameter is not present, the server receiving the message
|
|
|
|
# must reply.
|
|
|
|
try:
|
|
|
|
destination = args[1]
|
|
|
|
except IndexError:
|
2017-06-25 11:03:12 +02:00
|
|
|
destination = self.sid
|
2017-06-30 07:56:14 +02:00
|
|
|
if self.is_internal_server(destination):
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(destination, 'PONG %s %s' % (destination, source), queue=False)
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
if destination == self.sid and not self.has_eob:
|
2017-07-05 07:09:50 +02:00
|
|
|
# Charybdis' endburst is just sending a PING to the other server.
|
2016-01-23 22:11:31 +01:00
|
|
|
# https://github.com/charybdis-ircd/charybdis/blob/dc336d1/modules/core/m_server.c#L484-L485
|
|
|
|
self.has_eob = True
|
|
|
|
|
|
|
|
# Return the endburst hook.
|
|
|
|
return {'parse_as': 'ENDBURST'}
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
def handle_sjoin(self, servernumeric, command, args):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Handles incoming SJOIN commands."""
|
2015-09-06 03:00:57 +02:00
|
|
|
# parameters: channelTS, channel, simple modes, opt. mode parameters..., nicklist
|
2016-04-08 03:23:21 +02:00
|
|
|
# <- :0UY SJOIN 1451041566 #channel +nt :@0UYAAAAAB
|
2017-08-08 06:54:33 +02:00
|
|
|
channel = args[1]
|
2017-06-25 11:03:12 +02:00
|
|
|
chandata = self.channels[channel].deepcopy()
|
2015-09-06 03:00:57 +02:00
|
|
|
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)
|
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug('(%s) handle_sjoin: got userlist %r for %r', self.name, userlist, channel)
|
2015-09-06 03:00:57 +02:00
|
|
|
for userpair in userlist:
|
|
|
|
# charybdis sends this in the form "@+UID1, +UID2, UID3, @UID4"
|
|
|
|
r = re.search(r'([^\d]*)(.*)', userpair)
|
|
|
|
user = r.group(2)
|
|
|
|
modeprefix = r.group(1) or ''
|
|
|
|
finalprefix = ''
|
|
|
|
assert user, 'Failed to get the UID from %r; our regex needs updating?' % userpair
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug('(%s) handle_sjoin: got modeprefix %r for user %r', self.name, modeprefix, user)
|
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_sjoin: 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
|
|
|
for m in modeprefix:
|
|
|
|
# Iterate over the mapping of prefix chars to prefixes, and
|
|
|
|
# find the characters that match.
|
2017-06-25 11:03:12 +02:00
|
|
|
for char, prefix in self.prefixmodes.items():
|
2015-09-06 03:00:57 +02:00
|
|
|
if m == prefix:
|
|
|
|
finalprefix += char
|
|
|
|
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 finalprefix}
|
2017-06-25 11:03:12 +02:00
|
|
|
self.channels[channel].users.add(user)
|
2016-06-23 07:26:25 +02:00
|
|
|
|
|
|
|
# Statekeeping with timestamps
|
|
|
|
their_ts = int(args[0])
|
2017-06-25 11:03:12 +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
|
|
|
|
|
|
|
def handle_join(self, numeric, command, args):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Handles incoming channel JOINs."""
|
2015-09-06 03:00:57 +02:00
|
|
|
# parameters: channelTS, channel, '+' (a plus sign)
|
2016-04-08 03:23:21 +02:00
|
|
|
# <- :0UYAAAAAF JOIN 0 #channel +
|
2015-09-06 03:00:57 +02:00
|
|
|
ts = int(args[0])
|
|
|
|
if args[0] == '0':
|
|
|
|
# /join 0; part the user from all channels
|
2017-06-25 11:03:12 +02:00
|
|
|
oldchans = self.users[numeric].channels.copy()
|
2015-09-06 03:00:57 +02:00
|
|
|
log.debug('(%s) Got /join 0 from %r, channel list is %r',
|
2017-06-25 11:03:12 +02:00
|
|
|
self.name, numeric, oldchans)
|
2015-09-06 03:00:57 +02:00
|
|
|
for channel in oldchans:
|
2017-06-25 11:03:12 +02:00
|
|
|
self.channels[channel].users.discard(numeric)
|
|
|
|
self.users[numeric].channels.discard(channel)
|
2015-09-06 03:00:57 +02:00
|
|
|
return {'channels': oldchans, 'text': 'Left all channels.', 'parse_as': 'PART'}
|
|
|
|
else:
|
2017-08-08 06:54:33 +02:00
|
|
|
channel = args[1]
|
2016-07-11 06:35:17 +02:00
|
|
|
self.updateTS(numeric, channel, ts)
|
2016-04-17 02:02:02 +02:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[numeric].channels.add(channel)
|
|
|
|
self.channels[channel].users.add(numeric)
|
2016-04-17 02:02:02 +02:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
# We send users and modes here because SJOIN and JOIN both use one hook,
|
|
|
|
# for simplicity's sake (with plugins).
|
|
|
|
return {'channel': channel, 'users': [numeric], 'modes':
|
2017-06-25 11:03:12 +02:00
|
|
|
self.channels[channel].modes, 'ts': ts}
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
def handle_euid(self, numeric, command, args):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Handles incoming EUID commands (user introduction)."""
|
2015-09-06 03:00:57 +02:00
|
|
|
# <- :42X EUID GL 1 1437505322 +ailoswz ~gl 127.0.0.1 127.0.0.1 42XAAAAAB * * :realname
|
|
|
|
nick = args[0]
|
2017-07-07 12:18:40 +02:00
|
|
|
self._check_nick_collision(nick)
|
2016-02-08 03:38:22 +01:00
|
|
|
ts, modes, ident, host, ip, uid, realhost, accountname, realname = args[2:11]
|
2015-09-06 03:00:57 +02:00
|
|
|
if realhost == '*':
|
|
|
|
realhost = None
|
2016-02-08 03:38:22 +01:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
log.debug('(%s) handle_euid got args: nick=%s ts=%s uid=%s ident=%s '
|
2017-06-25 11:03:12 +02:00
|
|
|
'host=%s realname=%s realhost=%s ip=%s', self.name, nick, ts, uid,
|
2015-09-06 03:00:57 +02:00
|
|
|
ident, host, realname, realhost, ip)
|
2016-07-11 05:27:09 +02:00
|
|
|
assert ts != 0, "Bad TS 0 for user %s" % uid
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2016-01-23 22:37:15 +01:00
|
|
|
if ip == '0': # IP was invalid; something used for services.
|
|
|
|
ip = '0.0.0.0'
|
|
|
|
|
2017-07-01 06:44:31 +02:00
|
|
|
self.users[uid] = User(nick, ts, uid, numeric, ident, host, realname, realhost, ip)
|
2016-02-08 03:38:22 +01:00
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
parsedmodes = self.parse_modes(uid, [modes])
|
2015-09-06 03:00:57 +02:00
|
|
|
log.debug('Applying modes %s for %s', parsedmodes, uid)
|
2017-06-30 07:56:14 +02:00
|
|
|
self.apply_modes(uid, parsedmodes)
|
2017-06-25 11:03:12 +02:00
|
|
|
self.servers[numeric].users.add(uid)
|
2016-02-08 03:38:22 +01:00
|
|
|
|
2015-10-25 18:27:06 +01:00
|
|
|
# Call the OPERED UP hook if +o is being added to the mode list.
|
2017-07-08 05:02:37 +02:00
|
|
|
self._check_oper_status_change(uid, parsedmodes)
|
2016-02-08 03:38:22 +01:00
|
|
|
|
|
|
|
# Set the accountname if present
|
|
|
|
if accountname != "*":
|
2017-06-30 07:56:14 +02:00
|
|
|
self.call_hooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': accountname}])
|
2016-02-08 03:38:22 +01:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip}
|
|
|
|
|
|
|
|
def handle_uid(self, numeric, command, args):
|
2016-09-18 23:13:05 +02:00
|
|
|
"""Handles legacy user introductions (UID)."""
|
|
|
|
# tl;dr We want to convert the following UID parameters:
|
|
|
|
# nickname, hopcount, nickTS, umodes, username, visible hostname, IP address, UID, gecos
|
|
|
|
# to EUID parameters when parsing:
|
|
|
|
# nickname, hopcount, nickTS, umodes, username, visible hostname, IP address, UID,
|
|
|
|
# real hostname, account name, gecos
|
|
|
|
|
|
|
|
euid_args = args[:]
|
|
|
|
|
|
|
|
# Insert a * to denote that the user is not logged in.
|
|
|
|
euid_args.insert(8, '*')
|
|
|
|
|
|
|
|
# Copy the visible hostname to the real hostname, as this data isn't sent yet.
|
|
|
|
# TODO: handle encap realhost / encap login
|
|
|
|
euid_args.insert(8, args[5])
|
|
|
|
|
|
|
|
return self.handle_euid(numeric, command, euid_args)
|
2015-09-06 03:00:57 +02:00
|
|
|
|
2015-10-10 07:48:31 +02:00
|
|
|
def handle_sid(self, numeric, command, args):
|
|
|
|
"""Handles incoming server introductions."""
|
2015-09-06 03:00:57 +02:00
|
|
|
# parameters: server name, hopcount, sid, server description
|
|
|
|
servername = args[0].lower()
|
2015-10-10 07:48:31 +02:00
|
|
|
sid = args[2]
|
2015-09-06 03:00:57 +02:00
|
|
|
sdesc = args[-1]
|
2017-07-01 06:45:10 +02:00
|
|
|
self.servers[sid] = Server(numeric, servername, desc=sdesc)
|
2015-09-06 03:00:57 +02:00
|
|
|
return {'name': servername, 'sid': sid, 'text': sdesc}
|
|
|
|
|
2016-01-17 03:14:46 +01:00
|
|
|
def handle_server(self, numeric, command, args):
|
|
|
|
"""
|
|
|
|
Handles 1) incoming legacy (no SID) server introductions,
|
|
|
|
2) Sending server data in initial connection.
|
|
|
|
"""
|
2017-06-25 11:03:12 +02:00
|
|
|
if numeric == self.uplink and not self.servers[numeric].name:
|
2016-01-17 03:14:46 +01:00
|
|
|
# <- SERVER charybdis.midnight.vpn 1 :charybdis test server
|
|
|
|
sname = args[0].lower()
|
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug('(%s) Found uplink server name as %r', self.name, sname)
|
|
|
|
self.servers[numeric].name = sname
|
|
|
|
self.servers[numeric].desc = args[-1]
|
2016-01-17 03:14:46 +01:00
|
|
|
|
|
|
|
# According to the TS6 protocol documentation, we should send SVINFO
|
|
|
|
# when we get our uplink's SERVER command.
|
2017-06-25 11:03:12 +02:00
|
|
|
self.send('SVINFO 6 6 0 :%s' % int(time.time()))
|
2016-01-17 03:14:46 +01:00
|
|
|
|
|
|
|
return
|
|
|
|
|
2015-10-10 07:48:31 +02:00
|
|
|
# <- :services.int SERVER a.bc 2 :(H) [GL] a
|
|
|
|
servername = args[0].lower()
|
|
|
|
sdesc = args[-1]
|
2017-07-01 06:45:10 +02:00
|
|
|
self.servers[servername] = Server(numeric, servername, desc=sdesc)
|
2015-10-13 02:49:03 +02:00
|
|
|
return {'name': servername, 'sid': None, 'text': sdesc}
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
def handle_tmode(self, numeric, command, args):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Handles incoming TMODE commands (channel mode change)."""
|
2016-03-21 01:34:13 +01:00
|
|
|
# <- :42XAAAAAB TMODE 1437450768 #test -c+lkC 3 agte4
|
2016-04-08 03:23:21 +02:00
|
|
|
# <- :0UYAAAAAD TMODE 0 #a +h 0UYAAAAAD
|
2017-08-08 06:54:33 +02:00
|
|
|
channel = args[1]
|
2017-06-25 11:03:12 +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[0])
|
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
|
|
|
|
|
|
|
def handle_tb(self, numeric, command, args):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Handles incoming topic burst (TB) commands."""
|
2016-07-02 04:45:13 +02:00
|
|
|
# <- :42X TB #chat 1467427448 GL!~gl@127.0.0.1 :test
|
2017-08-08 06:54:33 +02:00
|
|
|
channel = args[0]
|
2016-07-02 04:45:13 +02:00
|
|
|
ts = args[1]
|
2015-09-06 03:00:57 +02:00
|
|
|
setter = args[2]
|
|
|
|
topic = args[-1]
|
2017-06-25 11:03:12 +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
|
|
|
|
2016-08-01 05:25:17 +02:00
|
|
|
def handle_etb(self, numeric, command, args):
|
|
|
|
"""Handles extended topic burst (ETB)."""
|
|
|
|
# <- :00AAAAAAC ETB 0 #test 1470021157 GL :test | abcd
|
|
|
|
# Same as TB, with extra TS and extensions arguments.
|
2017-08-08 06:54:33 +02:00
|
|
|
channel = args[1]
|
2016-08-01 05:25:17 +02:00
|
|
|
ts = args[2]
|
|
|
|
setter = args[3]
|
|
|
|
topic = args[-1]
|
2017-06-25 11:03:12 +02:00
|
|
|
self.channels[channel].topic = topic
|
|
|
|
self.channels[channel].topicset = True
|
2016-08-01 05:25:17 +02:00
|
|
|
return {'channel': channel, 'setter': setter, 'ts': ts, 'text': topic}
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
def handle_chghost(self, numeric, command, args):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Handles incoming CHGHOST commands."""
|
2017-06-17 02:12:48 +02:00
|
|
|
target = self._get_UID(args[0])
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[target].host = newhost = args[1]
|
2015-12-31 00:53:31 +01:00
|
|
|
return {'target': target, 'newhost': newhost}
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
def handle_bmask(self, numeric, command, args):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Handles incoming BMASK commands (ban propagation on burst)."""
|
2015-09-06 03:00:57 +02:00
|
|
|
# <- :42X BMASK 1424222769 #dev b :*!test@*.isp.net *!badident@*
|
|
|
|
# This is used for propagating bans, not TMODE!
|
2017-08-08 06:54:33 +02:00
|
|
|
channel = args[1]
|
2015-09-06 03:00:57 +02:00
|
|
|
mode = args[2]
|
|
|
|
ts = int(args[0])
|
|
|
|
modes = []
|
|
|
|
for ban in args[-1].split():
|
|
|
|
modes.append(('+%s' % mode, ban))
|
2017-06-30 07:56:14 +02:00
|
|
|
self.apply_modes(channel, modes)
|
2015-09-06 03:00:57 +02:00
|
|
|
return {'target': channel, 'modes': modes, 'ts': ts}
|
|
|
|
|
|
|
|
def handle_472(self, numeric, command, args):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Handles the incoming 472 numeric.
|
|
|
|
|
|
|
|
472 is sent to us when one of our clients tries to set a mode the uplink
|
|
|
|
server doesn't support. In this case, we'll raise a warning to alert
|
|
|
|
the administrator that certain extensions should be loaded for the best
|
|
|
|
compatibility.
|
|
|
|
"""
|
2015-09-06 03:00:57 +02:00
|
|
|
# <- :charybdis.midnight.vpn 472 GL|devel O :is an unknown mode char to me
|
|
|
|
badmode = args[1]
|
|
|
|
reason = args[-1]
|
|
|
|
setter = args[0]
|
2016-03-08 06:38:57 +01:00
|
|
|
charlist = {'A': 'chm_adminonly', 'O': 'chm_operonly', 'S': 'chm_sslonly',
|
|
|
|
'T': 'chm_nonotice'}
|
2015-09-06 03:00:57 +02:00
|
|
|
if badmode in charlist:
|
|
|
|
log.warning('(%s) User %r attempted to set channel mode %r, but the '
|
|
|
|
'extension providing it isn\'t loaded! To prevent possible'
|
|
|
|
' desyncs, try adding the line "loadmodule "extensions/%s.so";" to '
|
2017-06-25 11:03:12 +02:00
|
|
|
'your IRCd configuration.', self.name, setter, badmode,
|
2015-09-06 03:00:57 +02:00
|
|
|
charlist[badmode])
|
|
|
|
|
2016-07-05 22:27:31 +02:00
|
|
|
def handle_su(self, numeric, command, args):
|
2016-02-08 03:38:22 +01:00
|
|
|
"""
|
2016-07-12 08:21:08 +02:00
|
|
|
Handles SU, which is used for setting login information.
|
2016-02-08 03:38:22 +01:00
|
|
|
"""
|
2016-07-05 22:27:31 +02:00
|
|
|
# <- :00A ENCAP * SU 42XAAAAAC :GLolol
|
|
|
|
# <- :00A ENCAP * SU 42XAAAAAC
|
|
|
|
try:
|
|
|
|
account = args[1] # Account name is being set
|
|
|
|
except IndexError:
|
|
|
|
account = '' # No account name means a logout
|
|
|
|
|
|
|
|
uid = args[0]
|
2017-06-30 07:56:14 +02:00
|
|
|
self.call_hooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': account}])
|
2016-02-08 03:38:22 +01:00
|
|
|
|
2016-07-12 08:21:08 +02:00
|
|
|
def handle_rsfnc(self, numeric, command, args):
|
|
|
|
"""
|
|
|
|
Handles RSFNC, used for forced nick change attempts.
|
|
|
|
"""
|
|
|
|
# <- :00A ENCAP somenet.relay RSFNC 801AAAAAB Guest75038 1468299643 :1468299675
|
|
|
|
return {'target': args[0], 'newnick': args[1]}
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
Class = TS6Protocol
|