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 sys
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
|
2016-06-21 03:18:54 +02:00
|
|
|
from pylinkirc import utils
|
|
|
|
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):
|
|
|
|
def __init__(self, irc):
|
2016-04-06 03:37:09 +02:00
|
|
|
super().__init__(irc)
|
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-01-17 03:14:46 +01:00
|
|
|
### OUTGOING COMMANDS
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
def spawnClient(self, nick, ident='null', host='null', realhost=None, modes=set(),
|
2016-03-26 20:55:23 +01:00
|
|
|
server=None, ip='0.0.0.0', realname=None, ts=None, opertype='IRC Operator',
|
2015-09-18 04:01:54 +02:00
|
|
|
manipulatable=False):
|
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.
|
|
|
|
"""
|
2015-09-06 03:00:57 +02:00
|
|
|
server = server or self.irc.sid
|
2016-04-25 06:16:41 +02:00
|
|
|
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalServer(server):
|
2016-01-10 02:44:05 +01:00
|
|
|
raise ValueError('Server %r is not a PyLink server!' % server)
|
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())
|
|
|
|
realname = realname or self.irc.botdata['realname']
|
|
|
|
realhost = realhost or host
|
2016-05-01 01:33:46 +02:00
|
|
|
raw_modes = self.irc.joinModes(modes)
|
2015-09-06 03:00:57 +02:00
|
|
|
u = self.irc.users[uid] = IrcUser(nick, ts, uid, ident=ident, host=host, realname=realname,
|
2016-03-26 20:55:23 +01:00
|
|
|
realhost=realhost, ip=ip, manipulatable=manipulatable, opertype=opertype)
|
2016-04-25 06:16:41 +02:00
|
|
|
|
2016-04-25 06:43:52 +02:00
|
|
|
self.irc.applyModes(uid, modes)
|
2015-09-06 03:00:57 +02:00
|
|
|
self.irc.servers[server].users.add(uid)
|
2016-04-25 06:16:41 +02:00
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
self._send(server, "EUID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} "
|
|
|
|
"{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."""
|
2016-05-01 01:57:38 +02:00
|
|
|
channel = self.irc.toLower(channel)
|
2015-09-06 03:00:57 +02:00
|
|
|
# JOIN:
|
|
|
|
# parameters: channelTS, channel, '+' (a plus sign)
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalClient(client):
|
2016-01-10 02:44:05 +01:00
|
|
|
log.error('(%s) Error trying to join %r to %r (no such client exists)', self.irc.name, client, channel)
|
|
|
|
raise LookupError('No such PyLink client exists.')
|
2015-09-06 03:00:57 +02:00
|
|
|
self._send(client, "JOIN {ts} {channel} +".format(ts=self.irc.channels[channel].ts, channel=channel))
|
|
|
|
self.irc.channels[channel].users.add(client)
|
|
|
|
self.irc.users[client].channels.add(channel)
|
|
|
|
|
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')])
|
|
|
|
sjoin(self.irc.sid, '#test', [('o', self.irc.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.
|
2016-05-01 01:57:38 +02:00
|
|
|
channel = self.irc.toLower(channel)
|
2015-09-06 03:00:57 +02:00
|
|
|
server = server or self.irc.sid
|
2016-01-17 01:53:46 +01:00
|
|
|
assert users, "sjoin: No users sent?"
|
|
|
|
log.debug('(%s) sjoin: got %r for users', self.irc.name, users)
|
2015-09-06 03:00:57 +02:00
|
|
|
if not server:
|
2016-01-10 02:44:05 +01:00
|
|
|
raise LookupError('No such PyLink client exists.')
|
2015-11-08 19:49:09 +01:00
|
|
|
|
2016-06-23 06:34:16 +02:00
|
|
|
modes = set(modes or self.irc.channels[channel].modes)
|
2016-06-25 22:56:24 +02:00
|
|
|
orig_ts = self.irc.channels[channel].ts
|
|
|
|
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.
|
|
|
|
banmodes = {k: set() for k in self.irc.cmodes['*A']}
|
|
|
|
regularmodes = []
|
|
|
|
log.debug('(%s) Unfiltered SJOIN modes: %s', self.irc.name, modes)
|
|
|
|
for mode in modes:
|
|
|
|
modechar = mode[0][-1]
|
|
|
|
if modechar in self.irc.cmodes['*A']:
|
|
|
|
# Mode character is one of 'beIq'
|
|
|
|
banmodes[modechar].add(mode[1])
|
|
|
|
else:
|
|
|
|
regularmodes.append(mode)
|
|
|
|
log.debug('(%s) Filtered SJOIN modes to be regular modes: %s, banmodes: %s', self.irc.name, regularmodes, banmodes)
|
|
|
|
|
|
|
|
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:
|
|
|
|
pr = self.irc.prefixmodes.get(prefix)
|
|
|
|
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:
|
|
|
|
self.irc.users[user].channels.add(channel)
|
|
|
|
except KeyError: # Not initialized yet?
|
2016-01-17 01:53:46 +01:00
|
|
|
log.debug("(%s) sjoin: KeyError trying to add %r to %r's channel list?", self.irc.name, channel, user)
|
2016-06-28 08:13:39 +02:00
|
|
|
users = users[12:]
|
2015-09-06 03:00:57 +02:00
|
|
|
namelist = ' '.join(namelist)
|
|
|
|
self._send(server, "SJOIN {ts} {channel} {modes} :{users}".format(
|
|
|
|
ts=ts, users=namelist, channel=channel,
|
2016-06-23 06:34:16 +02:00
|
|
|
modes=self.irc.joinModes(regularmodes)))
|
2015-09-06 03:00:57 +02:00
|
|
|
self.irc.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:
|
2016-06-28 08:35:56 +02:00
|
|
|
log.debug('(%s) sjoin: bursting mode %s with bans %s, ts:%s', self.irc.name, bmode, bans, ts)
|
|
|
|
bans = list(bans) # Convert into list for splicing
|
|
|
|
while bans[:12]:
|
|
|
|
self._send(server, "BMASK {ts} {channel} {bmode} :{bans}".format(ts=ts,
|
|
|
|
channel=channel, bmode=bmode, bans=' '.join(bans[:12])))
|
|
|
|
bans = bans[12:]
|
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
|
|
|
|
|
|
|
if (not self.irc.isInternalClient(numeric)) and \
|
|
|
|
(not self.irc.isInternalServer(numeric)):
|
|
|
|
raise LookupError('No such PyLink client/server exists.')
|
|
|
|
|
2016-04-25 06:43:52 +02:00
|
|
|
self.irc.applyModes(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):
|
2016-05-01 01:57:38 +02:00
|
|
|
ts = ts or self.irc.channels[self.irc.toLower(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.
|
2016-06-28 08:40:58 +02:00
|
|
|
while modes[:10]:
|
2016-01-17 02:08:17 +01:00
|
|
|
# Seriously, though. If you send more than 10 mode parameters in
|
|
|
|
# a line, charybdis will silently REJECT the entire command!
|
2016-08-21 02:36:34 +02:00
|
|
|
joinedmodes = self.irc.joinModes([m for m in modes[:10] if m[0] not in self.irc.cmodes['*A']])
|
2016-06-28 08:40:58 +02:00
|
|
|
modes = modes[10:]
|
2015-09-06 03:00:57 +02:00
|
|
|
self._send(numeric, 'TMODE %s %s %s' % (ts, target, joinedmodes))
|
|
|
|
else:
|
2016-05-01 01:33:46 +02:00
|
|
|
joinedmodes = self.irc.joinModes(modes)
|
2015-09-06 03:00:57 +02:00
|
|
|
self._send(numeric, 'MODE %s %s' % (target, joinedmodes))
|
|
|
|
|
2016-01-17 02:09:52 +01:00
|
|
|
def topicBurst(self, numeric, target, text):
|
2015-09-25 03:36:54 +02:00
|
|
|
"""Sends a topic change from a PyLink server. This is usually used on burst."""
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalServer(numeric):
|
2016-01-10 02:44:05 +01:00
|
|
|
raise LookupError('No such PyLink server exists.')
|
2015-09-06 03:00:57 +02:00
|
|
|
# TB
|
|
|
|
# capab: TB
|
|
|
|
# source: server
|
|
|
|
# propagation: broadcast
|
|
|
|
# parameters: channel, topicTS, opt. topic setter, topic
|
|
|
|
ts = self.irc.channels[target].ts
|
|
|
|
servername = self.irc.servers[numeric].name
|
|
|
|
self._send(numeric, 'TB %s %s %s :%s' % (target, ts, servername, text))
|
|
|
|
self.irc.channels[target].topic = text
|
|
|
|
self.irc.channels[target].topicset = True
|
|
|
|
|
2016-01-17 01:38:27 +01:00
|
|
|
def invite(self, numeric, target, channel):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Sends an INVITE from a PyLink client.."""
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalClient(numeric):
|
2016-01-10 02:44:05 +01:00
|
|
|
raise LookupError('No such PyLink client exists.')
|
2015-09-06 03:00:57 +02:00
|
|
|
self._send(numeric, 'INVITE %s %s %s' % (target, channel, self.irc.channels[channel].ts))
|
|
|
|
|
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."""
|
2015-09-06 03:00:57 +02:00
|
|
|
if 'KNOCK' not in self.irc.caps:
|
2016-01-17 01:41:17 +01:00
|
|
|
log.debug('(%s) knock: Dropping KNOCK to %r since the IRCd '
|
2015-09-06 03:00:57 +02:00
|
|
|
'doesn\'t support it.', self.irc.name, target)
|
|
|
|
return
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalClient(numeric):
|
2016-01-10 02:44:05 +01:00
|
|
|
raise LookupError('No such PyLink client exists.')
|
2015-09-06 03:00:57 +02:00
|
|
|
# No text value is supported here; drop it.
|
|
|
|
self._send(numeric, 'KNOCK %s' % target)
|
|
|
|
|
2015-12-31 00:54:09 +01:00
|
|
|
def updateClient(self, target, field, text):
|
|
|
|
"""Updates the hostname of any connected client."""
|
2015-09-06 03:00:57 +02:00
|
|
|
field = field.upper()
|
|
|
|
if field == 'HOST':
|
2015-12-31 00:54:09 +01:00
|
|
|
self.irc.users[target].host = text
|
|
|
|
self._send(self.irc.sid, 'CHGHOST %s :%s' % (target, text))
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalClient(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.
|
|
|
|
self.irc.callHooks([self.irc.sid, 'CHGHOST',
|
|
|
|
{'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 02:11:23 +01:00
|
|
|
def ping(self, source=None, target=None):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Sends a PING to a target server. Periodic PINGs are sent to our uplink
|
|
|
|
automatically by the Irc() internals; plugins shouldn't have to use this."""
|
2015-09-06 03:00:57 +02:00
|
|
|
source = source or self.irc.sid
|
|
|
|
if source is None:
|
|
|
|
return
|
|
|
|
if target is not None:
|
|
|
|
self._send(source, 'PING %s %s' % (source, target))
|
|
|
|
else:
|
|
|
|
self._send(source, 'PING %s' % source)
|
|
|
|
|
2016-01-17 03:14:46 +01:00
|
|
|
### Core / handlers
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
def connect(self):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Initializes a connection to a server."""
|
2015-09-06 03:00:57 +02:00
|
|
|
ts = self.irc.start_ts
|
2016-03-20 02:19:41 +01:00
|
|
|
self.has_eob = False
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
f = self.irc.send
|
|
|
|
|
|
|
|
# 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':
|
2015-09-06 03:00:57 +02:00
|
|
|
'g', 'opmoderated': 'z', 'noctcp': 'C',
|
|
|
|
# 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
|
|
|
|
|
|
|
if self.irc.serverdata.get('use_owner'):
|
|
|
|
chary_cmodes['owner'] = 'y'
|
|
|
|
self.irc.prefixmodes['y'] = '~'
|
|
|
|
if self.irc.serverdata.get('use_admin'):
|
|
|
|
chary_cmodes['admin'] = 'a'
|
|
|
|
self.irc.prefixmodes['a'] = '!'
|
|
|
|
if self.irc.serverdata.get('use_halfop'):
|
|
|
|
chary_cmodes['halfop'] = 'h'
|
|
|
|
self.irc.prefixmodes['h'] = '%'
|
|
|
|
|
2016-04-18 20:22:54 +02:00
|
|
|
self.irc.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'}
|
2016-04-18 20:22:54 +02:00
|
|
|
self.irc.umodes = chary_umodes
|
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:
|
|
|
|
# +B (bot), +C (blocks CTCP), +D (deaf), +V (no invites), +I (hides channel list)
|
|
|
|
if self.irc.serverdata.get('use_elemental_modes'):
|
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'}
|
2015-09-06 03:00:57 +02:00
|
|
|
self.irc.cmodes.update(elemental_cmodes)
|
|
|
|
self.irc.cmodes['*D'] += ''.join(elemental_cmodes.values())
|
2016-04-18 20:22:54 +02:00
|
|
|
|
2016-05-15 20:05:02 +02:00
|
|
|
elemental_umodes = {'noctcp': 'C', 'deaf': 'D', 'bot': 'B', 'noinvite': 'V',
|
2015-09-06 03:00:57 +02:00
|
|
|
'hidechans': 'I'}
|
|
|
|
self.irc.umodes.update(elemental_umodes)
|
|
|
|
self.irc.umodes['*D'] += ''.join(elemental_umodes.values())
|
|
|
|
|
|
|
|
# https://github.com/grawity/irc-docs/blob/master/server/ts6.txt#L55
|
|
|
|
f('PASS %s TS 6 %s' % (self.irc.serverdata["sendpass"], self.irc.sid))
|
|
|
|
|
|
|
|
# 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)
|
2016-01-17 02:09:52 +01:00
|
|
|
# TB: topic burst command; we send this in topicBurst
|
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
|
|
|
|
f('CAPAB :QS ENCAP EX CHW IE KNOCK SAVE SERVICES TB EUID RSFNC EOPMOD')
|
2015-09-06 03:00:57 +02:00
|
|
|
|
|
|
|
f('SERVER %s 0 :%s' % (self.irc.serverdata["hostname"],
|
|
|
|
self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc']))
|
|
|
|
|
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 :)
|
|
|
|
self.ping()
|
|
|
|
|
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
|
|
|
|
2016-01-17 03:14:46 +01:00
|
|
|
if args[0] != self.irc.serverdata['recvpass']:
|
|
|
|
# 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]
|
|
|
|
log.debug('(%s) Found uplink SID as %r', self.irc.name, numeric)
|
|
|
|
|
|
|
|
# Server name and SID are sent in different messages, so we fill this
|
|
|
|
# with dummy information until we get the actual sid.
|
|
|
|
self.irc.servers[numeric] = IrcServer(None, '')
|
|
|
|
self.irc.uplink = numeric
|
|
|
|
|
|
|
|
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
|
|
|
|
self.irc.caps = caps = args[0].split()
|
|
|
|
|
2016-08-01 05:42:34 +02:00
|
|
|
for required_cap in ('EUID', 'SAVE', 'TB', 'ENCAP', 'QS', 'CHW'):
|
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:
|
|
|
|
self.irc.cmodes['banexception'] = 'e'
|
|
|
|
if 'IE' in caps:
|
|
|
|
self.irc.cmodes['invex'] = 'I'
|
|
|
|
if 'SERVICES' in caps:
|
|
|
|
self.irc.cmodes['regonly'] = 'r'
|
|
|
|
|
|
|
|
log.debug('(%s) self.irc.connected set!', self.irc.name)
|
|
|
|
self.irc.connected.set()
|
|
|
|
|
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:
|
|
|
|
destination = self.irc.sid
|
2016-01-01 02:28:47 +01:00
|
|
|
if self.irc.isInternalServer(destination):
|
2015-09-06 03:00:57 +02:00
|
|
|
self._send(destination, 'PONG %s %s' % (destination, source))
|
|
|
|
|
2016-01-23 22:11:31 +01:00
|
|
|
if destination == self.irc.sid and not self.has_eob:
|
|
|
|
# Charybdis' idea of endburst is just sending a PING. No, really!
|
|
|
|
# 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_pong(self, source, command, args):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Handles incoming PONG commands."""
|
2015-09-06 03:00:57 +02:00
|
|
|
if source == self.irc.uplink:
|
|
|
|
self.irc.lastping = time.time()
|
|
|
|
|
|
|
|
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
|
2016-05-01 01:57:38 +02:00
|
|
|
channel = self.irc.toLower(args[1])
|
2016-08-28 03:56:36 +02:00
|
|
|
chandata = self.irc.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]
|
2016-04-25 06:43:52 +02:00
|
|
|
parsedmodes = self.irc.parseModes(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
|
|
|
log.debug('(%s) handle_sjoin: got userlist %r for %r', self.irc.name, userlist, channel)
|
|
|
|
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
|
|
|
|
log.debug('(%s) handle_sjoin: got modeprefix %r for user %r', self.irc.name, modeprefix, user)
|
2016-01-28 02:49:00 +01:00
|
|
|
|
|
|
|
# Don't crash when we get an invalid UID.
|
|
|
|
if user not in self.irc.users:
|
|
|
|
log.debug('(%s) handle_sjoin: tried to introduce user %s not in our user list, ignoring...',
|
|
|
|
self.irc.name, user)
|
|
|
|
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.
|
|
|
|
for char, prefix in self.irc.prefixmodes.items():
|
|
|
|
if m == prefix:
|
|
|
|
finalprefix += char
|
|
|
|
namelist.append(user)
|
|
|
|
self.irc.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}
|
2015-09-06 03:00:57 +02:00
|
|
|
self.irc.channels[channel].users.add(user)
|
2016-06-23 07:26:25 +02:00
|
|
|
|
|
|
|
# Statekeeping with timestamps
|
|
|
|
their_ts = int(args[0])
|
|
|
|
our_ts = self.irc.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
|
|
|
|
oldchans = self.irc.users[numeric].channels.copy()
|
|
|
|
log.debug('(%s) Got /join 0 from %r, channel list is %r',
|
|
|
|
self.irc.name, numeric, oldchans)
|
|
|
|
for channel in oldchans:
|
|
|
|
self.irc.channels[channel].users.discard(numeric)
|
|
|
|
self.irc.users[numeric].channels.discard(channel)
|
|
|
|
return {'channels': oldchans, 'text': 'Left all channels.', 'parse_as': 'PART'}
|
|
|
|
else:
|
2016-05-01 01:57:38 +02:00
|
|
|
channel = self.irc.toLower(args[1])
|
2016-07-11 06:35:17 +02:00
|
|
|
self.updateTS(numeric, channel, ts)
|
2016-04-17 02:02:02 +02:00
|
|
|
|
|
|
|
self.irc.users[numeric].channels.add(channel)
|
|
|
|
self.irc.channels[channel].users.add(numeric)
|
|
|
|
|
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':
|
|
|
|
self.irc.channels[channel].modes, 'ts': ts}
|
|
|
|
|
|
|
|
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]
|
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 '
|
|
|
|
'host=%s realname=%s realhost=%s ip=%s', self.irc.name, nick, ts, uid,
|
|
|
|
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'
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
self.irc.users[uid] = IrcUser(nick, ts, uid, ident, host, realname, realhost, ip)
|
2016-02-08 03:38:22 +01:00
|
|
|
|
2016-04-25 06:43:52 +02:00
|
|
|
parsedmodes = self.irc.parseModes(uid, [modes])
|
2015-09-06 03:00:57 +02:00
|
|
|
log.debug('Applying modes %s for %s', parsedmodes, uid)
|
2016-04-25 06:43:52 +02:00
|
|
|
self.irc.applyModes(uid, parsedmodes)
|
2015-09-06 03:00:57 +02:00
|
|
|
self.irc.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.
|
|
|
|
if ('+o', None) in parsedmodes:
|
2016-03-26 21:15:22 +01:00
|
|
|
otype = 'Server Administrator' if ('+a', None) in parsedmodes else 'IRC Operator'
|
2015-12-27 00:41:22 +01:00
|
|
|
self.irc.callHooks([uid, 'CLIENT_OPERED', {'text': otype}])
|
2016-02-08 03:38:22 +01:00
|
|
|
|
|
|
|
# Set the accountname if present
|
|
|
|
if accountname != "*":
|
|
|
|
self.irc.callHooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': accountname}])
|
|
|
|
|
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):
|
|
|
|
raise ProtocolError("Servers should use EUID instead of UID to send users! "
|
|
|
|
"This IS a required capability after all...")
|
|
|
|
|
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]
|
2015-09-12 19:39:05 +02:00
|
|
|
self.irc.servers[sid] = IrcServer(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.
|
|
|
|
"""
|
|
|
|
if numeric == self.irc.uplink and not self.irc.servers[numeric].name:
|
|
|
|
# <- SERVER charybdis.midnight.vpn 1 :charybdis test server
|
|
|
|
sname = args[0].lower()
|
|
|
|
|
|
|
|
log.debug('(%s) Found uplink server name as %r', self.irc.name, sname)
|
|
|
|
self.irc.servers[numeric].name = sname
|
|
|
|
self.irc.servers[numeric].desc = args[-1]
|
|
|
|
|
|
|
|
# According to the TS6 protocol documentation, we should send SVINFO
|
|
|
|
# when we get our uplink's SERVER command.
|
|
|
|
self.irc.send('SVINFO 6 6 0 :%s' % int(time.time()))
|
|
|
|
|
|
|
|
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]
|
|
|
|
self.irc.servers[servername] = IrcServer(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
|
2016-05-01 01:57:38 +02:00
|
|
|
channel = self.irc.toLower(args[1])
|
2015-09-13 22:47:18 +02:00
|
|
|
oldobj = self.irc.channels[channel].deepcopy()
|
2015-09-06 03:00:57 +02:00
|
|
|
modes = args[2:]
|
2016-04-25 06:43:52 +02:00
|
|
|
changedmodes = self.irc.parseModes(channel, modes)
|
|
|
|
self.irc.applyModes(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_mode(self, numeric, command, args):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Handles incoming user mode changes."""
|
2015-09-06 03:00:57 +02:00
|
|
|
# <- :70MAAAAAA MODE 70MAAAAAA -i+xc
|
|
|
|
target = args[0]
|
|
|
|
modestrings = args[1:]
|
2016-04-25 06:43:52 +02:00
|
|
|
changedmodes = self.irc.parseModes(target, modestrings)
|
|
|
|
self.irc.applyModes(target, changedmodes)
|
2015-09-09 04:51:14 +02:00
|
|
|
# Call the OPERED UP hook if +o is being set.
|
2015-09-06 03:00:57 +02:00
|
|
|
if ('+o', None) in changedmodes:
|
2016-03-26 21:15:22 +01:00
|
|
|
otype = 'Server Administrator' if ('a', None) in self.irc.users[target].modes else 'IRC Operator'
|
2015-12-27 00:41:22 +01:00
|
|
|
self.irc.callHooks([target, 'CLIENT_OPERED', {'text': otype}])
|
2015-09-06 03:00:57 +02:00
|
|
|
return {'target': target, 'modes': changedmodes}
|
|
|
|
|
|
|
|
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
|
2016-08-01 05:19:14 +02:00
|
|
|
channel = self.irc.toLower(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]
|
|
|
|
self.irc.channels[channel].topic = topic
|
|
|
|
self.irc.channels[channel].topicset = True
|
2015-12-19 06:53:35 +01:00
|
|
|
return {'channel': channel, 'setter': setter, 'ts': ts, 'text': topic}
|
2015-09-06 03:00:57 +02:00
|
|
|
|
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.
|
|
|
|
channel = self.irc.toLower(args[1])
|
|
|
|
ts = args[2]
|
|
|
|
setter = args[3]
|
|
|
|
topic = args[-1]
|
|
|
|
self.irc.channels[channel].topic = topic
|
|
|
|
self.irc.channels[channel].topicset = True
|
|
|
|
return {'channel': channel, 'setter': setter, 'ts': ts, 'text': topic}
|
|
|
|
|
2015-09-06 03:00:57 +02:00
|
|
|
def handle_invite(self, numeric, command, args):
|
2015-09-09 04:51:14 +02:00
|
|
|
"""Handles incoming INVITEs."""
|
2015-09-06 03:00:57 +02:00
|
|
|
# <- :70MAAAAAC INVITE 0ALAAAAAA #blah 12345
|
|
|
|
target = args[0]
|
2016-08-01 05:19:14 +02:00
|
|
|
channel = self.irc.toLower(args[1])
|
2015-09-06 03:00:57 +02:00
|
|
|
try:
|
|
|
|
ts = args[3]
|
|
|
|
except IndexError:
|
|
|
|
ts = int(time.time())
|
|
|
|
# We don't actually need to process this; it's just something plugins/hooks can use
|
2015-11-16 06:16:03 +01:00
|
|
|
return {'target': target, 'channel': channel, 'ts': ts}
|
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."""
|
2015-09-06 03:00:57 +02:00
|
|
|
target = args[0]
|
|
|
|
self.irc.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!
|
2016-08-01 05:19:14 +02:00
|
|
|
channel = self.irc.toLower(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))
|
2016-04-25 06:43:52 +02:00
|
|
|
self.irc.applyModes(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 '
|
|
|
|
'your IRCd configuration.', self.irc.name, setter, badmode,
|
|
|
|
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]
|
|
|
|
self.irc.callHooks([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
|