2015-12-26 23:45:28 +01:00
|
|
|
"""
|
2020-03-09 00:47:31 +01:00
|
|
|
unreal.py: UnrealIRCd 4.x-5.x protocol module for PyLink.
|
2015-12-26 23:45:28 +01:00
|
|
|
"""
|
|
|
|
|
2015-10-13 03:45:25 +02:00
|
|
|
import codecs
|
2015-10-09 05:46:30 +02:00
|
|
|
import re
|
2019-07-15 00:12:29 +02:00
|
|
|
import socket
|
|
|
|
import time
|
2015-09-03 22:32:59 +02:00
|
|
|
|
2019-07-15 00:12:29 +02:00
|
|
|
from pylinkirc import conf, utils
|
2016-06-21 03:18:54 +02:00
|
|
|
from pylinkirc.classes import *
|
|
|
|
from pylinkirc.log import log
|
2020-06-19 00:47:20 +02:00
|
|
|
from pylinkirc.protocols.ts6_common import TS6BaseProtocol
|
|
|
|
|
|
|
|
__all__ = ['UnrealProtocol']
|
|
|
|
|
2015-09-03 22:32:59 +02:00
|
|
|
|
2017-01-01 09:00:01 +01:00
|
|
|
SJOIN_PREFIXES = {'q': '*', 'a': '~', 'o': '@', 'h': '%', 'v': '+', 'b': '&', 'e': '"', 'I': "'"}
|
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
class UnrealProtocol(TS6BaseProtocol):
|
2017-07-08 05:13:52 +02:00
|
|
|
# I'm not sure what the real limit is, but the text posted at
|
2018-07-08 21:53:59 +02:00
|
|
|
# https://github.com/jlu5/PyLink/issues/378 suggests 427 characters.
|
2017-07-08 05:13:52 +02:00
|
|
|
# https://github.com/unrealircd/unrealircd/blob/4cad9cb/src/modules/m_server.c#L1260 may
|
2021-06-10 05:15:07 +02:00
|
|
|
# also help. (but why BUFSIZE-*80*?) -jlu5
|
2017-07-08 05:13:52 +02:00
|
|
|
S2S_BUFSIZE = 427
|
2019-11-17 21:21:59 +01:00
|
|
|
_KNOWN_CMODES = {'ban': 'b',
|
|
|
|
'banexception': 'e',
|
|
|
|
'blockcolor': 'c',
|
|
|
|
'censor': 'G',
|
|
|
|
'delayjoin': 'D',
|
|
|
|
'flood_unreal': 'f',
|
|
|
|
'invex': 'I',
|
|
|
|
'inviteonly': 'i',
|
|
|
|
'issecure': 'Z',
|
|
|
|
'key': 'k',
|
|
|
|
'limit': 'l',
|
|
|
|
'moderated': 'm',
|
|
|
|
'noctcp': 'C',
|
|
|
|
'noextmsg': 'n',
|
|
|
|
'noinvite': 'V',
|
|
|
|
'nokick': 'Q',
|
|
|
|
'noknock': 'K',
|
|
|
|
'nonick': 'N',
|
|
|
|
'nonotice': 'T',
|
|
|
|
'op': 'o',
|
|
|
|
'operonly': 'O',
|
|
|
|
'permanent': 'P',
|
|
|
|
'private': 'p',
|
|
|
|
'registered': 'r',
|
|
|
|
'regmoderated': 'M',
|
|
|
|
'regonly': 'R',
|
|
|
|
'secret': 's',
|
|
|
|
'sslonly': 'z',
|
|
|
|
'stripcolor': 'S',
|
|
|
|
'topiclock': 't',
|
|
|
|
'voice': 'v'}
|
|
|
|
_KNOWN_UMODES = {'bot': 'B',
|
2019-12-29 18:43:43 +01:00
|
|
|
'censor': 'G',
|
2019-11-17 21:21:59 +01:00
|
|
|
'cloak': 'x',
|
|
|
|
'deaf': 'd',
|
|
|
|
'filter': 'G',
|
|
|
|
'hidechans': 'p',
|
|
|
|
'hideidle': 'I',
|
|
|
|
'hideoper': 'H',
|
|
|
|
'invisible': 'i',
|
|
|
|
'noctcp': 'T',
|
|
|
|
'protected': 'q',
|
|
|
|
'regdeaf': 'R',
|
|
|
|
'registered': 'r',
|
2019-12-29 18:43:43 +01:00
|
|
|
'sslonlymsg': 'Z',
|
2019-11-17 21:21:59 +01:00
|
|
|
'servprotect': 'S',
|
|
|
|
'showwhois': 'W',
|
|
|
|
'snomask': 's',
|
|
|
|
'ssl': 'z',
|
|
|
|
'vhost': 't',
|
|
|
|
'wallops': 'w'}
|
2017-07-08 05:13:52 +02:00
|
|
|
|
2017-06-25 10:12:22 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
2018-09-13 02:18:37 +02:00
|
|
|
self.protocol_caps |= {'slash-in-nicks', 'underscore-in-hosts', 'slash-in-hosts'}
|
2016-03-26 21:26:57 +01:00
|
|
|
# Set our case mapping (rfc1459 maps "\" and "|" together, for example)
|
2015-09-11 03:41:01 +02:00
|
|
|
self.casemapping = 'ascii'
|
2018-09-13 02:20:51 +02:00
|
|
|
|
|
|
|
# Unreal protocol version
|
2019-11-17 21:21:59 +01:00
|
|
|
self.proto_ver = 4203
|
2016-03-26 21:19:06 +01:00
|
|
|
self.min_proto_ver = 4000
|
2018-09-13 02:20:51 +02:00
|
|
|
|
2015-11-12 03:55:05 +01:00
|
|
|
self.hook_map = {'UMODE2': 'MODE', 'SVSKILL': 'KILL', 'SVSMODE': 'MODE',
|
2015-11-22 08:28:39 +01:00
|
|
|
'SVS2MODE': 'MODE', 'SJOIN': 'JOIN', 'SETHOST': 'CHGHOST',
|
2015-12-25 03:09:52 +01:00
|
|
|
'SETIDENT': 'CHGIDENT', 'SETNAME': 'CHGNAME',
|
|
|
|
'EOS': 'ENDBURST'}
|
2015-09-03 22:32:59 +02:00
|
|
|
|
2016-04-09 20:34:09 +02:00
|
|
|
self.caps = []
|
2017-06-25 11:03:12 +02:00
|
|
|
self.prefixmodes = {'q': '~', 'a': '&', 'o': '@', 'h': '%', 'v': '+'}
|
2016-04-09 20:34:09 +02:00
|
|
|
|
2017-01-01 09:21:37 +01:00
|
|
|
self.needed_caps = ["VL", "SID", "CHANMODES", "NOQUIT", "SJ3", "NICKIP", "UMODE2", "SJOIN"]
|
2015-09-05 21:02:45 +02:00
|
|
|
|
2017-07-07 22:35:30 +02:00
|
|
|
# Command aliases to handlers defined in parent modules
|
2015-11-02 06:50:46 +01:00
|
|
|
self.handle_svskill = self.handle_kill
|
2017-07-07 22:35:30 +02:00
|
|
|
self.topic_burst = self.topic
|
2015-11-02 06:50:46 +01:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
### OUTGOING COMMAND FUNCTIONS
|
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-10-13 04:34:52 +02:00
|
|
|
manipulatable=False):
|
2016-04-25 06:17:56 +02:00
|
|
|
"""
|
|
|
|
Spawns a new client with the given options.
|
2015-10-09 05:28:21 +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
|
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
|
|
|
|
2016-03-26 20:55:23 +01:00
|
|
|
# Unreal 4.0 uses TS6-style UIDs. They don't start from AAAAAA like other IRCd's
|
|
|
|
# do, but that doesn't matter to us...
|
2016-04-25 06:16:41 +02:00
|
|
|
uid = self.uidgen[server].next_uid()
|
|
|
|
|
2015-09-11 03:41:01 +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-11 03:41:01 +02:00
|
|
|
realhost = realhost or host
|
2016-08-28 04:14:37 +02:00
|
|
|
|
|
|
|
# Add +xt so that vHost cloaking always works.
|
2016-08-28 04:19:47 +02:00
|
|
|
modes = set(modes) # Ensure type safety
|
2016-08-28 04:14:37 +02:00
|
|
|
modes |= {('+x', None), ('+t', None)}
|
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
raw_modes = self.join_modes(modes)
|
2017-08-25 22:53:45 +02:00
|
|
|
u = self.users[uid] = User(self, 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)
|
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)
|
2015-11-27 07:15:52 +01:00
|
|
|
|
|
|
|
# UnrealIRCd requires encoding the IP by first packing it into a binary format,
|
|
|
|
# and then encoding the binary with Base64.
|
|
|
|
if ip == '0.0.0.0': # Dummy IP (for services, etc.) use a single *.
|
|
|
|
encoded_ip = '*'
|
|
|
|
else:
|
|
|
|
try: # Try encoding as IPv4 first.
|
|
|
|
binary_ip = socket.inet_pton(socket.AF_INET, ip)
|
|
|
|
except OSError:
|
|
|
|
try: # That failed, try IPv6 next.
|
|
|
|
binary_ip = socket.inet_pton(socket.AF_INET6, ip)
|
|
|
|
except OSError:
|
|
|
|
raise ValueError("Invalid IPv4 or IPv6 address %r." % ip)
|
|
|
|
|
|
|
|
# Encode in Base64.
|
|
|
|
encoded_ip = codecs.encode(binary_ip, "base64")
|
|
|
|
# Now, strip the trailing \n and decode into a string again.
|
|
|
|
encoded_ip = encoded_ip.strip().decode()
|
|
|
|
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :001 UID jlu5 0 1441306929 jlu5 localhost 0018S7901 0 +iowx * midnight-1C620195 fwAAAQ== :realname
|
2017-09-24 07:36:16 +02:00
|
|
|
self._send_with_prefix(server, "UID {nick} {hopcount} {ts} {ident} {realhost} {uid} 0 {modes} "
|
|
|
|
"{host} * {ip} :{realname}".format(ts=ts, host=host,
|
|
|
|
nick=nick, ident=ident, uid=uid,
|
|
|
|
modes=raw_modes, realname=realname,
|
|
|
|
realhost=realhost, ip=encoded_ip,
|
|
|
|
hopcount=self.servers[server].hopcount))
|
2015-11-27 07:34:15 +01:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
return u
|
2015-09-03 22:32:59 +02:00
|
|
|
|
2016-01-17 01:36:45 +01:00
|
|
|
def join(self, client, channel):
|
2015-10-13 04:38:38 +02:00
|
|
|
"""Joins a PyLink client to a channel."""
|
2017-06-30 07:56:14 +02:00
|
|
|
if not self.is_internal_client(client):
|
2015-10-13 04:38:38 +02:00
|
|
|
raise LookupError('No such PyLink client exists.')
|
2018-08-26 00:50:11 +02:00
|
|
|
|
|
|
|
# Forward this on to SJOIN, as using JOIN in Unreal S2S seems to cause TS corruption bugs.
|
|
|
|
# This seems to be what Unreal itself does anyways.
|
2018-09-22 06:40:27 +02:00
|
|
|
if channel not in self.channels:
|
2018-08-26 00:50:11 +02:00
|
|
|
prefix = 'o' # Create new channels with the first joiner as op
|
|
|
|
else:
|
|
|
|
prefix = ''
|
|
|
|
self.sjoin(self.sid, channel, [(prefix, client)])
|
2015-10-13 04:38:38 +02:00
|
|
|
|
2016-06-23 06:34:16 +02:00
|
|
|
def sjoin(self, server, channel, users, ts=None, modes=set()):
|
2015-10-13 04:38:38 +02:00
|
|
|
"""Sends an SJOIN for a group of users to a channel.
|
|
|
|
|
2015-11-09 00:26:17 +01:00
|
|
|
The sender should always be a server (SID). TS is optional, and defaults
|
2015-10-13 04:38:38 +02:00
|
|
|
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-10-13 04:38:38 +02:00
|
|
|
"""
|
2017-01-01 09:00:01 +01:00
|
|
|
# <- :001 SJOIN 1444361345 #test :*@+1JJAAAAAB %2JJAAAA4C 1JJAAAADS
|
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?"
|
2015-10-13 04:38:38 +02:00
|
|
|
if not server:
|
|
|
|
raise LookupError('No such PyLink server exists.')
|
2015-11-09 00:26:17 +01:00
|
|
|
|
2017-08-25 11:11:48 +02:00
|
|
|
changedmodes = 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
|
2015-10-13 04:38:38 +02:00
|
|
|
uids = []
|
2017-01-01 09:00:01 +01:00
|
|
|
itemlist = []
|
2016-06-23 06:34:16 +02:00
|
|
|
|
2015-10-13 04:38:38 +02:00
|
|
|
for userpair in users:
|
|
|
|
assert len(userpair) == 2, "Incorrect format of userpair: %r" % userpair
|
|
|
|
prefixes, user = userpair
|
2016-06-23 06:34:16 +02:00
|
|
|
|
2015-10-13 04:38:38 +02:00
|
|
|
# Unreal uses slightly different prefixes in SJOIN. +q is * instead of ~,
|
|
|
|
# and +a is ~ instead of &.
|
|
|
|
# &, ", and ' are used for bursting bans.
|
2017-01-01 09:00:01 +01:00
|
|
|
prefixchars = ''.join([SJOIN_PREFIXES.get(prefix, '') for prefix in prefixes])
|
2016-06-23 06:34:16 +02:00
|
|
|
|
2015-10-13 04:38:38 +02:00
|
|
|
if prefixchars:
|
2016-06-23 06:34:16 +02:00
|
|
|
changedmodes |= {('+%s' % prefix, user) for prefix in prefixes}
|
|
|
|
|
2017-01-01 09:00:01 +01:00
|
|
|
itemlist.append(prefixchars+user)
|
2015-10-13 04:38:38 +02:00
|
|
|
uids.append(user)
|
2016-06-23 06:34:16 +02:00
|
|
|
|
2015-10-13 04:38:38 +02:00
|
|
|
try:
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[user].channels.add(channel)
|
2015-10-13 04:38:38 +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
|
|
|
|
2017-01-01 09:00:01 +01:00
|
|
|
# Track simple modes separately.
|
|
|
|
simplemodes = set()
|
|
|
|
for modepair in modes:
|
2017-06-25 11:03:12 +02:00
|
|
|
if modepair[0][-1] in self.cmodes['*A']:
|
2017-01-01 09:00:01 +01:00
|
|
|
# Bans, exempts, invex get expanded to forms like "&*!*@some.host" in SJOIN.
|
|
|
|
|
2017-08-25 11:11:48 +02:00
|
|
|
if (modepair[0][-1], modepair[1]) in self._channels[channel].modes:
|
2017-01-01 09:00:01 +01:00
|
|
|
# Mode is already set; skip it.
|
|
|
|
continue
|
2016-06-23 06:34:16 +02:00
|
|
|
|
2017-01-01 09:00:01 +01:00
|
|
|
sjoin_prefix = SJOIN_PREFIXES.get(modepair[0][-1])
|
|
|
|
if sjoin_prefix:
|
|
|
|
itemlist.append(sjoin_prefix+modepair[1])
|
|
|
|
else:
|
|
|
|
simplemodes.add(modepair)
|
2016-06-23 06:34:16 +02:00
|
|
|
|
2017-01-01 09:00:01 +01:00
|
|
|
# Store the part of the SJOIN that we may reuse due to line wrapping (i.e. the sjoin
|
|
|
|
# "prefix")
|
2017-01-07 03:29:47 +01:00
|
|
|
sjoin_prefix = ":{sid} SJOIN {ts} {channel}".format(sid=server, ts=ts, channel=channel)
|
2017-01-01 09:00:01 +01:00
|
|
|
|
|
|
|
# Modes are optional; add them if they exist
|
2016-06-23 06:34:16 +02:00
|
|
|
if modes:
|
2017-06-30 07:56:14 +02:00
|
|
|
sjoin_prefix += " %s" % self.join_modes(simplemodes)
|
2017-01-01 09:00:01 +01:00
|
|
|
|
|
|
|
sjoin_prefix += " :"
|
|
|
|
# Wrap arguments to the max supported S2S line length to prevent cutoff
|
2018-07-08 21:53:59 +02:00
|
|
|
# (https://github.com/jlu5/PyLink/issues/378)
|
2018-03-03 05:06:23 +01:00
|
|
|
for line in utils.wrap_arguments(sjoin_prefix, itemlist, self.S2S_BUFSIZE):
|
2017-06-25 11:03:12 +02:00
|
|
|
self.send(line)
|
2016-06-23 06:34:16 +02:00
|
|
|
|
2017-08-25 11:11:48 +02:00
|
|
|
self._channels[channel].users.update(uids)
|
2016-06-23 06:34:16 +02:00
|
|
|
|
2016-07-11 06:35:17 +02:00
|
|
|
self.updateTS(server, channel, ts, changedmodes)
|
2015-09-03 22:32:59 +02:00
|
|
|
|
2017-07-05 07:09:50 +02:00
|
|
|
def _ping_uplink(self):
|
|
|
|
"""Sends a PING to the uplink."""
|
|
|
|
if self.sid and self.uplink:
|
|
|
|
self._send_with_prefix(self.sid, 'PING %s %s' % (self.get_friendly_name(self.sid), self.get_friendly_name(self.uplink)))
|
2015-09-04 01:07:30 +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. The mode list should be
|
2017-06-30 07:56:14 +02:00
|
|
|
a list of (mode, arg) tuples, i.e. the format of utils.parse_modes() output.
|
2016-01-17 02:08:17 +01:00
|
|
|
"""
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :unreal.midnight.vpn MODE #test +ntCo jlu5 1444361345
|
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)
|
2017-01-02 21:16:35 +01:00
|
|
|
|
2017-08-29 05:07:12 +02:00
|
|
|
if self.is_channel(target):
|
2017-09-06 06:21:16 +02:00
|
|
|
modes = list(modes) # Needed for indexing
|
2018-09-16 20:29:05 +02:00
|
|
|
|
2017-04-01 21:39:38 +02:00
|
|
|
# Make sure we expand any PUIDs when sending outgoing modes...
|
|
|
|
for idx, mode in enumerate(modes):
|
2017-06-25 11:03:12 +02:00
|
|
|
if mode[0][-1] in self.prefixmodes:
|
|
|
|
log.debug('(%s) mode: expanding PUID of mode %s', self.name, str(mode))
|
2017-04-01 21:39:38 +02:00
|
|
|
modes[idx] = (mode[0], self._expandPUID(mode[1]))
|
|
|
|
|
2015-11-12 04:24:57 +01:00
|
|
|
# The MODE command is used for channel mode changes only
|
2017-08-25 11:11:48 +02:00
|
|
|
ts = ts or self._channels[target].ts
|
2017-01-02 21:16:35 +01:00
|
|
|
|
|
|
|
# 7 characters for "MODE", the space between MODE and the target, the space between the
|
|
|
|
# target and mode list, and the space between the mode list and TS.
|
2017-07-08 05:13:52 +02:00
|
|
|
bufsize = self.S2S_BUFSIZE - 7
|
2017-01-02 21:16:35 +01:00
|
|
|
|
|
|
|
# Subtract the length of the TS and channel arguments
|
|
|
|
bufsize -= len(str(ts))
|
|
|
|
bufsize -= len(target)
|
|
|
|
|
|
|
|
# Subtract the prefix (":SID " for servers or ":SIDAAAAAA " for servers)
|
2017-06-30 07:56:14 +02:00
|
|
|
bufsize -= (5 if self.is_internal_server(numeric) else 11)
|
2017-01-02 21:16:35 +01:00
|
|
|
|
2017-01-14 08:58:11 +01:00
|
|
|
# There is also an (undocumented) 15 args per line limit for MODE. The target, mode
|
|
|
|
# characters, and TS take up three args, so we're left with 12 spaces for parameters.
|
|
|
|
# Any lines that go over 15 args/line has the potential of corrupting a channel's TS
|
|
|
|
# pretty badly, as the last argument gets mangled into a number:
|
|
|
|
# * *** Warning! Possible desynch: MODE for channel #test ('+bbbbbbbbbbbb *!*@0.1 *!*@1.1 *!*@2.1 *!*@3.1 *!*@4.1 *!*@5.1 *!*@6.1 *!*@7.1 *!*@8.1 *!*@9.1 *!*@10.1 *!*@11.1') has fishy timestamp (12) (from pylink.local/pylink.local)
|
|
|
|
|
|
|
|
# Thanks to kevin and Jobe for helping me debug this!
|
2017-06-30 07:56:14 +02:00
|
|
|
for modestring in self.wrap_modes(modes, bufsize, max_modes_per_msg=12):
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(numeric, 'MODE %s %s %s' % (target, modestring, ts))
|
2015-11-12 04:24:57 +01:00
|
|
|
else:
|
|
|
|
# For user modes, the only way to set modes (for non-U:Lined servers)
|
|
|
|
# is through UMODE2, which sets the modes on the caller.
|
|
|
|
# U:Lines can use SVSMODE/SVS2MODE, but I won't expect people to
|
|
|
|
# U:Line a PyLink daemon...
|
2017-06-30 07:56:14 +02:00
|
|
|
if not self.is_internal_client(target):
|
2015-11-12 04:24:57 +01:00
|
|
|
raise ProtocolError('Cannot force mode change on external clients!')
|
2017-01-02 21:16:35 +01:00
|
|
|
|
|
|
|
# XXX: I don't expect usermode changes to ever get cut off, but length
|
|
|
|
# checks could be added just to be safe...
|
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(target, 'UMODE2 %s' % joinedmodes)
|
2015-11-12 04:24:57 +01:00
|
|
|
|
2017-07-17 17:13:28 +02:00
|
|
|
def set_server_ban(self, source, duration, user='*', host='*', reason='User banned'):
|
|
|
|
"""
|
|
|
|
Sets a server ban.
|
|
|
|
"""
|
|
|
|
# Permanent:
|
|
|
|
# <- :unreal.midnight.vpn TKL + G ident host.net james!james@localhost 0 1500303745 :no reason
|
|
|
|
# Temporary:
|
|
|
|
# <- :unreal.midnight.vpn TKL + G * everyone james!james@localhost 1500303702 1500303672 :who needs reasons, do people even read them?
|
|
|
|
assert not (user == host == '*'), "Refusing to set ridiculous ban on *@*"
|
|
|
|
|
|
|
|
if source in self.users:
|
|
|
|
# GLINEs are always forwarded from the server as far as I can tell.
|
|
|
|
real_source = self.get_server(source)
|
|
|
|
else:
|
|
|
|
real_source = source
|
|
|
|
|
|
|
|
setter = self.get_hostmask(source) if source in self.users else self.get_friendly_name(source)
|
|
|
|
currtime = int(time.time())
|
|
|
|
self._send_with_prefix(real_source, 'TKL + G %s %s %s %s %s :%s' % (user, host, setter, currtime+duration if duration != 0 else 0, currtime, 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 ident, host, or realname of any connected client."""
|
2015-11-15 18:45:46 +01: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 SETIDENT/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, 'SETIDENT %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, 'SETHOST %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, 'SETNAME :%s' % text)
|
2015-11-15 18:45:46 +01: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-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-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-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-11-15 18:45:46 +01:00
|
|
|
|
2016-01-17 01:41:17 +01:00
|
|
|
def knock(self, numeric, target, text):
|
2015-11-16 06:09:40 +01:00
|
|
|
"""Sends a KNOCK from a PyLink client."""
|
|
|
|
# KNOCKs in UnrealIRCd are actually just specially formatted NOTICEs,
|
|
|
|
# sent to all ops in a channel.
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :unreal.midnight.vpn NOTICE @#test :[Knock] by jlu5|!jlu5@hidden-1C620195 (test)
|
2017-08-29 05:07:12 +02:00
|
|
|
assert self.is_channel(target), "Can only knock on channels!"
|
2017-06-30 07:56:14 +02:00
|
|
|
sender = self.get_server(numeric)
|
|
|
|
s = '[Knock] by %s (%s)' % (self.get_hostmask(numeric), text)
|
2017-06-25 08:40:41 +02:00
|
|
|
self._send_with_prefix(sender, 'NOTICE @%s :%s' % (target, s))
|
2015-11-16 06:09:40 +01:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
### HANDLERS
|
2015-09-05 21:02:45 +02:00
|
|
|
|
2017-06-25 10:12:22 +02:00
|
|
|
def post_connect(self):
|
2015-10-09 05:28:21 +02:00
|
|
|
"""Initializes a connection to a server."""
|
2017-06-25 11:03:12 +02:00
|
|
|
ts = self.start_ts
|
|
|
|
self.prefixmodes = {'q': '~', 'a': '&', 'o': '@', 'h': '%', 'v': '+'}
|
2015-11-22 08:57:24 +01:00
|
|
|
|
2016-07-29 06:59:56 +02:00
|
|
|
# Track usages of legacy (Unreal 3.2) nicks.
|
2017-08-29 04:42:10 +02:00
|
|
|
self.legacy_uidgen = PUIDGenerator('U32user')
|
2016-04-02 08:02:12 +02:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
f = self.send
|
|
|
|
host = self.serverdata["hostname"]
|
2015-12-07 02:44:59 +01:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
f('PASS :%s' % self.serverdata["sendpass"])
|
2016-06-22 02:03:23 +02:00
|
|
|
# https://github.com/unrealircd/unrealircd/blob/2f8cb55e/doc/technical/protoctl.txt
|
2015-09-11 03:41:01 +02:00
|
|
|
# We support the following protocol features:
|
2017-01-01 07:15:42 +01:00
|
|
|
# SJOIN - supports SJOIN for user introduction
|
2015-09-11 03:41:01 +02:00
|
|
|
# SJ3 - extended SJOIN
|
|
|
|
# NOQUIT - QUIT messages aren't sent for all users in a netsplit
|
|
|
|
# NICKv2 - Extended NICK command, sending MODE and CHGHOST info with it
|
2016-04-09 19:17:25 +02:00
|
|
|
# SID - Use UIDs and SIDs (Unreal 4)
|
2015-09-11 03:41:01 +02:00
|
|
|
# VL - Sends version string in below SERVER message
|
|
|
|
# UMODE2 - used for users setting modes on themselves (one less argument needed)
|
2016-04-09 19:17:25 +02:00
|
|
|
# EAUTH - Early auth? (Unreal 4 linking protocol)
|
|
|
|
# NICKIP - Extends the NICK command used for introduction (for Unreal 3.2 servers)
|
|
|
|
# to include user IPs.
|
2016-08-09 02:05:28 +02:00
|
|
|
# VHP - Sends cloaked hosts of UnrealIRCd 3.2 users as the hostname. This is important
|
|
|
|
# because UnrealIRCd 3.2 only has one vHost field in its NICK command, and not two
|
|
|
|
# like UnrealIRCd 4.0 (cloaked host + displayed host). Without VHP, cloaking does
|
|
|
|
# not work for any UnrealIRCd 3.2 users.
|
2016-08-09 02:28:45 +02:00
|
|
|
# ESVID - Supports account names in services stamps instead of just the signon time.
|
|
|
|
# AFAIK this doesn't actually affect services' behaviour?
|
2021-06-10 05:18:34 +02:00
|
|
|
# EXTSWHOIS - support multiple SWHOIS lines (purely informational for us)
|
|
|
|
f('PROTOCTL SJOIN SJ3 NOQUIT NICKv2 VL UMODE2 PROTOCTL NICKIP EAUTH=%s SID=%s VHP ESVID EXTSWHOIS' % (self.serverdata["hostname"], self.sid))
|
2018-02-19 08:26:39 +01:00
|
|
|
sdesc = self.serverdata.get('serverdesc') or conf.conf['pylink']['serverdesc']
|
2017-06-25 11:03:12 +02:00
|
|
|
f('SERVER %s 1 U%s-h6e-%s :%s' % (host, self.proto_ver, self.sid, sdesc))
|
2019-11-30 08:03:35 +01:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
self._send_with_prefix(self.sid, 'EOS')
|
2015-11-22 08:57:24 +01:00
|
|
|
|
2017-08-06 06:52:34 +02:00
|
|
|
# Extban definitions
|
2019-08-23 03:48:46 +02:00
|
|
|
self.extbans_acting = {'quiet': '~q:',
|
|
|
|
'ban_nonick': '~n:',
|
|
|
|
'ban_nojoins': '~j:',
|
|
|
|
'filter': '~T:block:',
|
|
|
|
'filter_censor': '~T:censor:',
|
|
|
|
'msgbypass_external': '~m:external:',
|
|
|
|
'msgbypass_censor': '~m:censor:',
|
|
|
|
'msgbypass_moderated': '~m:moderated:',
|
|
|
|
# These two sort of map to InspIRCd +e S: and +e T:
|
|
|
|
'ban_stripcolor': '~m:color:',
|
|
|
|
'ban_nonotice': '~m:notice:',
|
|
|
|
'timedban_unreal': '~t:'}
|
|
|
|
self.extbans_matching = {'ban_account': '~a:',
|
|
|
|
'ban_inchannel': '~c:',
|
|
|
|
'ban_opertype': '~O:',
|
|
|
|
'ban_realname': '~r:',
|
|
|
|
'ban_account_legacy': '~R:',
|
|
|
|
'ban_certfp': '~S:'}
|
2017-08-06 06:52:34 +02:00
|
|
|
|
2015-12-25 03:09:52 +01:00
|
|
|
def handle_eos(self, numeric, command, args):
|
|
|
|
"""EOS is used to denote end of burst."""
|
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-12-25 03:09:52 +01:00
|
|
|
return {}
|
2015-09-03 22:32:59 +02:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
def handle_uid(self, numeric, command, args):
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :001 UID jlu5 0 1441306929 jlu5 localhost 0018S7901 0 +iowx * midnight-1C620195 fwAAAQ== :realname
|
|
|
|
# <- :001 UID jlu5| 0 1441389007 jlu5 10.120.0.6 001ZO8F03 0 +iwx * 391A9CB9.26A16454.D9847B69.IP CngABg== :realname
|
2016-02-21 03:16:21 +01:00
|
|
|
# arguments: nick, hopcount?, ts, ident, real-host, UID, services account (0 if none), modes,
|
2015-11-22 22:07:25 +01:00
|
|
|
# displayed host, cloaked (+x) host, base64-encoded IP, and realname
|
2015-09-11 03:41:01 +02:00
|
|
|
nick = args[0]
|
2017-07-07 12:18:40 +02:00
|
|
|
self._check_nick_collision(nick)
|
2016-02-21 03:16:21 +01:00
|
|
|
ts, ident, realhost, uid, accountname, modestring, host = args[2:9]
|
2018-05-27 01:22:36 +02:00
|
|
|
ts = int(ts)
|
2016-02-21 03:16:21 +01:00
|
|
|
|
2015-11-22 22:07:25 +01:00
|
|
|
if host == '*':
|
|
|
|
# A single * means that there is no displayed/virtual host, and
|
|
|
|
# that it's the same as the real host
|
2015-11-29 05:55:14 +01:00
|
|
|
host = args[9]
|
2016-02-21 03:16:21 +01:00
|
|
|
|
|
|
|
# Decode UnrealIRCd's IPs, which are stored in base64-encoded network structure
|
2015-10-13 03:45:25 +02:00
|
|
|
raw_ip = args[10].encode() # codecs.decode only takes bytes, not str
|
|
|
|
if raw_ip == b'*': # Dummy IP (for services, etc.)
|
|
|
|
ip = '0.0.0.0'
|
|
|
|
else:
|
2015-11-27 07:15:52 +01:00
|
|
|
# First, decode the Base64 string into a packed binary IP address.
|
|
|
|
ip = codecs.decode(raw_ip, "base64")
|
|
|
|
|
|
|
|
try: # IPv4 address.
|
|
|
|
ip = socket.inet_ntop(socket.AF_INET, ip)
|
|
|
|
except ValueError: # IPv6 address.
|
|
|
|
ip = socket.inet_ntop(socket.AF_INET6, ip)
|
|
|
|
# HACK: make sure a leading ":" in the IPv6 address (e.g. ::1)
|
|
|
|
# doesn't cause it to be misinterpreted as the last argument
|
|
|
|
# in a line, should it be mirrored to other networks.
|
|
|
|
if ip.startswith(':'):
|
|
|
|
ip = '0' + ip
|
2016-02-21 03:16:21 +01:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
realname = args[-1]
|
2016-01-03 20:09:40 +01:00
|
|
|
|
2018-05-27 01:22:36 +02:00
|
|
|
self.users[uid] = User(self, nick, ts, uid, numeric, ident, host, realname, realhost, ip)
|
2017-06-25 11:03:12 +02:00
|
|
|
self.servers[numeric].users.add(uid)
|
2016-01-03 20:09:40 +01:00
|
|
|
|
2016-02-21 03:16:21 +01:00
|
|
|
# Handle user modes
|
2017-06-30 07:56:14 +02:00
|
|
|
parsedmodes = self.parse_modes(uid, [modestring])
|
|
|
|
self.apply_modes(uid, parsedmodes)
|
2015-11-22 22:07:25 +01:00
|
|
|
|
|
|
|
# The cloaked (+x) host is completely separate from the displayed host
|
|
|
|
# and real host in that it is ONLY shown if the user is +x (cloak mode
|
2016-07-28 02:37:56 +02:00
|
|
|
# enabled) but NOT +t (vHost set).
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[uid].cloaked_host = args[9]
|
2015-11-22 22:07:25 +01:00
|
|
|
|
2017-07-08 05:02:37 +02:00
|
|
|
self._check_oper_status_change(uid, parsedmodes)
|
2015-12-18 06:37:01 +01:00
|
|
|
|
2016-01-03 20:09:40 +01:00
|
|
|
if ('+x', None) not in parsedmodes:
|
|
|
|
# If +x is not set, update to use the person's real host.
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[uid].host = realhost
|
2016-01-03 20:09:40 +01:00
|
|
|
|
2016-08-09 01:35:10 +02:00
|
|
|
# Set the account name if present: if this is a number, set it to the user nick.
|
|
|
|
if ('+r', None) in parsedmodes and accountname.isdigit():
|
2016-07-28 02:38:17 +02:00
|
|
|
accountname = nick
|
|
|
|
|
2020-10-19 22:58:45 +02:00
|
|
|
# Track SSL/TLS status
|
|
|
|
self.users[uid].ssl = ('+z', None) in parsedmodes
|
|
|
|
|
2016-08-09 01:35:10 +02:00
|
|
|
if not accountname.isdigit():
|
2017-06-30 07:56:14 +02:00
|
|
|
self.call_hooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': accountname}])
|
2016-02-21 03:16:21 +01:00
|
|
|
|
2017-10-15 10:55:53 +02:00
|
|
|
# parse_as is used here to prevent legacy user introduction from being confused
|
|
|
|
# with a nick change.
|
|
|
|
return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host,
|
|
|
|
'ident': ident, 'ip': ip, 'parse_as': 'UID'}
|
2015-09-03 22:32:59 +02:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
def handle_pass(self, numeric, command, args):
|
|
|
|
# <- PASS :abcdefg
|
2017-06-25 11:03:12 +02:00
|
|
|
if args[0] != self.serverdata['recvpass']:
|
2017-07-03 07:52:46 +02:00
|
|
|
raise ProtocolError("RECVPASS from uplink does not match configuration!")
|
2015-09-04 01:07:30 +02:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
def handle_ping(self, numeric, command, args):
|
2017-06-25 11:03:12 +02:00
|
|
|
if numeric == self.uplink:
|
|
|
|
self.send('PONG %s :%s' % (self.serverdata['hostname'], args[-1]), queue=False)
|
2015-09-04 01:07:30 +02:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
def handle_server(self, numeric, command, args):
|
2015-10-13 03:17:58 +02:00
|
|
|
"""Handles the SERVER command, which is used for both authentication and
|
|
|
|
introducing legacy (non-SID) servers."""
|
|
|
|
# <- SERVER unreal.midnight.vpn 1 :U3999-Fhin6OoEM UnrealIRCd test server
|
2015-09-11 03:41:01 +02:00
|
|
|
sname = args[0]
|
2017-10-15 10:54:39 +02:00
|
|
|
if self.uplink not in self.servers: # We're doing authentication
|
2016-04-09 20:34:09 +02:00
|
|
|
for cap in self.needed_caps:
|
2015-09-11 03:41:01 +02:00
|
|
|
if cap not in self.caps:
|
|
|
|
raise ProtocolError("Not all required capabilities were met "
|
|
|
|
"by the remote server. Your version of UnrealIRCd "
|
|
|
|
"is probably too old! (Got: %s, needed: %s)" %
|
2016-04-09 20:34:09 +02:00
|
|
|
(sorted(self.caps), sorted(self.needed_caps)))
|
2016-07-12 01:20:10 +02:00
|
|
|
|
|
|
|
sdesc = args[-1].split(" ", 1)
|
|
|
|
# Get our protocol version. I really don't know why the version and the server
|
2021-06-10 05:15:07 +02:00
|
|
|
# description aren't two arguments instead of one... -jlu5
|
2015-09-11 03:41:01 +02:00
|
|
|
vline = sdesc[0].split('-', 1)
|
2016-07-12 01:20:10 +02:00
|
|
|
sdesc = " ".join(sdesc[1:])
|
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
try:
|
|
|
|
protover = int(vline[0].strip('U'))
|
|
|
|
except ValueError:
|
2015-10-13 03:17:58 +02:00
|
|
|
raise ProtocolError("Protocol version too old! (needs at least %s "
|
2016-07-12 01:20:10 +02:00
|
|
|
"(Unreal 4.x), got something invalid; "
|
2015-10-13 03:17:58 +02:00
|
|
|
"is VL being sent?)" % self.min_proto_ver)
|
2016-07-12 01:20:10 +02:00
|
|
|
|
2015-10-13 03:17:58 +02:00
|
|
|
if protover < self.min_proto_ver:
|
|
|
|
raise ProtocolError("Protocol version too old! (needs at least %s "
|
2016-07-12 01:20:10 +02:00
|
|
|
"(Unreal 4.x), got %s)" % (self.min_proto_ver, protover))
|
2017-08-25 22:53:45 +02:00
|
|
|
self.servers[numeric] = Server(self, None, sname, desc=sdesc)
|
2016-04-02 04:08:25 +02:00
|
|
|
|
2019-11-17 21:21:59 +01:00
|
|
|
# Prior to 4203, Unreal did not send PROTOCTL USERMODES (see handle_protoctl() )
|
|
|
|
if protover < 4203:
|
|
|
|
self.umodes.update(self._KNOWN_UMODES)
|
|
|
|
self.umodes['*D'] = ''.join(self._KNOWN_UMODES.values())
|
2015-09-11 03:41:01 +02:00
|
|
|
else:
|
2015-10-13 03:15:39 +02:00
|
|
|
# Legacy (non-SID) servers can still be introduced using the SERVER command.
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :services.int SERVER a.bc 2 :(H) [jlu5] a
|
2017-08-11 04:50:32 +02:00
|
|
|
return super().handle_server(numeric, command, args)
|
2015-10-10 07:38:28 +02:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
def handle_protoctl(self, numeric, command, args):
|
2016-04-09 20:34:09 +02:00
|
|
|
"""Handles protocol negotiation."""
|
|
|
|
# Make a list of all our capability names.
|
|
|
|
self.caps += [arg.split('=')[0] for arg in args]
|
|
|
|
|
2019-11-17 21:21:59 +01:00
|
|
|
# Unreal 4.0.x:
|
2015-09-11 03:41:01 +02:00
|
|
|
# <- PROTOCTL NOQUIT NICKv2 SJOIN SJOIN2 UMODE2 VL SJ3 TKLEXT TKLEXT2 NICKIP ESVID
|
|
|
|
# <- PROTOCTL CHANMODES=beI,k,l,psmntirzMQNRTOVKDdGPZSCc NICKCHARS= SID=001 MLOCK TS=1441314501 EXTSWHOIS
|
2019-11-17 21:21:59 +01:00
|
|
|
# Unreal 4.2.x:
|
|
|
|
# <- PROTOCTL NOQUIT NICKv2 SJOIN SJOIN2 UMODE2 VL SJ3 TKLEXT TKLEXT2 NICKIP ESVID SJSBY
|
|
|
|
# <- PROTOCTL CHANMODES=beI,kLf,l,psmntirzMQNRTOVKDdGPZSCc USERMODES=iowrsxzdHtIDZRqpWGTSB BOOTED=1574014839 PREFIX=(qaohv)~&@%+ NICKCHARS= SID=001 MLOCK TS=1574020869 EXTSWHOIS
|
|
|
|
# Unreal 5.0.0-rc1:
|
|
|
|
# <- PROTOCTL NOQUIT NICKv2 SJOIN SJOIN2 UMODE2 VL SJ3 TKLEXT TKLEXT2 NICKIP ESVID SJSBY MTAGS
|
|
|
|
# <- PROTOCTL CHANMODES=beI,kLf,lH,psmntirzMQNRTOVKDdGPZSCc USERMODES=iowrsxzdHtIDZRqpWGTSB BOOTED=1574020755 PREFIX=(qaohv)~&@%+ SID=001 MLOCK TS=1574020823 EXTSWHOIS
|
|
|
|
# <- PROTOCTL NICKCHARS= CHANNELCHARS=utf8
|
2015-09-11 03:41:01 +02:00
|
|
|
for cap in args:
|
|
|
|
if cap.startswith('SID'):
|
2017-06-25 11:03:12 +02:00
|
|
|
self.uplink = cap.split('=', 1)[1]
|
2015-09-11 03:41:01 +02:00
|
|
|
elif cap.startswith('CHANMODES'):
|
2016-04-09 20:34:09 +02:00
|
|
|
# Parse all the supported channel modes.
|
|
|
|
supported_cmodes = cap.split('=', 1)[1]
|
2017-06-25 11:03:12 +02:00
|
|
|
self.cmodes['*A'], self.cmodes['*B'], self.cmodes['*C'], self.cmodes['*D'] = supported_cmodes.split(',')
|
2019-11-17 21:21:59 +01:00
|
|
|
for namedmode, modechar in self._KNOWN_CMODES.items():
|
2016-04-09 20:34:09 +02:00
|
|
|
if modechar in supported_cmodes:
|
2017-06-25 11:03:12 +02:00
|
|
|
self.cmodes[namedmode] = modechar
|
2019-11-17 21:21:59 +01:00
|
|
|
elif cap.startswith('USERMODES'): # Only for protover >= 4203
|
|
|
|
self.umodes['*D'] = supported_umodes = cap.split('=', 1)[1]
|
|
|
|
for namedmode, modechar in self._KNOWN_UMODES.items():
|
|
|
|
if modechar in supported_umodes:
|
|
|
|
self.umodes[namedmode] = modechar
|
2016-04-09 20:34:09 +02:00
|
|
|
|
|
|
|
# Add in the supported prefix modes.
|
2017-06-25 11:03:12 +02:00
|
|
|
self.cmodes.update({'halfop': 'h', 'admin': 'a', 'owner': 'q',
|
2019-11-17 21:21:59 +01:00
|
|
|
'op': 'o', 'voice': 'v'})
|
2015-09-04 01:07:30 +02:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
def handle_join(self, numeric, command, args):
|
2015-10-09 05:46:30 +02:00
|
|
|
"""Handles the UnrealIRCd JOIN command."""
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :jlu5 JOIN #pylink,#test
|
2016-04-29 04:17:20 +02:00
|
|
|
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()
|
2016-04-29 04:17:20 +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)
|
2016-04-29 04:17:20 +02:00
|
|
|
for ch in oldchans:
|
2017-08-25 11:11:48 +02:00
|
|
|
self._channels[ch].users.discard(numeric)
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[numeric].channels.discard(ch)
|
2016-04-29 04:17:20 +02:00
|
|
|
return {'channels': oldchans, 'text': 'Left all channels.', 'parse_as': 'PART'}
|
|
|
|
|
|
|
|
else:
|
|
|
|
for channel in args[0].split(','):
|
2017-08-25 11:11:48 +02:00
|
|
|
c = self._channels[channel]
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[numeric].channels.add(channel)
|
2017-08-25 11:11:48 +02:00
|
|
|
self._channels[channel].users.add(numeric)
|
2016-04-29 04:17:20 +02:00
|
|
|
# Call hooks manually, because one JOIN command in UnrealIRCd can
|
|
|
|
# have multiple channels...
|
2017-06-30 07:56:14 +02:00
|
|
|
self.call_hooks([numeric, command, {'channel': channel, 'users': [numeric], 'modes':
|
2016-04-29 04:17:20 +02:00
|
|
|
c.modes, 'ts': c.ts}])
|
2015-09-05 21:29:20 +02:00
|
|
|
|
2015-10-09 05:46:30 +02:00
|
|
|
def handle_sjoin(self, numeric, command, args):
|
|
|
|
"""Handles the UnrealIRCd SJOIN command."""
|
2017-01-01 07:15:42 +01:00
|
|
|
# <- :001 SJOIN 1444361345 #test :001AAAAAA @001AAAAAB +001AAAAAC
|
2017-01-01 09:00:01 +01:00
|
|
|
# <- :001 SJOIN 1483250129 #services +nt :+001OR9V02 @*~001DH6901 &*!*@test "*!*@blah.blah '*!*@yes.no
|
2017-08-08 06:54:33 +02:00
|
|
|
channel = args[1]
|
2017-08-25 11:11:48 +02:00
|
|
|
chandata = self._channels[channel].deepcopy()
|
2015-10-09 05:46:30 +02:00
|
|
|
userlist = args[-1].split()
|
2015-11-09 00:26:17 +01:00
|
|
|
|
2015-10-09 05:46:30 +02:00
|
|
|
namelist = []
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug('(%s) handle_sjoin: got userlist %r for %r', self.name, userlist, channel)
|
2016-06-23 07:26:25 +02:00
|
|
|
|
2017-01-01 07:15:42 +01:00
|
|
|
modestring = ''
|
2017-01-01 09:00:01 +01:00
|
|
|
|
2017-01-01 07:15:42 +01:00
|
|
|
# FIXME: Implement edge-case mode conflict handling as documented here:
|
|
|
|
# https://www.unrealircd.org/files/docs/technical/serverprotocol.html#S5_1
|
2017-01-01 09:00:01 +01:00
|
|
|
|
2017-01-01 07:15:42 +01:00
|
|
|
changedmodes = set()
|
2017-01-01 09:20:12 +01:00
|
|
|
parsedmodes = []
|
2017-01-01 07:15:42 +01:00
|
|
|
try:
|
|
|
|
if args[2].startswith('+'):
|
2017-01-02 04:53:41 +01:00
|
|
|
modestring = args[2:-1] or args[2]
|
|
|
|
# Strip extra spaces between the mode argument and the user list, if
|
|
|
|
# there are any. XXX: report this as a bug in unreal's s2s protocol?
|
|
|
|
modestring = [m for m in modestring if m]
|
2017-06-30 07:56:14 +02:00
|
|
|
parsedmodes = self.parse_modes(channel, modestring)
|
2017-01-01 09:20:12 +01:00
|
|
|
changedmodes = set(parsedmodes)
|
2017-01-01 07:15:42 +01:00
|
|
|
except IndexError:
|
|
|
|
pass
|
2016-06-23 07:26:25 +02:00
|
|
|
|
2015-10-09 05:46:30 +02:00
|
|
|
for userpair in userlist:
|
2017-01-01 07:15:42 +01:00
|
|
|
# &, ", and ' entries are used for bursting bans:
|
|
|
|
# https://www.unrealircd.org/files/docs/technical/serverprotocol.html#S5_1
|
|
|
|
if userpair.startswith("&"):
|
|
|
|
changedmodes.add(('+b', userpair[1:]))
|
|
|
|
elif userpair.startswith('"'):
|
|
|
|
changedmodes.add(('+e', userpair[1:]))
|
|
|
|
elif userpair.startswith("'"):
|
|
|
|
changedmodes.add(('+I', userpair[1:]))
|
|
|
|
else:
|
2017-04-01 21:10:19 +02:00
|
|
|
# Note: don't be too zealous in matching here or we'll break with nicks
|
|
|
|
# like "[abcd]".
|
|
|
|
r = re.search(r'([~*@%+]*)(.*)', userpair)
|
2017-01-01 07:15:42 +01:00
|
|
|
user = r.group(2)
|
2017-02-06 07:23:20 +01:00
|
|
|
|
|
|
|
if not user:
|
|
|
|
# Userpair with no user? Ignore. XXX: find out how this is even possible...
|
|
|
|
# <- :002 SJOIN 1486361658 #idlerpg :@
|
|
|
|
continue
|
|
|
|
|
2017-06-17 02:12:48 +02:00
|
|
|
user = self._get_UID(user) # Normalize nicks to UIDs for Unreal 3.2 links
|
2019-03-02 08:34:32 +01:00
|
|
|
if user not in self.users:
|
|
|
|
# Work around a potential race when sending kills on join
|
|
|
|
log.debug("(%s) Ignoring user %s in SJOIN to %s, they don't exist anymore", self.name, user, channel)
|
|
|
|
continue
|
|
|
|
|
2017-01-01 07:15:42 +01:00
|
|
|
# Unreal uses slightly different prefixes in SJOIN. +q is * instead of ~,
|
|
|
|
# and +a is ~ instead of &.
|
|
|
|
modeprefix = (r.group(1) or '').replace("~", "&").replace("*", "~")
|
|
|
|
finalprefix = ''
|
2017-02-06 07:23:20 +01:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug('(%s) handle_sjoin: got modeprefix %r for user %r', self.name, modeprefix, user)
|
2017-01-01 07:15:42 +01: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():
|
2017-01-01 07:15:42 +01:00
|
|
|
if m == prefix:
|
|
|
|
finalprefix += char
|
|
|
|
namelist.append(user)
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[user].channels.add(channel)
|
2017-01-01 07:15:42 +01:00
|
|
|
|
|
|
|
# Only merge the remote's prefix modes if their TS is smaller or equal to ours.
|
|
|
|
changedmodes |= {('+%s' % mode, user) for mode in finalprefix}
|
|
|
|
|
2017-08-25 11:11:48 +02:00
|
|
|
self._channels[channel].users.add(user)
|
2016-06-23 07:26:25 +02:00
|
|
|
|
2017-08-25 11:11:48 +02:00
|
|
|
our_ts = self._channels[channel].ts
|
2016-06-23 07:26:25 +02:00
|
|
|
their_ts = int(args[0])
|
2016-07-11 06:35:17 +02:00
|
|
|
self.updateTS(numeric, channel, their_ts, changedmodes)
|
2016-06-23 07:26:25 +02:00
|
|
|
|
2017-01-01 09:20:12 +01:00
|
|
|
return {'channel': channel, 'users': namelist, 'modes': parsedmodes,
|
2016-09-03 02:52:19 +02:00
|
|
|
'ts': their_ts, 'channeldata': chandata}
|
2015-10-09 05:46:30 +02:00
|
|
|
|
2016-04-02 08:02:12 +02:00
|
|
|
def handle_nick(self, numeric, command, args):
|
|
|
|
"""Handles NICK changes, and legacy NICK introductions from pre-4.0 servers."""
|
2016-07-29 09:37:07 +02:00
|
|
|
if len(args) > 2:
|
2016-04-02 08:02:12 +02:00
|
|
|
# Handle legacy NICK introduction here.
|
|
|
|
# I don't want to rewrite all the user introduction stuff, so I'll just reorder the arguments
|
|
|
|
# so that handle_uid can handle this instead.
|
2016-04-02 08:35:48 +02:00
|
|
|
# But since legacy nicks don't have any UIDs attached, we'll have to store the users
|
2016-07-29 09:37:07 +02:00
|
|
|
# internally using pseudo UIDs. In other words, we need to convert from this:
|
2016-04-02 08:02:12 +02:00
|
|
|
# <- NICK Global 3 1456843578 services novernet.com services.novernet.com 0 +ioS * :Global Noticer
|
|
|
|
# & nick hopcount timestamp username hostname server service-identifier-token :realname
|
2016-08-09 02:05:28 +02:00
|
|
|
# With NICKIP and VHP enabled:
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- NICK legacy32 2 1470699865 jlu5 localhost unreal32.midnight.vpn jlu5 +iowx hidden-1C620195 AAAAAAAAAAAAAAAAAAAAAQ== :realname
|
2016-04-02 08:02:12 +02:00
|
|
|
# to this:
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :001 UID jlu5 0 1441306929 jlu5 localhost 0018S7901 0 +iowx * hidden-1C620195 fwAAAQ== :realname
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug('(%s) got legacy NICK args: %s', self.name, ' '.join(args))
|
2016-04-02 08:02:12 +02:00
|
|
|
|
|
|
|
new_args = args[:] # Clone the old args list
|
2016-04-02 20:51:29 +02:00
|
|
|
servername = new_args[5].lower() # Get the name of the users' server.
|
2016-04-02 08:02:12 +02:00
|
|
|
|
2016-07-29 09:37:07 +02:00
|
|
|
# Fake a UID and put it where it belongs in the new-style UID command. These take the
|
|
|
|
# NICK@COUNTER, where COUNTER is an int starting at 0 and incremented every time a new
|
|
|
|
# user joins.
|
2016-07-29 06:59:56 +02:00
|
|
|
fake_uid = self.legacy_uidgen.next_uid(prefix=args[0])
|
2016-04-02 08:02:12 +02:00
|
|
|
new_args[5] = fake_uid
|
|
|
|
|
2016-08-09 02:05:28 +02:00
|
|
|
# This adds a dummy cloaked host (equal the real host) to put the displayed host in the
|
|
|
|
# right position. As long as the VHP capability is respected, this will propagate +x cloaked
|
|
|
|
# hosts from UnrealIRCd 3.2 users. Otherwise, +x host cloaking won't work!
|
2016-04-02 08:02:12 +02:00
|
|
|
new_args.insert(-2, args[4])
|
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
log.debug('(%s) translating legacy NICK args to: %s', self.name, ' '.join(new_args))
|
2016-04-02 08:02:12 +02:00
|
|
|
|
2016-04-02 19:56:13 +02:00
|
|
|
return self.handle_uid(servername, 'UID_LEGACY', new_args)
|
2016-04-02 08:02:12 +02:00
|
|
|
else:
|
|
|
|
# Normal NICK change, just let ts6_common handle it.
|
2021-06-10 05:15:07 +02:00
|
|
|
# :70MAAAAAA NICK jlu5-devel 1434744242
|
2016-07-29 09:37:07 +02:00
|
|
|
return super().handle_nick(numeric, command, args)
|
2016-04-02 08:02:12 +02:00
|
|
|
|
2015-10-09 06:06:09 +02:00
|
|
|
def handle_mode(self, numeric, command, args):
|
2016-03-21 01:34:13 +01:00
|
|
|
# <- :unreal.midnight.vpn MODE #test +bb test!*@* *!*@bad.net
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :unreal.midnight.vpn MODE #test +q jlu5 1444361345
|
|
|
|
# <- :unreal.midnight.vpn MODE #test +ntCo jlu5 1444361345
|
|
|
|
# <- :unreal.midnight.vpn MODE #test +mntClfo 5 [10t]:5 jlu5 1444361345
|
|
|
|
# <- :jlu5 MODE #services +v jlu5
|
2015-11-02 06:41:41 +01:00
|
|
|
|
|
|
|
# This seems pretty relatively inconsistent - why do some commands have a TS at the end while others don't?
|
|
|
|
# Answer: the first syntax (MODE sent by SERVER) is used for channel bursts - according to Unreal 3.2 docs,
|
|
|
|
# the last argument should be interpreted as a timestamp ONLY if it is a number and the sender is a server.
|
|
|
|
# Ban bursting does not give any TS, nor do normal users setting modes. SAMODE is special though, it will
|
|
|
|
# send 0 as a TS argument (which should be ignored unless breaking the internal channel TS is desired).
|
|
|
|
|
2015-10-09 06:06:09 +02:00
|
|
|
# Also, we need to get rid of that extra space following the +f argument. :|
|
2017-08-29 05:07:12 +02:00
|
|
|
if self.is_channel(args[0]):
|
2017-08-08 06:54:33 +02:00
|
|
|
channel = args[0]
|
2017-08-25 11:11:48 +02:00
|
|
|
oldobj = self._channels[channel].deepcopy()
|
2016-06-23 07:33:09 +02:00
|
|
|
|
2017-01-02 04:53:41 +01:00
|
|
|
modes = [arg for arg in args[1:] if arg] # normalize whitespace
|
2017-06-30 07:56:14 +02:00
|
|
|
parsedmodes = self.parse_modes(channel, modes)
|
2016-06-23 07:33:09 +02:00
|
|
|
|
2015-10-10 06:37:11 +02:00
|
|
|
if parsedmodes:
|
2016-06-23 07:33:09 +02:00
|
|
|
if parsedmodes[0][0] == '+&':
|
2016-07-12 01:37:01 +02:00
|
|
|
# UnrealIRCd uses a & virtual mode to denote mode bounces, meaning that an
|
|
|
|
# attempt to set modes by us was rejected for some reason (usually due to
|
|
|
|
# timestamps). Drop the mode change to prevent mode floods.
|
|
|
|
log.debug("(%s) Received mode bounce %s in channel %s! Our TS: %s",
|
2017-08-25 11:11:48 +02:00
|
|
|
self.name, modes, channel, self._channels[channel].ts)
|
2016-06-23 07:33:09 +02:00
|
|
|
return
|
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
self.apply_modes(channel, parsedmodes)
|
2016-06-23 07:33:09 +02:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
if numeric in self.servers and args[-1].isdigit():
|
2015-11-02 06:41:41 +01:00
|
|
|
# Sender is a server AND last arg is number. Perform TS updates.
|
|
|
|
their_ts = int(args[-1])
|
2015-11-15 18:52:01 +01:00
|
|
|
if their_ts > 0:
|
2016-07-11 06:35:17 +02:00
|
|
|
self.updateTS(numeric, channel, their_ts)
|
2016-09-03 02:52:19 +02:00
|
|
|
return {'target': channel, 'modes': parsedmodes, 'channeldata': oldobj}
|
2015-10-10 06:37:11 +02:00
|
|
|
else:
|
2017-08-11 21:03:19 +02:00
|
|
|
# User mode change
|
|
|
|
target = self._get_UID(args[0])
|
|
|
|
return self._handle_umode(target, self.parse_modes(target, args[1:]))
|
2015-10-10 06:37:11 +02:00
|
|
|
|
2017-06-30 07:20:30 +02:00
|
|
|
def _check_cloak_change(self, uid, parsedmodes):
|
2016-01-03 20:09:40 +01:00
|
|
|
"""
|
|
|
|
Checks whether +x/-x was set in the mode query, and changes the
|
|
|
|
hostname of the user given to or from their cloaked host if True.
|
|
|
|
"""
|
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
userobj = self.users[uid]
|
2016-01-03 20:09:40 +01:00
|
|
|
final_modes = userobj.modes
|
|
|
|
oldhost = userobj.host
|
|
|
|
|
|
|
|
if (('+x', None) in parsedmodes and ('t', None) not in final_modes) \
|
|
|
|
or (('-t', None) in parsedmodes and ('x', None) in final_modes):
|
|
|
|
# If either:
|
|
|
|
# 1) +x is being set, and the user does NOT have +t.
|
|
|
|
# 2) -t is being set, but the user has +x set already.
|
|
|
|
# We should update the user's host to their cloaked host and send
|
|
|
|
# out a hook payload saying that the host has changed.
|
|
|
|
newhost = userobj.host = userobj.cloaked_host
|
|
|
|
elif ('-x', None) in parsedmodes or ('-t', None) in parsedmodes:
|
|
|
|
# Otherwise, if either:
|
|
|
|
# 1) -x is being set.
|
|
|
|
# 2) -t is being set, but the person doesn't have +x set already.
|
|
|
|
# (the case where the person DOES have +x is handled above)
|
|
|
|
# Restore the person's host to the uncloaked real host.
|
|
|
|
newhost = userobj.host = userobj.realhost
|
|
|
|
else:
|
|
|
|
# Nothing changed, just return.
|
|
|
|
return
|
|
|
|
|
|
|
|
if newhost != oldhost:
|
|
|
|
# Only send a payload if the old and new hosts are different.
|
2017-06-30 07:56:14 +02:00
|
|
|
self.call_hooks([uid, 'SETHOST',
|
2016-01-03 20:09:40 +01:00
|
|
|
{'target': uid, 'newhost': newhost}])
|
|
|
|
|
2015-11-09 00:26:48 +01:00
|
|
|
def handle_svsmode(self, numeric, command, args):
|
2016-02-21 03:16:21 +01:00
|
|
|
"""Handles SVSMODE, used by services for setting user modes on others."""
|
2015-11-09 00:26:48 +01:00
|
|
|
# <- :source SVSMODE target +usermodes
|
2017-06-17 02:12:48 +02:00
|
|
|
target = self._get_UID(args[0])
|
2016-01-03 20:09:40 +01:00
|
|
|
|
2017-08-11 21:03:19 +02:00
|
|
|
return self._handle_umode(target, self.parse_modes(target, args[1:]))
|
2016-02-21 03:16:21 +01:00
|
|
|
|
|
|
|
def handle_svs2mode(self, sender, command, args):
|
|
|
|
"""
|
2016-07-28 01:35:40 +02:00
|
|
|
Handles SVS2MODE, which sets services login information on the given target.
|
2016-02-21 03:16:21 +01:00
|
|
|
"""
|
2017-08-11 21:03:19 +02:00
|
|
|
# In a nutshell: check for the +d argument: if it's an integer, ignore
|
|
|
|
# it and set the user's account name to their nick. Otherwise, treat the
|
|
|
|
# parameter as the new account name (this is known as logging in AS some account,
|
|
|
|
# which is supported by atheme and Anope 2.x).
|
2016-08-09 01:35:10 +02:00
|
|
|
|
2016-07-28 01:35:40 +02:00
|
|
|
# Logging in (with account info, atheme):
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :NickServ SVS2MODE jlu5 +rd jlu5
|
2016-02-21 03:16:21 +01:00
|
|
|
|
2016-08-09 01:35:10 +02:00
|
|
|
# Logging in (without account info, anope 2.0?):
|
2016-07-28 01:35:40 +02:00
|
|
|
# <- :NickServ SVS2MODE 001WCO6YK +r
|
|
|
|
|
2016-08-09 01:35:10 +02:00
|
|
|
# Logging in (without account info, anope 1.8):
|
|
|
|
# Note: ignore the timestamp.
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :services.abc.net SVS2MODE jlu5 +rd 1470696723
|
2016-08-09 01:35:10 +02:00
|
|
|
|
2016-07-28 01:35:40 +02:00
|
|
|
# Logging out (atheme):
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :NickServ SVS2MODE jlu5 -r+d 0
|
2016-02-21 03:16:21 +01:00
|
|
|
|
2016-08-09 01:35:10 +02:00
|
|
|
# Logging out (anope 1.8):
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :services.abc.net SVS2MODE jlu5 -r+d 1
|
2016-08-09 01:35:10 +02:00
|
|
|
|
|
|
|
# Logging out (anope 2.0):
|
|
|
|
# <- :NickServ SVS2MODE 009EWLA03 -r
|
|
|
|
|
|
|
|
# Logging in to account from a different nick (atheme):
|
|
|
|
# Note: no +r is being set.
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :NickServ SVS2MODE somenick +d jlu5
|
2016-02-21 03:16:21 +01:00
|
|
|
|
2016-07-28 01:35:40 +02:00
|
|
|
# Logging in to account from a different nick (anope):
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :NickServ SVS2MODE 001SALZ01 +d jlu5
|
2016-07-28 01:35:40 +02:00
|
|
|
# <- :NickServ SVS2MODE 001SALZ01 +r
|
2016-01-03 20:09:40 +01:00
|
|
|
|
2017-06-17 02:12:48 +02:00
|
|
|
target = self._get_UID(args[0])
|
2017-06-30 07:56:14 +02:00
|
|
|
parsedmodes = self.parse_modes(target, args[1:])
|
2016-07-28 01:35:40 +02:00
|
|
|
|
|
|
|
if ('+r', None) in parsedmodes:
|
|
|
|
# Umode +r is being set (log in)
|
|
|
|
try:
|
|
|
|
# Try to get the account name (mode argument for +d)
|
|
|
|
account = args[2]
|
|
|
|
except IndexError:
|
|
|
|
# If one doesn't exist, make it the same as the nick, but only if the account name
|
|
|
|
# wasn't set already.
|
2017-06-25 11:03:12 +02:00
|
|
|
if not self.users[target].services_account:
|
2017-06-30 07:56:14 +02:00
|
|
|
account = self.get_friendly_name(target)
|
2016-07-28 01:35:40 +02:00
|
|
|
else:
|
|
|
|
return
|
2016-08-09 01:35:10 +02:00
|
|
|
else:
|
|
|
|
if account.isdigit():
|
|
|
|
# If the +d argument is a number, ignore it and set the account name to the nick.
|
2017-06-30 07:56:14 +02:00
|
|
|
account = self.get_friendly_name(target)
|
2016-08-09 01:35:10 +02:00
|
|
|
|
2016-07-28 01:35:40 +02:00
|
|
|
elif ('-r', None) in parsedmodes:
|
|
|
|
# Umode -r being set.
|
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
if not self.users[target].services_account:
|
2016-07-28 01:35:40 +02:00
|
|
|
# User already has no account; ignore.
|
|
|
|
return
|
|
|
|
|
|
|
|
account = ''
|
|
|
|
elif ('+d', None) in parsedmodes:
|
|
|
|
# Nick identification status wasn't changed, but services account was.
|
2016-02-21 03:16:21 +01:00
|
|
|
account = args[2]
|
2016-08-09 01:35:10 +02:00
|
|
|
if account == '0': # +d 0 means logout
|
2016-02-21 03:16:21 +01:00
|
|
|
account = ''
|
|
|
|
else:
|
2016-07-28 01:35:40 +02:00
|
|
|
return
|
|
|
|
|
2017-06-30 07:56:14 +02:00
|
|
|
self.call_hooks([target, 'CLIENT_SERVICES_LOGIN', {'text': account}])
|
2017-08-11 21:03:19 +02:00
|
|
|
# The internal mode +d used for services stamps clashes with the DEAF mode, so don't parse it as
|
|
|
|
# an actual mode mode parsing.
|
|
|
|
return self._handle_umode(target, [mode for mode in parsedmodes if mode[0][-1] != 'd'])
|
2015-11-09 00:26:48 +01:00
|
|
|
|
2017-08-11 21:03:19 +02:00
|
|
|
def _handle_umode(self, target, parsedmodes):
|
|
|
|
"""Internal helper function to parse umode changes."""
|
|
|
|
if not parsedmodes:
|
|
|
|
return
|
2015-12-18 06:37:01 +01:00
|
|
|
|
2017-08-11 21:03:19 +02:00
|
|
|
self.apply_modes(target, parsedmodes)
|
|
|
|
|
|
|
|
self._check_oper_status_change(target, parsedmodes)
|
|
|
|
self._check_cloak_change(target, parsedmodes)
|
2016-01-03 20:09:40 +01:00
|
|
|
|
2017-08-11 21:03:19 +02:00
|
|
|
return {'target': target, 'modes': parsedmodes}
|
|
|
|
|
|
|
|
def handle_umode2(self, source, command, args):
|
|
|
|
"""Handles UMODE2, used to set user modes on oneself."""
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :jlu5 UMODE2 +W
|
2017-08-11 21:03:19 +02:00
|
|
|
target = self._get_UID(source)
|
|
|
|
return self._handle_umode(target, self.parse_modes(target, args))
|
2015-10-10 06:37:11 +02:00
|
|
|
|
2015-10-13 03:25:30 +02:00
|
|
|
def handle_topic(self, numeric, command, args):
|
|
|
|
"""Handles the TOPIC command."""
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- jlu5 TOPIC #services jlu5 1444699395 :weeee
|
2016-01-10 05:50:38 +01:00
|
|
|
# <- TOPIC #services devel.relay 1452399682 :test
|
2017-08-08 06:54:33 +02:00
|
|
|
channel = args[0]
|
2015-10-13 03:25:30 +02:00
|
|
|
topic = args[-1]
|
2016-01-10 05:50:38 +01:00
|
|
|
setter = args[1]
|
2015-10-13 03:25:30 +02:00
|
|
|
ts = args[2]
|
2016-01-10 05:50:38 +01:00
|
|
|
|
2017-08-25 11:11:48 +02:00
|
|
|
oldtopic = self._channels[channel].topic
|
|
|
|
self._channels[channel].topic = topic
|
|
|
|
self._channels[channel].topicset = True
|
2016-01-10 05:50:38 +01:00
|
|
|
|
|
|
|
return {'channel': channel, 'setter': setter, 'ts': ts, 'text': topic,
|
2015-10-13 03:25:30 +02:00
|
|
|
'oldtopic': oldtopic}
|
|
|
|
|
2015-11-15 18:30:29 +01:00
|
|
|
def handle_setident(self, numeric, command, args):
|
|
|
|
"""Handles SETIDENT, used for self ident changes."""
|
|
|
|
# <- :70MAAAAAB SETIDENT test
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[numeric].ident = newident = args[0]
|
2015-11-15 18:30:29 +01:00
|
|
|
return {'target': numeric, 'newident': newident}
|
|
|
|
|
|
|
|
def handle_sethost(self, numeric, command, args):
|
|
|
|
"""Handles CHGHOST, used for self hostname changes."""
|
|
|
|
# <- :70MAAAAAB SETIDENT some.host
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[numeric].host = newhost = args[0]
|
2016-01-03 20:15:19 +01:00
|
|
|
|
|
|
|
# When SETHOST or CHGHOST is used, modes +xt are implicitly set on the
|
|
|
|
# target.
|
2017-06-30 07:56:14 +02:00
|
|
|
self.apply_modes(numeric, [('+x', None), ('+t', None)])
|
2016-01-03 20:15:19 +01:00
|
|
|
|
2015-11-15 18:30:29 +01:00
|
|
|
return {'target': numeric, 'newhost': newhost}
|
|
|
|
|
|
|
|
def handle_setname(self, numeric, command, args):
|
|
|
|
"""Handles SETNAME, used for self real name/gecos changes."""
|
|
|
|
# <- :70MAAAAAB SETNAME :afdsafasf
|
2017-06-25 11:03:12 +02:00
|
|
|
self.users[numeric].realname = newgecos = args[0]
|
2015-11-15 18:30:29 +01:00
|
|
|
return {'target': numeric, 'newgecos': newgecos}
|
|
|
|
|
|
|
|
def handle_chgident(self, numeric, command, args):
|
|
|
|
"""Handles CHGIDENT, used for denoting ident changes."""
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :jlu5 CHGIDENT jlu5 test
|
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].ident = newident = args[1]
|
2015-11-15 18:30:29 +01:00
|
|
|
return {'target': target, 'newident': newident}
|
|
|
|
|
|
|
|
def handle_chghost(self, numeric, command, args):
|
|
|
|
"""Handles CHGHOST, used for denoting hostname changes."""
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :jlu5 CHGHOST jlu5 some.host
|
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]
|
2016-01-03 20:15:19 +01:00
|
|
|
|
|
|
|
# When SETHOST or CHGHOST is used, modes +xt are implicitly set on the
|
|
|
|
# target.
|
2017-06-30 07:56:14 +02:00
|
|
|
self.apply_modes(target, [('+x', None), ('+t', None)])
|
2016-01-03 20:15:19 +01:00
|
|
|
|
2015-11-15 18:30:29 +01:00
|
|
|
return {'target': target, 'newhost': newhost}
|
|
|
|
|
|
|
|
def handle_chgname(self, numeric, command, args):
|
|
|
|
"""Handles CHGNAME, used for denoting real name/gecos changes."""
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :jlu5 CHGNAME jlu5 :afdsafasf
|
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].realname = newgecos = args[1]
|
2015-11-15 18:30:29 +01:00
|
|
|
return {'target': target, 'newgecos': newgecos}
|
|
|
|
|
2016-08-18 06:19:13 +02:00
|
|
|
def handle_tsctl(self, source, command, args):
|
|
|
|
"""Handles /TSCTL alltime requests."""
|
2021-06-10 05:15:07 +02:00
|
|
|
# <- :jlu5 TSCTL alltime
|
2016-08-18 06:19:13 +02:00
|
|
|
|
|
|
|
if args[0] == 'alltime':
|
2017-06-25 11:03:12 +02:00
|
|
|
self._send_with_prefix(self.sid, 'NOTICE %s :*** Server=%s time()=%d' % (source, self.hostname(), time.time()))
|
2016-08-18 06:19:13 +02:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
Class = UnrealProtocol
|