2015-12-26 23:45:28 +01:00
|
|
|
"""
|
|
|
|
unreal.py: UnrealIRCd 4.0 protocol module for PyLink.
|
|
|
|
"""
|
|
|
|
|
2015-09-03 22:32:59 +02:00
|
|
|
import time
|
|
|
|
import sys
|
|
|
|
import os
|
2015-10-13 03:45:25 +02:00
|
|
|
import codecs
|
2015-11-27 07:15:52 +01:00
|
|
|
import socket
|
2015-10-09 05:46:30 +02:00
|
|
|
import re
|
2015-09-03 22:32:59 +02:00
|
|
|
|
2015-12-26 23:45:28 +01:00
|
|
|
# Import hacks to access utils and classes...
|
2015-09-03 22:32:59 +02:00
|
|
|
curdir = os.path.dirname(__file__)
|
|
|
|
sys.path += [curdir, os.path.dirname(curdir)]
|
2015-12-26 23:45:28 +01:00
|
|
|
|
2015-09-03 22:32:59 +02:00
|
|
|
import utils
|
|
|
|
from log import log
|
|
|
|
from classes import *
|
2015-09-11 03:41:01 +02:00
|
|
|
from ts6_common import TS6BaseProtocol
|
2015-09-03 22:32:59 +02:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
class UnrealProtocol(TS6BaseProtocol):
|
|
|
|
def __init__(self, irc):
|
|
|
|
super(UnrealProtocol, self).__init__(irc)
|
|
|
|
# Set our case mapping (rfc1459 maps "\" and "|" together, for example".
|
|
|
|
self.casemapping = 'ascii'
|
2015-10-13 03:17:58 +02:00
|
|
|
self.proto_ver = 3999
|
|
|
|
self.min_proto_ver = 3999
|
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-24 03:59:17 +02:00
|
|
|
self.uidgen = {}
|
2015-11-15 18:12:21 +01:00
|
|
|
self.sidgen = utils.TS6SIDGenerator(self.irc)
|
2015-09-03 22:32:59 +02:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
self.caps = {}
|
2015-10-13 04:38:38 +02:00
|
|
|
self.irc.prefixmodes = {'q': '~', 'a': '&', 'o': '@', 'h': '%', 'v': '+'}
|
2015-09-11 03:41:01 +02:00
|
|
|
self._unrealCmodes = {'l': 'limit', 'c': 'blockcolor', 'G': 'censor',
|
|
|
|
'D': 'delayjoin', 'n': 'noextmsg', 's': 'secret',
|
|
|
|
'T': 'nonotice', 'z': 'sslonly', 'b': 'ban', 'V': 'noinvite',
|
|
|
|
'Z': 'issecure', 'r': 'registered', 'N': 'nonick',
|
|
|
|
'e': 'banexception', 'R': 'regonly', 'M': 'regmoderated',
|
|
|
|
'p': 'private', 'Q': 'nokick', 'P': 'permanent', 'k': 'key',
|
|
|
|
'C': 'noctcp', 'O': 'operonly', 'S': 'stripcolor',
|
|
|
|
'm': 'moderated', 'K': 'noknock', 'o': 'op', 'v': 'voice',
|
2015-10-09 06:06:09 +02:00
|
|
|
'I': 'invex', 't': 'topiclock', 'f': 'flood_unreal'}
|
2015-11-22 08:57:24 +01:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
self._neededCaps = ["VL", "SID", "CHANMODES", "NOQUIT", "SJ3"]
|
2015-09-05 21:02:45 +02:00
|
|
|
|
2015-11-15 18:12:21 +01:00
|
|
|
# Some command aliases
|
2015-11-02 06:50:46 +01:00
|
|
|
self.handle_svskill = self.handle_kill
|
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
### OUTGOING COMMAND FUNCTIONS
|
|
|
|
def spawnClient(self, nick, ident='null', host='null', realhost=None, modes=set(),
|
2015-10-09 05:28:21 +02:00
|
|
|
server=None, ip='0.0.0.0', realname=None, ts=None, opertype=None,
|
2015-10-13 04:34:52 +02:00
|
|
|
manipulatable=False):
|
2015-10-09 05:28:21 +02:00
|
|
|
"""Spawns a client with nick <nick> on the given IRC connection.
|
|
|
|
|
|
|
|
Note: No nick collision / valid nickname checks are done here; it is
|
|
|
|
up to plugins to make sure they don't introduce anything invalid."""
|
2015-09-11 03:41:01 +02:00
|
|
|
server = server or self.irc.sid
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalServer(server):
|
2016-01-10 02:44:05 +01:00
|
|
|
raise ValueError('Server %r is not a PyLink server!' % server)
|
2015-09-11 03:41:01 +02:00
|
|
|
# Unreal 3.4 uses TS6-style UIDs. They don't start from AAAAAA like other IRCd's
|
|
|
|
# do, but we can do that fine...
|
2015-09-24 03:59:17 +02:00
|
|
|
uid = self.uidgen.setdefault(server, utils.TS6UIDGenerator(server)).next_uid()
|
2015-09-11 03:41:01 +02:00
|
|
|
ts = ts or int(time.time())
|
|
|
|
realname = realname or self.irc.botdata['realname']
|
|
|
|
realhost = realhost or host
|
|
|
|
raw_modes = utils.joinModes(modes)
|
|
|
|
u = self.irc.users[uid] = IrcUser(nick, ts, uid, ident=ident, host=host, realname=realname,
|
2015-10-13 04:34:52 +02:00
|
|
|
realhost=realhost, ip=ip, manipulatable=manipulatable)
|
2015-09-11 03:41:01 +02:00
|
|
|
utils.applyModes(self.irc, uid, modes)
|
|
|
|
self.irc.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()
|
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
# <- :001 UID GL 0 1441306929 gl localhost 0018S7901 0 +iowx * midnight-1C620195 fwAAAQ== :realname
|
|
|
|
self._send(server, "UID {nick} 0 {ts} {ident} {realhost} {uid} 0 {modes} "
|
2015-11-27 07:15:52 +01:00
|
|
|
"{host} * {ip} :{realname}".format(ts=ts, host=host,
|
2015-09-11 03:41:01 +02:00
|
|
|
nick=nick, ident=ident, uid=uid,
|
|
|
|
modes=raw_modes, realname=realname,
|
2015-11-27 07:15:52 +01:00
|
|
|
realhost=realhost, ip=encoded_ip))
|
2015-11-27 07:34:15 +01:00
|
|
|
|
|
|
|
# Force the virtual hostname to show correctly by running SETHOST on
|
|
|
|
# the user. Otherwise, Unreal will show the real host of the person
|
|
|
|
# instead, which is probably not what we want.
|
|
|
|
self.updateClient(uid, 'HOST', host)
|
|
|
|
|
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."""
|
|
|
|
channel = utils.toLower(self.irc, channel)
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalClient(client):
|
2015-10-13 04:38:38 +02:00
|
|
|
raise LookupError('No such PyLink client exists.')
|
|
|
|
self._send(client, "JOIN %s" % channel)
|
|
|
|
self.irc.channels[channel].users.add(client)
|
|
|
|
self.irc.users[client].channels.add(channel)
|
|
|
|
|
2016-01-17 01:53:46 +01:00
|
|
|
def sjoin(self, server, channel, users, ts=None):
|
2015-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')])
|
|
|
|
sjoin(self.irc.sid, '#test', [('o', self.irc.pseudoclient.uid)])
|
2015-10-13 04:38:38 +02:00
|
|
|
|
|
|
|
Note that for UnrealIRCd, no mode data is sent in an SJOIN command, only
|
|
|
|
The channel name, TS, and user list.
|
|
|
|
"""
|
|
|
|
# <- :001 SJOIN 1444361345 #endlessvoid :001DJ1O02
|
|
|
|
# The nicklist consists of users joining the channel, with status prefixes for
|
|
|
|
# their status ('@+', '@', '+' or ''), for example:
|
|
|
|
# '@+1JJAAAAAB +2JJAAAA4C 1JJAAAADS'.
|
|
|
|
channel = utils.toLower(self.irc, channel)
|
|
|
|
server = server or self.irc.sid
|
2016-01-17 01:53:46 +01:00
|
|
|
assert users, "sjoin: No users sent?"
|
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
|
|
|
|
2015-10-13 04:38:38 +02:00
|
|
|
orig_ts = self.irc.channels[channel].ts
|
|
|
|
ts = ts or orig_ts
|
2015-11-09 00:26:17 +01:00
|
|
|
self.updateTS(channel, ts)
|
|
|
|
|
2015-10-13 04:38:38 +02:00
|
|
|
changedmodes = []
|
|
|
|
uids = []
|
|
|
|
namelist = []
|
|
|
|
for userpair in users:
|
|
|
|
assert len(userpair) == 2, "Incorrect format of userpair: %r" % userpair
|
|
|
|
prefixes, user = userpair
|
|
|
|
# Unreal uses slightly different prefixes in SJOIN. +q is * instead of ~,
|
|
|
|
# and +a is ~ instead of &.
|
|
|
|
# &, ", and ' are used for bursting bans.
|
|
|
|
sjoin_prefixes = {'q': '*', 'a': '~', 'o': '@', 'h': '%', 'v': '+'}
|
|
|
|
prefixchars = ''.join([sjoin_prefixes.get(prefix, '') for prefix in prefixes])
|
|
|
|
if prefixchars:
|
|
|
|
changedmodes + [('+%s' % prefix, user) for prefix in prefixes]
|
|
|
|
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)
|
2015-10-13 04:38:38 +02:00
|
|
|
namelist = ' '.join(namelist)
|
|
|
|
self._send(server, "SJOIN {ts} {channel} :{users}".format(
|
|
|
|
ts=ts, users=namelist, channel=channel))
|
|
|
|
self.irc.channels[channel].users.update(uids)
|
|
|
|
if ts <= orig_ts:
|
|
|
|
# Only save our prefix modes in the channel state if our TS is lower than or equal to theirs.
|
|
|
|
utils.applyModes(self.irc, channel, changedmodes)
|
2015-09-03 22:32:59 +02:00
|
|
|
|
2016-01-17 02:11:23 +01:00
|
|
|
def ping(self, source=None, target=None):
|
2015-10-09 05:28:21 +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-11 03:41:01 +02:00
|
|
|
source = source or self.irc.sid
|
|
|
|
target = target or self.irc.uplink
|
|
|
|
if not (target is None or source is None):
|
|
|
|
self._send(source, 'PING %s %s' % (self.irc.servers[source].name, self.irc.servers[target].name))
|
2015-09-04 01:07:30 +02:00
|
|
|
|
2016-01-17 02:03:22 +01:00
|
|
|
def kill(self, numeric, target, reason):
|
|
|
|
"""Sends a kill from a PyLink client/server."""
|
2015-11-12 04:09:37 +01:00
|
|
|
# <- :GL KILL 38QAAAAAA :hidden-1C620195!GL (test)
|
|
|
|
|
2016-01-17 02:03:22 +01:00
|
|
|
if (not self.irc.isInternalClient(numeric)) and \
|
|
|
|
(not self.irc.isInternalServer(numeric)):
|
|
|
|
raise LookupError('No such PyLink client/server exists.')
|
2015-11-12 04:09:37 +01:00
|
|
|
|
2016-01-17 02:03:22 +01:00
|
|
|
assert target in self.irc.users, "Unknown target %r for kill()!" % target
|
|
|
|
|
|
|
|
# The killpath doesn't really matter here...
|
2015-11-12 04:09:37 +01:00
|
|
|
self._send(numeric, 'KILL %s :%s!PyLink (%s)' % (target, self.irc.serverdata['hostname'], reason))
|
|
|
|
self.removeClient(target)
|
|
|
|
|
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
|
|
|
|
a list of (mode, arg) tuples, i.e. the format of utils.parseModes() output.
|
|
|
|
"""
|
2015-11-12 04:24:57 +01:00
|
|
|
# <- :unreal.midnight.vpn MODE #endlessvoid +ntCo GL 1444361345
|
2016-01-17 02:08:17 +01:00
|
|
|
|
|
|
|
if (not self.irc.isInternalClient(numeric)) and \
|
|
|
|
(not self.irc.isInternalServer(numeric)):
|
|
|
|
raise LookupError('No such PyLink client/server exists.')
|
|
|
|
|
2015-11-12 04:24:57 +01:00
|
|
|
utils.applyModes(self.irc, target, modes)
|
|
|
|
joinedmodes = utils.joinModes(modes)
|
|
|
|
if utils.isChannel(target):
|
|
|
|
# The MODE command is used for channel mode changes only
|
|
|
|
ts = ts or self.irc.channels[utils.toLower(self.irc, target)].ts
|
|
|
|
self._send(numeric, 'MODE %s %s %s' % (target, joinedmodes, ts))
|
|
|
|
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...
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalClient(target):
|
2015-11-12 04:24:57 +01:00
|
|
|
raise ProtocolError('Cannot force mode change on external clients!')
|
|
|
|
self._send(target, 'UMODE2 %s' % joinedmodes)
|
|
|
|
|
2016-01-17 02:09:52 +01:00
|
|
|
def topicBurst(self, numeric, target, text):
|
2015-11-15 18:12:21 +01:00
|
|
|
"""Sends a TOPIC change from a PyLink server."""
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalServer(numeric):
|
2015-11-15 18:12:21 +01:00
|
|
|
raise LookupError('No such PyLink server exists.')
|
|
|
|
self._send(numeric, 'TOPIC %s :%s' % (target, text))
|
|
|
|
self.irc.channels[target].topic = text
|
|
|
|
self.irc.channels[target].topicset = True
|
|
|
|
|
2015-12-31 00:54:09 +01:00
|
|
|
def updateClient(self, target, field, text):
|
|
|
|
"""Updates the ident, host, or realname of any connected client."""
|
2015-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)
|
|
|
|
|
2016-01-01 02:28:47 +01:00
|
|
|
if self.irc.isInternalClient(target):
|
2015-12-31 00:54:09 +01:00
|
|
|
# It is one of our clients, use SETIDENT/HOST/NAME.
|
|
|
|
if field == 'IDENT':
|
|
|
|
self.irc.users[target].ident = text
|
|
|
|
self._send(target, 'SETIDENT %s' % text)
|
|
|
|
elif field == 'HOST':
|
|
|
|
self.irc.users[target].host = text
|
|
|
|
self._send(target, 'SETHOST %s' % text)
|
|
|
|
elif field in ('REALNAME', 'GECOS'):
|
|
|
|
self.irc.users[target].realname = text
|
|
|
|
self._send(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':
|
|
|
|
self.irc.users[target].ident = text
|
|
|
|
self._send(self.irc.sid, 'CHGIDENT %s %s' % (target, text))
|
|
|
|
|
|
|
|
# Send hook payloads for other plugins to listen to.
|
|
|
|
self.irc.callHooks([self.irc.sid, 'CHGIDENT',
|
|
|
|
{'target': target, 'newident': text}])
|
|
|
|
|
|
|
|
elif field == 'HOST':
|
|
|
|
self.irc.users[target].host = text
|
|
|
|
self._send(self.irc.sid, 'CHGHOST %s %s' % (target, text))
|
|
|
|
|
|
|
|
self.irc.callHooks([self.irc.sid, 'CHGHOST',
|
|
|
|
{'target': target, 'newhost': text}])
|
|
|
|
|
|
|
|
elif field in ('REALNAME', 'GECOS'):
|
|
|
|
self.irc.users[target].realname = text
|
|
|
|
self._send(self.irc.sid, 'CHGNAME %s :%s' % (target, text))
|
|
|
|
|
|
|
|
self.irc.callHooks([self.irc.sid, 'CHGNAME',
|
|
|
|
{'target': target, 'newgecos': text}])
|
2015-11-15 18:45:46 +01:00
|
|
|
|
2016-01-17 01:38:27 +01:00
|
|
|
def invite(self, numeric, target, channel):
|
2015-11-16 06:00:51 +01:00
|
|
|
"""Sends an INVITE from a PyLink client.."""
|
2016-01-01 02:28:47 +01:00
|
|
|
if not self.irc.isInternalClient(numeric):
|
2015-11-16 06:00:51 +01:00
|
|
|
raise LookupError('No such PyLink client exists.')
|
|
|
|
self._send(numeric, 'INVITE %s %s' % (target, channel))
|
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.
|
|
|
|
# <- :unreal.midnight.vpn NOTICE @#test :[Knock] by GL|!gl@hidden-1C620195 (test)
|
|
|
|
assert utils.isChannel(target), "Can only knock on channels!"
|
2016-01-01 02:28:47 +01:00
|
|
|
sender = self.irc.getServer(numeric)
|
2015-11-16 06:09:40 +01:00
|
|
|
s = '[Knock] by %s (%s)' % (utils.getHostmask(self.irc, numeric), text)
|
|
|
|
self._send(sender, 'NOTICE @%s :%s' % (target, s))
|
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
### HANDLERS
|
2015-09-05 21:02:45 +02:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
def connect(self):
|
2015-10-09 05:28:21 +02:00
|
|
|
"""Initializes a connection to a server."""
|
2015-09-11 03:41:01 +02:00
|
|
|
ts = self.irc.start_ts
|
|
|
|
self.irc.prefixmodes = {'q': '~', 'a': '&', 'o': '@', 'h': '%', 'v': '+'}
|
2015-11-22 08:57:24 +01:00
|
|
|
|
|
|
|
self.irc.umodes.update({'deaf': 'd', 'invisible': 'i', 'hidechans': 'p',
|
|
|
|
'protected': 'q', 'registered': 'r',
|
|
|
|
'snomask': 's', 'vhost': 't', 'wallops': 'w',
|
|
|
|
'bot': 'B', 'cloak': 'x', 'ssl': 'z',
|
|
|
|
'filter': 'G', 'hideoper': 'H', 'hideidle': 'I',
|
|
|
|
'regdeaf': 'R', 'servprotect': 'S',
|
|
|
|
'u_noctcp': 'T', 'showwhois': 'W',
|
|
|
|
'*A': '', '*B': '', '*C': '', '*D': 'dipqrstwBxzGHIRSTW'})
|
2015-09-03 22:32:59 +02:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
f = self.irc.send
|
|
|
|
host = self.irc.serverdata["hostname"]
|
2015-12-07 02:44:59 +01:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
f('PASS :%s' % self.irc.serverdata["sendpass"])
|
2016-01-10 03:34:41 +01:00
|
|
|
# https://github.com/unrealircd/unrealself.ircd/blob/2f8cb55e/doc/technical/protoctl.txt
|
2015-09-11 03:41:01 +02:00
|
|
|
# We support the following protocol features:
|
|
|
|
# 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
|
|
|
|
# SID - Use UIDs and SIDs (unreal 3.4)
|
|
|
|
# VL - Sends version string in below SERVER message
|
|
|
|
# UMODE2 - used for users setting modes on themselves (one less argument needed)
|
|
|
|
# EAUTH - Early auth? (Unreal 3.4 linking protocol)
|
|
|
|
f('PROTOCTL SJ3 NOQUIT NICKv2 VL UMODE2 PROTOCTL EAUTH=%s SID=%s' % (self.irc.serverdata["hostname"], self.irc.sid))
|
|
|
|
sdesc = self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc']
|
|
|
|
f('SERVER %s 1 U%s-h6e-%s :%s' % (host, self.proto_ver, self.irc.sid, sdesc))
|
2015-10-13 03:20:16 +02:00
|
|
|
f('NETINFO 1 %s %s * 0 0 0 :%s' % (self.irc.start_ts, self.proto_ver, self.irc.serverdata.get("netname", self.irc.name)))
|
2015-09-11 03:41:01 +02:00
|
|
|
self._send(self.irc.sid, 'EOS')
|
2015-11-22 08:57:24 +01:00
|
|
|
|
2015-12-25 03:09:52 +01:00
|
|
|
def handle_eos(self, numeric, command, args):
|
|
|
|
"""EOS is used to denote end of burst."""
|
|
|
|
return {}
|
2015-09-03 22:32:59 +02:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
def handle_uid(self, numeric, command, args):
|
|
|
|
# <- :001 UID GL 0 1441306929 gl localhost 0018S7901 0 +iowx * midnight-1C620195 fwAAAQ== :realname
|
|
|
|
# <- :001 UID GL| 0 1441389007 gl 10.120.0.6 001ZO8F03 0 +iwx * 391A9CB9.26A16454.D9847B69.IP CngABg== :realname
|
2015-11-22 22:07:25 +01:00
|
|
|
# arguments: nick, hopcount???, ts, ident, real-host, UID, number???, modes,
|
|
|
|
# displayed host, cloaked (+x) host, base64-encoded IP, and realname
|
2015-09-11 03:41:01 +02:00
|
|
|
# TODO: find out what all the "???" fields mean.
|
|
|
|
nick = args[0]
|
|
|
|
ts, ident, realhost, uid = args[2:6]
|
|
|
|
modestring = args[7]
|
2015-11-22 22:07:25 +01:00
|
|
|
host = args[8]
|
|
|
|
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]
|
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
|
2015-09-11 03:41:01 +02:00
|
|
|
realname = args[-1]
|
2016-01-03 20:09:40 +01:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
self.irc.users[uid] = IrcUser(nick, ts, uid, ident, host, realname, realhost, ip)
|
2016-01-03 20:09:40 +01:00
|
|
|
self.irc.servers[numeric].users.add(uid)
|
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
parsedmodes = utils.parseModes(self.irc, uid, [modestring])
|
|
|
|
utils.applyModes(self.irc, 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
|
|
|
|
# enabled) but NOT +t (vHost set). We'll store this separately for now,
|
|
|
|
# but more handling is needed so that plugins can update the cloak host
|
|
|
|
# appropriately.
|
|
|
|
self.irc.users[uid].cloaked_host = args[9]
|
|
|
|
|
2015-12-18 06:37:01 +01:00
|
|
|
if ('+o', None) in parsedmodes:
|
2015-12-27 00:41:22 +01:00
|
|
|
# If +o being set, call the CLIENT_OPERED internal hook.
|
|
|
|
self.irc.callHooks([uid, 'CLIENT_OPERED', {'text': 'IRC_Operator'}])
|
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.
|
|
|
|
self.updateClient(uid, 'HOST', realhost)
|
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip}
|
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
|
|
|
|
if args[0] != self.irc.serverdata['recvpass']:
|
|
|
|
raise ProtocolError("Error: 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):
|
|
|
|
if numeric == self.irc.uplink:
|
|
|
|
self.irc.send('PONG %s :%s' % (self.irc.serverdata['hostname'], args[-1]))
|
2015-09-04 01:07:30 +02:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
def handle_pong(self, source, command, args):
|
|
|
|
log.debug('(%s) Ping received from %s for %s.', self.irc.name, source, args[-1])
|
|
|
|
if source in (self.irc.uplink, self.irc.servers[self.irc.uplink].name) and args[-1] == self.irc.serverdata['hostname']:
|
|
|
|
log.debug('(%s) Set self.irc.lastping.', self.irc.name)
|
|
|
|
self.irc.lastping = time.time()
|
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]
|
2015-10-13 03:17:58 +02:00
|
|
|
if numeric == self.irc.uplink: # We're doing authentication
|
2015-09-11 03:41:01 +02:00
|
|
|
for cap in self._neededCaps:
|
|
|
|
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)" %
|
|
|
|
(sorted(self.caps.keys()),
|
|
|
|
sorted(_neededCaps)))
|
|
|
|
sdesc = args[-1].split(" ")
|
|
|
|
# Get our protocol version :)
|
|
|
|
vline = sdesc[0].split('-', 1)
|
|
|
|
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 "
|
|
|
|
"(Unreal 4.0.0-rc1), got something invalid; "
|
|
|
|
"is VL being sent?)" % self.min_proto_ver)
|
2015-09-11 03:41:01 +02:00
|
|
|
sdesc = args[-1][1:]
|
2015-10-13 03:17:58 +02:00
|
|
|
if protover < self.min_proto_ver:
|
|
|
|
raise ProtocolError("Protocol version too old! (needs at least %s "
|
|
|
|
"(Unreal 4.0.0-rc1), got %s)" % (self.min_proto_ver, protover))
|
2015-09-11 03:41:01 +02:00
|
|
|
self.irc.servers[numeric] = IrcServer(None, sname)
|
|
|
|
else:
|
2015-10-13 03:15:39 +02:00
|
|
|
# Legacy (non-SID) servers can still be introduced using the SERVER command.
|
|
|
|
# <- :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)
|
|
|
|
return {'name': servername, 'sid': None, 'text': sdesc}
|
2015-10-10 07:38:28 +02:00
|
|
|
|
|
|
|
def handle_sid(self, numeric, command, args):
|
|
|
|
"""Handles the SID command, used for introducing remote servers by our uplink."""
|
|
|
|
# <- SID services.int 2 00A :Shaltúre IRC Services
|
|
|
|
sname = args[0].lower()
|
|
|
|
sid = args[2]
|
|
|
|
sdesc = args[-1]
|
|
|
|
self.irc.servers[sid] = IrcServer(numeric, sname, desc=sdesc)
|
|
|
|
return {'name': sname, 'sid': sid, 'text': sdesc}
|
|
|
|
|
|
|
|
def handle_squit(self, numeric, command, args):
|
|
|
|
"""Handles the SQUIT command."""
|
|
|
|
# <- SQUIT services.int :Read error
|
|
|
|
# Convert the server name to a SID...
|
2015-10-13 02:50:44 +02:00
|
|
|
args[0] = self._getSid(args[0])
|
2015-10-13 03:15:39 +02:00
|
|
|
# Then, use the SQUIT handler in TS6BaseProtocol as usual.
|
2015-10-10 07:38:28 +02:00
|
|
|
return super(UnrealProtocol, self).handle_squit(numeric, 'SQUIT', args)
|
2015-09-04 01:07:30 +02:00
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
def handle_protoctl(self, numeric, command, args):
|
|
|
|
# <- 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
|
|
|
|
for cap in args:
|
|
|
|
if cap.startswith('SID'):
|
|
|
|
self.irc.uplink = cap.split('=', 1)[1]
|
|
|
|
self.caps['SID'] = True
|
|
|
|
elif cap.startswith('CHANMODES'):
|
|
|
|
cmodes = cap.split('=', 1)[1]
|
|
|
|
self.irc.cmodes['*A'], self.irc.cmodes['*B'], self.irc.cmodes['*C'], self.irc.cmodes['*D'] = cmodes.split(',')
|
|
|
|
for m in cmodes:
|
|
|
|
if m in self._unrealCmodes:
|
|
|
|
self.irc.cmodes[self._unrealCmodes[m]] = m
|
|
|
|
self.caps['CHANMODES'] = True
|
2015-10-09 06:06:09 +02:00
|
|
|
self.irc.cmodes['*B'] += 'f' # Add +f to the list too, dunno why it isn't there.
|
2015-09-11 03:41:01 +02:00
|
|
|
# Because more than one PROTOCTL line is sent, we have to delay the
|
|
|
|
# check to see whether our needed capabilities are all there...
|
|
|
|
# That's done by handle_server(), which comes right after PROTOCTL.
|
|
|
|
elif cap == 'VL':
|
|
|
|
self.caps['VL'] = True
|
|
|
|
elif cap == 'NOQUIT':
|
|
|
|
self.caps['NOQUIT'] = True
|
|
|
|
elif cap == 'SJ3':
|
|
|
|
self.caps['SJ3'] = True
|
2015-10-13 04:38:38 +02:00
|
|
|
self.irc.cmodes.update({'halfop': 'h', 'admin': 'a', 'owner': 'q',
|
|
|
|
'op': 'o', 'voice': 'v'})
|
2015-09-04 01:07:30 +02:00
|
|
|
|
2015-12-25 03:09:52 +01:00
|
|
|
# Set irc.connected to True, meaning that protocol negotiation passed.
|
|
|
|
log.debug('(%s) self.irc.connected set!', self.irc.name)
|
|
|
|
self.irc.connected.set()
|
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
def handle_privmsg(self, source, command, args):
|
|
|
|
# Convert nicks to UIDs, where they exist.
|
2015-10-13 02:58:36 +02:00
|
|
|
target = self._getNick(args[0])
|
2015-09-11 03:41:01 +02:00
|
|
|
# We use lowercase channels internally, but uppercase UIDs.
|
|
|
|
if utils.isChannel(target):
|
|
|
|
target = utils.toLower(self.irc, target)
|
|
|
|
return {'target': target, 'text': args[1]}
|
|
|
|
handle_notice = handle_privmsg
|
2015-09-05 21:02:45 +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."""
|
2015-10-09 05:44:12 +02:00
|
|
|
# <- :GL JOIN #pylink,#test
|
2015-09-11 03:41:01 +02:00
|
|
|
for channel in args[0].split(','):
|
|
|
|
c = self.irc.channels[channel]
|
|
|
|
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 ch in oldchans:
|
|
|
|
self.irc.channels[ch].users.discard(numeric)
|
|
|
|
self.irc.users[numeric].channels.discard(ch)
|
|
|
|
return {'channels': oldchans, 'text': 'Left all channels.', 'parse_as': 'PART'}
|
2015-10-09 05:44:12 +02:00
|
|
|
|
|
|
|
self.irc.users[numeric].channels.add(channel)
|
|
|
|
self.irc.channels[channel].users.add(numeric)
|
2015-10-09 05:28:21 +02:00
|
|
|
# Call hooks manually, because one JOIN command in UnrealIRCd can
|
|
|
|
# have multiple channels...
|
2015-09-11 03:41:01 +02:00
|
|
|
self.irc.callHooks([numeric, command, {'channel': channel, 'users': [numeric], 'modes':
|
2015-10-09 05:44:12 +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."""
|
|
|
|
# <- :001 SJOIN 1444361345 #endlessvoid :001DJ1O02
|
|
|
|
# memberlist should be a list of UIDs with their channel status prefixes, as
|
|
|
|
# in ":001AAAAAA @001AAAAAB +001AAAAAC".
|
|
|
|
# Interestingly, no modes are ever sent in this command as far as I've seen.
|
|
|
|
channel = utils.toLower(self.irc, args[1])
|
|
|
|
userlist = args[-1].split()
|
2015-11-09 00:26:17 +01:00
|
|
|
|
2015-10-09 05:46:30 +02:00
|
|
|
our_ts = self.irc.channels[channel].ts
|
|
|
|
their_ts = int(args[0])
|
2015-11-12 04:09:30 +01:00
|
|
|
self.updateTS(channel, their_ts)
|
2015-10-09 05:46:30 +02:00
|
|
|
|
|
|
|
namelist = []
|
|
|
|
log.debug('(%s) handle_sjoin: got userlist %r for %r', self.irc.name, userlist, channel)
|
|
|
|
for userpair in userlist:
|
2015-10-13 04:38:38 +02:00
|
|
|
if userpair.startswith("&\"'"): # TODO: handle ban bursts too
|
|
|
|
# &, ", and ' entries are used for bursting bans:
|
|
|
|
# https://www.unrealircd.org/files/docs/technical/serverprotocol.html#S5_1
|
|
|
|
break
|
2015-10-09 05:46:30 +02:00
|
|
|
r = re.search(r'([^\d]*)(.*)', userpair)
|
|
|
|
user = r.group(2)
|
2015-10-13 04:38:38 +02:00
|
|
|
# Unreal uses slightly different prefixes in SJOIN. +q is * instead of ~,
|
|
|
|
# and +a is ~ instead of &.
|
|
|
|
modeprefix = (r.group(1) or '').replace("~", "&").replace("*", "~")
|
2015-10-09 05:46:30 +02:00
|
|
|
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)
|
|
|
|
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)
|
2015-10-10 06:39:09 +02:00
|
|
|
# Only merge the remote's prefix modes if their TS is smaller or equal to ours.
|
2015-10-09 05:46:30 +02:00
|
|
|
if their_ts <= our_ts:
|
|
|
|
utils.applyModes(self.irc, channel, [('+%s' % mode, user) for mode in finalprefix])
|
|
|
|
self.irc.channels[channel].users.add(user)
|
2015-10-09 05:48:10 +02:00
|
|
|
return {'channel': channel, 'users': namelist, 'modes': self.irc.channels[channel].modes, 'ts': their_ts}
|
2015-10-09 05:46:30 +02:00
|
|
|
|
2015-10-09 06:06:09 +02:00
|
|
|
def handle_mode(self, numeric, command, args):
|
|
|
|
# <- :unreal.midnight.vpn MODE #endlessvoid +bb test!*@* *!*@bad.net
|
|
|
|
# <- :unreal.midnight.vpn MODE #endlessvoid +q GL 1444361345
|
|
|
|
# <- :unreal.midnight.vpn MODE #endlessvoid +ntCo GL 1444361345
|
|
|
|
# <- :unreal.midnight.vpn MODE #endlessvoid +mntClfo 5 [10t]:5 GL 1444361345
|
2015-11-02 06:41:41 +01:00
|
|
|
# <- :GL MODE #services +v GL
|
|
|
|
|
|
|
|
# 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. :|
|
2015-10-10 06:37:11 +02:00
|
|
|
if utils.isChannel(args[0]):
|
|
|
|
channel = utils.toLower(self.irc, args[0])
|
|
|
|
oldobj = self.irc.channels[channel].deepcopy()
|
2015-11-02 06:41:41 +01:00
|
|
|
modes = list(filter(None, args[1:])) # normalize whitespace
|
2015-10-10 06:37:11 +02:00
|
|
|
parsedmodes = utils.parseModes(self.irc, channel, modes)
|
|
|
|
if parsedmodes:
|
|
|
|
utils.applyModes(self.irc, channel, parsedmodes)
|
2015-11-02 06:41:41 +01:00
|
|
|
if numeric in self.irc.servers and args[-1].isdigit():
|
|
|
|
# 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:
|
|
|
|
self.updateTS(channel, their_ts)
|
2015-10-10 06:37:11 +02:00
|
|
|
return {'target': channel, 'modes': parsedmodes, 'oldchan': oldobj}
|
|
|
|
else:
|
|
|
|
log.warning("(%s) received MODE for non-channel target: %r",
|
|
|
|
self.irc.name, args)
|
2015-11-02 06:41:41 +01:00
|
|
|
raise NotImplementedError
|
2015-10-10 06:37:11 +02:00
|
|
|
|
2016-01-03 20:09:40 +01:00
|
|
|
def checkCloakChange(self, uid, parsedmodes):
|
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
|
|
|
userobj = self.irc.users[uid]
|
|
|
|
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.
|
|
|
|
self.irc.callHooks([uid, 'SETHOST',
|
|
|
|
{'target': uid, 'newhost': newhost}])
|
|
|
|
|
2015-11-09 00:26:48 +01:00
|
|
|
def handle_svsmode(self, numeric, command, args):
|
|
|
|
"""Handle SVSMODE/SVS2MODE, used for setting user modes on others (services)."""
|
|
|
|
# <- :source SVSMODE target +usermodes
|
2015-11-12 03:55:05 +01:00
|
|
|
target = self._getNick(args[0])
|
2015-11-09 00:26:48 +01:00
|
|
|
modes = args[1:]
|
2016-01-03 20:09:40 +01:00
|
|
|
|
2015-11-12 03:55:05 +01:00
|
|
|
parsedmodes = utils.parseModes(self.irc, target, modes)
|
|
|
|
utils.applyModes(self.irc, target, parsedmodes)
|
2016-01-03 20:09:40 +01:00
|
|
|
|
|
|
|
# If +x/-x is being set, update cloaked host info.
|
|
|
|
self.checkCloakChange(numeric, parsedmodes)
|
|
|
|
|
2015-11-09 00:26:48 +01:00
|
|
|
return {'target': numeric, 'modes': parsedmodes}
|
|
|
|
handle_svs2mode = handle_svsmode
|
|
|
|
|
2015-10-10 06:37:11 +02:00
|
|
|
def handle_umode2(self, numeric, command, args):
|
|
|
|
"""Handles UMODE2, used to set user modes on oneself."""
|
2015-11-12 04:24:57 +01:00
|
|
|
# <- :GL UMODE2 +W
|
2015-10-10 06:37:11 +02:00
|
|
|
parsedmodes = utils.parseModes(self.irc, numeric, args)
|
|
|
|
utils.applyModes(self.irc, numeric, parsedmodes)
|
2015-12-18 06:37:01 +01:00
|
|
|
|
|
|
|
if ('+o', None) in parsedmodes:
|
2015-12-27 00:41:22 +01:00
|
|
|
# If +o being set, call the CLIENT_OPERED internal hook.
|
|
|
|
self.irc.callHooks([uid, 'CLIENT_OPERED', {'text': 'IRC_Operator'}])
|
2015-12-18 06:37:01 +01:00
|
|
|
|
2016-01-03 20:09:40 +01:00
|
|
|
self.checkCloakChange(numeric, parsedmodes)
|
|
|
|
|
2015-10-10 06:37:11 +02:00
|
|
|
return {'target': numeric, 'modes': parsedmodes}
|
|
|
|
|
2015-10-13 03:25:30 +02:00
|
|
|
def handle_topic(self, numeric, command, args):
|
|
|
|
"""Handles the TOPIC command."""
|
|
|
|
# <- GL TOPIC #services GL 1444699395 :weeee
|
2016-01-10 05:50:38 +01:00
|
|
|
# <- TOPIC #services devel.relay 1452399682 :test
|
2015-10-13 03:25:30 +02:00
|
|
|
channel = utils.toLower(self.irc, args[0])
|
|
|
|
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
|
|
|
|
2015-10-13 03:25:30 +02:00
|
|
|
oldtopic = self.irc.channels[channel].topic
|
|
|
|
self.irc.channels[channel].topic = topic
|
|
|
|
self.irc.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-12 04:40:26 +01:00
|
|
|
def handle_whois(self, numeric, command, args):
|
|
|
|
"""Handles WHOIS queries."""
|
|
|
|
# <- :GL WHOIS PyLink-devel :pylink-devel
|
|
|
|
# In this case, the first argument is actually the server that the
|
|
|
|
# WHOIS query is requested from - IRCds should pass these requests on
|
|
|
|
# to the server in question. Since we're a services server, we can just
|
|
|
|
# process it regardless.
|
|
|
|
# The second argument is the ACTUAL nick requested.
|
|
|
|
|
|
|
|
# The actual WHOIS handling is done protocol-independently by coreplugin.
|
|
|
|
return {'target': self._getNick(args[-1])}
|
|
|
|
|
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
|
|
|
|
self.irc.users[numeric].ident = newident = args[0]
|
|
|
|
return {'target': numeric, 'newident': newident}
|
|
|
|
|
|
|
|
def handle_sethost(self, numeric, command, args):
|
|
|
|
"""Handles CHGHOST, used for self hostname changes."""
|
|
|
|
# <- :70MAAAAAB SETIDENT some.host
|
|
|
|
self.irc.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.
|
|
|
|
utils.applyModes(self.irc, numeric, [('+x', None), ('+t', None)])
|
|
|
|
|
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
|
|
|
|
self.irc.users[numeric].realname = newgecos = args[0]
|
|
|
|
return {'target': numeric, 'newgecos': newgecos}
|
|
|
|
|
|
|
|
def handle_chgident(self, numeric, command, args):
|
|
|
|
"""Handles CHGIDENT, used for denoting ident changes."""
|
|
|
|
# <- :GL CHGIDENT GL test
|
|
|
|
target = self._getNick(args[0])
|
|
|
|
self.irc.users[target].ident = newident = args[1]
|
|
|
|
return {'target': target, 'newident': newident}
|
|
|
|
|
|
|
|
def handle_chghost(self, numeric, command, args):
|
|
|
|
"""Handles CHGHOST, used for denoting hostname changes."""
|
|
|
|
# <- :GL CHGHOST GL some.host
|
|
|
|
target = self._getNick(args[0])
|
|
|
|
self.irc.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.
|
|
|
|
utils.applyModes(self.irc, target, [('+x', None), ('+t', None)])
|
|
|
|
|
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."""
|
|
|
|
# <- :GL CHGNAME GL :afdsafasf
|
|
|
|
target = self._getNick(args[0])
|
|
|
|
self.irc.users[target].realname = newgecos = args[1]
|
|
|
|
return {'target': target, 'newgecos': newgecos}
|
|
|
|
|
2015-11-16 06:00:51 +01:00
|
|
|
def handle_invite(self, numeric, command, args):
|
|
|
|
"""Handles incoming INVITEs."""
|
|
|
|
# <- :GL INVITE PyLink-devel :#a
|
|
|
|
target = self._getNick(args[0])
|
|
|
|
channel = args[1].lower()
|
|
|
|
# We don't actually need to process this; it's just something plugins/hooks can use
|
|
|
|
return {'target': target, 'channel': channel}
|
|
|
|
|
2015-09-11 03:41:01 +02:00
|
|
|
Class = UnrealProtocol
|