2017-08-11 21:27:58 +02:00
|
|
|
"""
|
|
|
|
ratbox.py: ircd-ratbox protocol module for PyLink.
|
|
|
|
"""
|
|
|
|
|
2016-10-01 08:33:27 +02:00
|
|
|
import time
|
|
|
|
|
2017-03-05 09:06:19 +01:00
|
|
|
from pylinkirc import utils, conf
|
2016-10-01 08:33:27 +02:00
|
|
|
from pylinkirc.log import log
|
|
|
|
from pylinkirc.classes import *
|
|
|
|
from pylinkirc.protocols.ts6 import *
|
|
|
|
|
|
|
|
class RatboxProtocol(TS6Protocol):
|
|
|
|
|
2017-06-25 10:12:22 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
2016-10-01 08:33:27 +02:00
|
|
|
# Don't require EUID for Ratbox
|
|
|
|
self.required_caps.discard('EUID')
|
|
|
|
|
2016-10-01 21:39:25 +02:00
|
|
|
self.hook_map['LOGIN'] = 'CLIENT_SERVICES_LOGIN'
|
2017-03-24 08:24:06 +01:00
|
|
|
self.protocol_caps -= {'slash-in-hosts'}
|
2016-10-01 21:39:25 +02:00
|
|
|
|
2017-06-25 10:12:22 +02:00
|
|
|
def post_connect(self):
|
2016-10-01 08:33:27 +02:00
|
|
|
"""Initializes a connection to a server."""
|
|
|
|
|
2017-06-30 06:55:52 +02:00
|
|
|
super().post_connect()
|
|
|
|
|
2016-10-01 22:00:04 +02:00
|
|
|
# Note: +r, +e, and +I support will be negotiated on link
|
2017-06-25 11:03:12 +02:00
|
|
|
self.cmodes = {'op': 'o', 'secret': 's', 'private': 'p', 'noextmsg': 'n', 'moderated': 'm',
|
2016-10-01 22:00:04 +02:00
|
|
|
'inviteonly': 'i', 'topiclock': 't', 'limit': 'l', 'ban': 'b', 'voice': 'v',
|
2017-08-11 22:45:40 +02:00
|
|
|
'key': 'k', 'sslonly': 'S', 'noknock': 'p',
|
2016-10-01 22:00:04 +02:00
|
|
|
'*A': 'beI',
|
|
|
|
'*B': 'k',
|
|
|
|
'*C': 'l',
|
2017-03-25 21:45:02 +01:00
|
|
|
'*D': 'imnpstrS'}
|
2016-10-01 08:33:27 +02:00
|
|
|
|
2017-06-25 11:03:12 +02:00
|
|
|
self.umodes = {
|
2016-10-01 22:40:10 +02:00
|
|
|
'invisible': 'i', 'callerid': 'g', 'oper': 'o', 'admin': 'a', 'sno_botfloods': 'b',
|
2016-10-01 08:33:27 +02:00
|
|
|
'sno_clientconnections': 'c', 'sno_extclientconnections': 'C', 'sno_debug': 'd',
|
2016-10-01 22:40:10 +02:00
|
|
|
'sno_fullauthblock': 'f', 'sno_skill': 'k', 'locops': 'l',
|
2016-10-01 08:33:27 +02:00
|
|
|
'sno_rejectedclients': 'r', 'snomask': 's', 'sno_badclientconnections': 'u',
|
2016-10-01 22:41:11 +02:00
|
|
|
'wallops': 'w', 'sno_serverconnects': 'x', 'sno_stats': 'y',
|
2016-10-01 22:40:10 +02:00
|
|
|
'operwall': 'z', 'sno_operspy': 'Z', 'deaf': 'D', 'servprotect': 'S',
|
2016-10-01 08:33:27 +02:00
|
|
|
# Now, map all the ABCD type modes:
|
|
|
|
'*A': '', '*B': '', '*C': '', '*D': 'igoabcCdfklrsuwxyzZD'
|
|
|
|
}
|
|
|
|
|
2017-08-25 21:24:09 +02:00
|
|
|
self.extbans_matching.clear()
|
|
|
|
|
2017-07-01 06:25:58 +02:00
|
|
|
def spawn_client(self, nick, ident='null', host='null', realhost=None, modes=set(),
|
2016-10-01 08:33:27 +02:00
|
|
|
server=None, ip='0.0.0.0', realname=None, ts=None, opertype=None,
|
|
|
|
manipulatable=False):
|
|
|
|
"""
|
|
|
|
Spawns a new client with the given options.
|
|
|
|
|
|
|
|
Note: No nick collision / valid nickname checks are done here; it is
|
|
|
|
up to plugins to make sure they don't introduce anything invalid.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# parameters: nickname, hopcount, nickTS, umodes, username, visible hostname, IP address,
|
|
|
|
# UID, gecos
|
|
|
|
|
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-10-01 08:33:27 +02:00
|
|
|
raise ValueError('Server %r is not a PyLink server!' % server)
|
|
|
|
|
|
|
|
uid = self.uidgen[server].next_uid()
|
|
|
|
|
|
|
|
ts = ts or int(time.time())
|
2017-03-05 09:06:19 +01:00
|
|
|
realname = realname or conf.conf['bot']['realname']
|
2017-06-30 07:56:14 +02:00
|
|
|
raw_modes = self.join_modes(modes)
|
2016-10-01 08:45:30 +02:00
|
|
|
|
|
|
|
orig_realhost = realhost
|
|
|
|
realhost = realhost or host
|
|
|
|
|
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-10-01 08:33:27 +02:00
|
|
|
realhost=realhost, ip=ip, manipulatable=manipulatable)
|
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)
|
2017-06-30 06:55:52 +02:00
|
|
|
|
2017-09-24 07:36:16 +02:00
|
|
|
self._send_with_prefix(server, "UID {nick} {hopcount} {ts} {modes} {ident} {host} {ip} {uid} "
|
2017-06-30 06:55:52 +02:00
|
|
|
":{realname}".format(ts=ts, host=host,
|
|
|
|
nick=nick, ident=ident, uid=uid,
|
2017-09-24 07:36:16 +02:00
|
|
|
modes=raw_modes, ip=ip, realname=realname,
|
|
|
|
hopcount=self.servers[server].hopcount))
|
2016-10-01 08:45:30 +02:00
|
|
|
|
|
|
|
if orig_realhost:
|
|
|
|
# If real host is specified, send it using ENCAP REALHOST
|
2017-06-30 06:55:52 +02:00
|
|
|
self._send_with_prefix(uid, "ENCAP * REALHOST %s" % orig_realhost)
|
2016-10-01 08:45:30 +02:00
|
|
|
|
2016-10-01 08:33:27 +02:00
|
|
|
return u
|
|
|
|
|
2017-07-01 06:29:38 +02:00
|
|
|
def update_client(self, target, field, text):
|
|
|
|
"""update_client() stub for ratbox."""
|
2017-03-26 23:32:41 +02:00
|
|
|
raise NotImplementedError("User data changing is not supported on ircd-ratbox.")
|
2016-10-01 09:19:52 +02:00
|
|
|
|
2016-10-01 08:33:27 +02:00
|
|
|
Class = RatboxProtocol
|