2016-10-01 08:33:27 +02:00
|
|
|
import time
|
|
|
|
|
|
|
|
from pylinkirc import utils
|
|
|
|
from pylinkirc.log import log
|
|
|
|
from pylinkirc.classes import *
|
|
|
|
from pylinkirc.protocols.ts6 import *
|
|
|
|
|
|
|
|
class RatboxProtocol(TS6Protocol):
|
|
|
|
|
|
|
|
def __init__(self, irc):
|
|
|
|
super().__init__(irc)
|
|
|
|
# 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'
|
|
|
|
|
2016-10-01 08:33:27 +02:00
|
|
|
def connect(self):
|
|
|
|
"""Initializes a connection to a server."""
|
|
|
|
super().connect()
|
|
|
|
|
2016-10-01 22:00:04 +02:00
|
|
|
# Note: +r, +e, and +I support will be negotiated on link
|
|
|
|
self.irc.cmodes = {'op': 'o', 'secret': 's', 'private': 'p', 'noextmsg': 'n', 'moderated': 'm',
|
|
|
|
'inviteonly': 'i', 'topiclock': 't', 'limit': 'l', 'ban': 'b', 'voice': 'v',
|
|
|
|
'key': 'k', 'sslonly': 'S',
|
|
|
|
'*A': 'beI',
|
|
|
|
'*B': 'k',
|
|
|
|
'*C': 'l',
|
|
|
|
'*D': 'imnpstr'}
|
2016-10-01 08:33:27 +02:00
|
|
|
|
|
|
|
self.irc.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'
|
|
|
|
}
|
|
|
|
|
|
|
|
def spawnClient(self, nick, ident='null', host='null', realhost=None, modes=set(),
|
|
|
|
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
|
|
|
|
|
|
|
|
server = server or self.irc.sid
|
|
|
|
if not self.irc.isInternalServer(server):
|
|
|
|
raise ValueError('Server %r is not a PyLink server!' % server)
|
|
|
|
|
|
|
|
uid = self.uidgen[server].next_uid()
|
|
|
|
|
|
|
|
ts = ts or int(time.time())
|
|
|
|
realname = realname or self.irc.botdata['realname']
|
|
|
|
raw_modes = self.irc.joinModes(modes)
|
2016-10-01 08:45:30 +02:00
|
|
|
|
|
|
|
orig_realhost = realhost
|
|
|
|
realhost = realhost or host
|
|
|
|
|
2016-11-10 03:40:16 +01:00
|
|
|
u = self.irc.users[uid] = IrcUser(nick, ts, uid, server, ident=ident, host=host, realname=realname,
|
2016-10-01 08:33:27 +02:00
|
|
|
realhost=realhost, ip=ip, manipulatable=manipulatable)
|
|
|
|
self.irc.applyModes(uid, modes)
|
|
|
|
self.irc.servers[server].users.add(uid)
|
|
|
|
self._send(server, "UID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} "
|
|
|
|
":{realname}".format(ts=ts, host=host,
|
|
|
|
nick=nick, ident=ident, uid=uid,
|
|
|
|
modes=raw_modes, ip=ip, realname=realname))
|
2016-10-01 08:45:30 +02:00
|
|
|
|
|
|
|
if orig_realhost:
|
|
|
|
# If real host is specified, send it using ENCAP REALHOST
|
2016-10-01 09:40:20 +02:00
|
|
|
self._send(uid, "ENCAP * REALHOST %s" % orig_realhost)
|
2016-10-01 08:45:30 +02:00
|
|
|
|
2016-10-01 08:33:27 +02:00
|
|
|
return u
|
|
|
|
|
2016-10-01 09:19:52 +02:00
|
|
|
def updateClient(self, target, field, text):
|
|
|
|
"""updateClient() stub for ratbox."""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2016-10-01 08:45:30 +02:00
|
|
|
def handle_realhost(self, uid, command, args):
|
|
|
|
"""Handles real host propagation."""
|
|
|
|
log.debug('(%s) Got REALHOST %s for %s', args[0], uid)
|
|
|
|
self.irc.users[uid].realhost = args[0]
|
|
|
|
|
2016-10-01 21:39:25 +02:00
|
|
|
def handle_login(self, uid, command, args):
|
|
|
|
"""Handles login propagation on burst."""
|
|
|
|
self.irc.users[uid].services_account = args[0]
|
|
|
|
return {'text': args[0]}
|
|
|
|
|
2016-10-01 08:33:27 +02:00
|
|
|
Class = RatboxProtocol
|