From 1e79adc17138a397b159b6ad1ecda49e09c17344 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sat, 26 Dec 2015 16:49:55 +1000 Subject: [PATCH 01/17] hybrid: Start module, very very broken --- protocols/hybrid.py | 365 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 365 insertions(+) create mode 100644 protocols/hybrid.py diff --git a/protocols/hybrid.py b/protocols/hybrid.py new file mode 100644 index 0000000..4918d42 --- /dev/null +++ b/protocols/hybrid.py @@ -0,0 +1,365 @@ +import time +import sys +import os +import re + +curdir = os.path.dirname(__file__) +sys.path += [curdir, os.path.dirname(curdir)] +import utils +from log import log + +from classes import * +from ts6_common import TS6BaseProtocol + +class HybridProtocol(TS6BaseProtocol): + def __init__(self, irc): + super(HybridProtocol, self).__init__(irc) + self.casemapping = 'ascii' + self.sidgen = utils.TS6SIDGenerator(self.irc) + self.uidgen = {} + self.eob = False + + self.caps = {} + self.irc.prefixmodes = {'o': '@', 'h': '%', 'v': '+'} + + def connect(self): + """Initializes a connection to a server.""" + ts = self.irc.start_ts + + f = self.irc.send + # Valid keywords (from mostly InspIRCd's named modes): + # admin allowinvite autoop ban banexception blockcolor + # c_registered exemptchanops filter forward flood halfop history invex + # inviteonly joinflood key kicknorejoin limit moderated nickflood + # noctcp noextmsg nokick noknock nonick nonotice official-join op + # operonly opmoderated owner permanent private redirect regonly + # regmoderated secret sslonly stripcolor topiclock voice + + # https://github.com/grawity/irc-docs/blob/master/server/ts6.txt#L80 + cmodes = { + # TS6 generic modes: + 'op': 'o', 'voice': 'v', 'ban': 'b', 'key': 'k', 'limit': + 'l', 'moderated': 'm', 'noextmsg': 'n', + 'secret': 's', 'topiclock': 't', + # hybrid-specific modes: + 'blockcolor': 'c', 'inviteonly': 'i', 'noctcp': 'C', + 'regmoderated': 'M', 'operonly': 'O', 'regonly': 'R', + 'sslonly': 'S', 'banexception': 'e', + # # cannot handle? + # 'paranoia': 'p', 'registered': 'r', 'inviteexempt': 'I', + # Now, map all the ABCD type modes: + '*A': 'beI', '*B': 'k', '*C': 'l', '*D': 'cimnprstCMORS' + } + + if self.irc.serverdata.get('use_halfop'): + cmodes['halfop'] = 'h' + self.irc.prefixmodes['h'] = '%' + + self.irc.cmodes.update(cmodes) + + # Same thing with umodes: + # bot callerid cloak deaf_commonchan helpop hidechans hideoper invisible oper + # regdeaf servprotect showwhois snomask u_registered u_stripcolor wallops + umodes = { + 'oper': 'o', 'invisible': 'i', 'wallops': 'w', 'chary_locops': 'l', + 'cloak': 'x', 'hidechans': 'p', 'regdeaf': 'R', 'deaf': 'D', + 'callerid': 'g', + # # can't handle? + # 'webirc': 'W', 'client_connections': 'c', 'bad_client_connections': 'u', + # 'rejected_clients': 'j', 'skill_notices': 'k', 'fullauthblock': 'f', + # 'remote_client_connections': 'F', 'admin_requests': 'y', 'debug': 'd', + # 'nickchange_notices': 'n', 'hideidle': 'q', 'registered': 'r', + # 'smessages': 's', 'ssl': 'S', 'sjoins': 'e', 'botfloods': 'b', + # 'showadmin': 'a', 'softcallerid': 'G', 'hideops': 'H', + # Now, map all the ABCD type modes: + '*A': '', '*B': '', '*C': '', '*D': 'oiwlxpRDg' + } + + self.irc.umodes.update(umodes) + + # https://github.com/grawity/irc-docs/blob/master/server/ts6.txt#L55 + f('PASS %s TS 6 %s' % (self.irc.serverdata["sendpass"], self.irc.sid)) + + # We request the following capabilities (for hybrid): + + # ENCAP: message encapsulation for certain commands + # EX: Support for ban exemptions (+e) + # IE: Support for invite exemptions (+e) + # CHW: Allow sending messages to @#channel and the like. + # KNOCK: Support for /knock + # SVS: Deal with extended NICK/UID messages that contain service IDs/stamps + # TBURST: Topic Burst command; we send this in topicServer + # DLN: DLINE command + # UNDLN: UNDLINE command + # KLN: KLINE command + # UNKLN: UNKLINE command + # HOPS: Supports HALFOPS + # CHW: Can do channel wall (@#) + # CLUSTER: Supports server clustering + # EOB: Supports EOB (end of burst) command + f('CAPAB :TBURST DLN KNOCK UNDLN UNKLN KLN ENCAP IE EX HOPS CHW SVS CLUSTER EOB QS') + + f('SERVER %s 0 :%s' % (self.irc.serverdata["hostname"], + self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc'])) + + 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 client with 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.""" + server = server or self.irc.sid + if not utils.isInternalServer(self.irc, server): + raise ValueError('Server %r is not a PyLink internal PseudoServer!' % server) + # Create an UIDGenerator instance for every SID, so that each gets + # distinct values. + uid = self.uidgen.setdefault(server, utils.TS6UIDGenerator(server)).next_uid() + # EUID: + # parameters: nickname, hopcount, nickTS, umodes, username, + # visible hostname, IP address, UID, real hostname, account name, gecos + ts = ts or int(time.time()) + realname = realname or self.irc.botdata['realname'] + realhost = realhost or host + raw_modes = utils.joinModes(modes) + u = self.irc.users[uid] = IrcUser(nick, ts, uid, ident=ident, host=host, realname=realname, + realhost=realhost, ip=ip, manipulatable=manipulatable) + utils.applyModes(self.irc, 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)) + # self._send(server, "EUID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} " + # "{realhost} * :{realname}".format(ts=ts, host=host, + # nick=nick, ident=ident, uid=uid, + # modes=raw_modes, ip=ip, realname=realname, + # realhost=realhost)) + # # <- :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} " + # "{host} * {ip} :{realname}".format(ts=ts, host=host, + # nick=nick, ident=ident, uid=uid, + # modes=raw_modes, realname=realname, + # realhost=realhost, ip=encoded_ip)) + # # 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) + return u + + def updateClient(self, numeric, field, text): + """Updates the ident, host, or realname of a PyLink client.""" + field = field.upper() + if field == 'IDENT': + self.irc.users[numeric].ident = text + self._send(numeric, 'SETIDENT %s' % text) + elif field == 'HOST': + self.irc.users[numeric].host = text + self._send(numeric, 'SETHOST %s' % text) + elif field in ('REALNAME', 'GECOS'): + self.irc.users[numeric].realname = text + self._send(numeric, 'SETNAME :%s' % text) + else: + raise NotImplementedError("Changing field %r of a client is unsupported by this protocol." % field) + + def joinClient(self, client, channel): + """Joins a PyLink client to a channel.""" + channel = utils.toLower(self.irc, channel) + if not utils.isInternalClient(self.irc, client): + 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) + + def pingServer(self, source=None, target=None): + """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.""" + 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' % (source,)) + + def handle_events(self, data): + """Event handler for the Hybrid protocol. + + This passes most commands to the various handle_ABCD() functions + elsewhere in this module, coersing various sender prefixes from nicks + to UIDs wherever possible. + """ + data = data.split(" ") + if not data: + # No data?? + return + try: # Message starts with a SID/UID prefix. + args = self.parseTS6Args(data) + sender = args[0] + command = args[1] + args = args[2:] + # If the sender isn't in UID format, try to convert it automatically + sender_server = self._getSid(sender) + if sender_server in self.irc.servers: + # Sender is a server when converted from name to SID. + numeric = sender_server + else: + # Sender is a user. + numeric = self._getNick(sender) + # parseTS6Args() will raise IndexError if the TS6 sender prefix is missing. + except IndexError: + # Raw command without an explicit sender; assume it's being sent by our uplink. + args = self.parseArgs(data) + numeric = self.irc.uplink + command = args[0] + args = args[1:] + try: + func = getattr(self, 'handle_'+command.lower()) + except AttributeError: # unhandled command + # self._send(self.irc.sid, 'ERROR', 'Unknown Command') + print('Unknown command.\nOffending line: {}'.format(data)) + exit(1) + else: + parsed_args = func(numeric, command, args) + if parsed_args is not None: + return [numeric, command, parsed_args] + + def _getNick(self, target): + """Converts a nick argument to its matching UID. This differs from utils.nickToUid() + in that it returns the original text instead of None, if no matching nick is found.""" + target = utils.nickToUid(self.irc, target) or target + if target not in self.irc.users and not utils.isChannel(target): + log.debug("(%s) Possible desync? Got command target %s, who " + "isn't in our user list!", self.irc.name, target) + return target + + # command handlers + def handle_pass(self, numeric, command, args): + # <- PASS $somepassword TS 6 42X + if args[0] != self.irc.serverdata['recvpass']: + raise ProtocolError("Error: RECVPASS from uplink does not match configuration!") + ver = args[args.index('TS') + 1] + if ver != '6': + raise ProtocolError("Remote protocol version {} is too old! Is this even TS6?".format()) + numeric = args[3] + log.debug('(%s) Found uplink SID as %r', self.irc.name, numeric) + self.irc.servers[numeric] = IrcServer(None, 'unknown') + self.irc.uplink = numeric + + def handle_capab(self, numeric, command, args): + # We only get a list of keywords here. Charybdis obviously assumes that + # we know what modes it supports (indeed, this is a standard list). + # <- CAPAB :BAN CHW CLUSTER ENCAP EOPMOD EUID EX IE KLN KNOCK MLOCK QS RSFNC SAVE SERVICES TB UNKLN + self.irc.caps = caps = args[0].split() + # for required_cap in ('EUID', 'SAVE', 'TB', 'ENCAP', 'QS'): + # if required_cap not in caps: + # raise ProtocolError('%s not found in TS6 capabilities list; this is required! (got %r)' % (required_cap, caps)) + + log.debug('(%s) self.irc.connected set!', self.irc.name) + self.irc.connected.set() + + def handle_server(self, numeric, command, args): + # <- SERVER charybdis.midnight.vpn 1 :charybdis test server + sname = args[0].lower() + log.debug('(%s) Found uplink server name as %r', self.irc.name, sname) + self.irc.servers[self.irc.uplink].name = sname + self.irc.servers[self.irc.uplink].desc = args[2] + # According to the TS6 protocol documentation, we should send SVINFO + # when we get our uplink's SERVER command. + self.irc.send('SVINFO 6 6 0 :%s' % int(time.time())) + + def handle_svinfo(self, numeric, command, args): + # TODO: do things here? + pass + + def handle_uid(self, numeric, command, args): + """Handles incoming UID commands (user introduction).""" + # <- :0UY UID dan 1 1451041551 +Facdeiklosuw ~ident localhost 127.0.0.1 0UYAAAAAB * :realname + nick = args[0] + ts, modes, ident, host, ip, uid, account, realname = args[2:10] + if account == '*': + account = None + log.debug('(%s) handle_uid got args: nick=%s ts=%s uid=%s ident=%s ' + 'host=%s realname=%s ip=%s', self.irc.name, nick, ts, uid, + ident, host, realname, ip) + + self.irc.users[uid] = IrcUser(nick, ts, uid, ident, host, realname, realname, ip) + parsedmodes = utils.parseModes(self.irc, uid, [modes]) + log.debug('Applying modes %s for %s', parsedmodes, uid) + utils.applyModes(self.irc, uid, parsedmodes) + self.irc.servers[numeric].users.add(uid) + # Call the OPERED UP hook if +o is being added to the mode list. + if ('+o', None) in parsedmodes: + self.irc.callHooks([uid, 'PYLINK_CLIENT_OPERED', {'text': 'IRC_Operator'}]) + return {'uid': uid, 'ts': ts, 'nick': nick, 'realname': realname, 'host': host, 'ident': ident, 'ip': ip} + + def handle_svstag(self, numeric, command, args): + if args[2] in ['313']: + return + raise Exception('COULD NOT PARSE SVSTAG: {} {} {}'.format(numeric, command, args)) + + def handle_sjoin(self, numeric, command, args): + """Handles incoming channel JOINs.""" + # parameters: channelTS, channel, '+' (a plus sign) + # <- :0UY SJOIN 1451041566 #channel +nt :@0UYAAAAAB + ts = int(args[0]) + uids = args[3].split() + users = {} + umodes = ['+'] + modeprefixes = {v: k for k, v in self.irc.prefixmodes.items()} + for uid in uids: + modes = '' + while uid and uid[0] in modeprefixes: + modes += uid[0] + uid = uid[1:] + for mode in modes: + umodes[0] += modeprefixes[mode] + umodes.append(uid) + if args[1] == '0': + # /join 0; part the user from all channels + for uid in users: + oldchans = self.irc.users[uid].channels.copy() + log.debug('(%s) Got /join 0 from %r, channel list is %r', + self.irc.name, uid, oldchans) + for channel in oldchans: + self.irc.channels[channel].users.discard(uid) + self.irc.users[uid].channels.discard(channel) + # return {'channels': oldchans, 'text': 'Left all channels.', 'parse_as': 'PART'} + else: + channel = utils.toLower(self.irc, args[1]) + self.updateTS(channel, ts) + parsedmodes = utils.parseModes(self.irc, channel, [args[2]]) + utils.applyModes(self.irc, channel, parsedmodes) + parsedmodes = utils.parseModes(self.irc, channel, umodes) + utils.applyModes(self.irc, channel, parsedmodes) + # We send users and modes here because SJOIN and JOIN both use one hook, + # for simplicity's sake (with plugins). + return {'channel': channel, 'users': uids, 'modes': + self.irc.channels[channel].modes, 'ts': ts} + + def handle_ping(self, source, command, args): + """Handles incoming PING commands.""" + # PING: + # source: any + # parameters: origin, opt. destination server + # PONG: + # source: server + # parameters: origin, destination + + # Sends a PING to the destination server, which will reply with a PONG. If the + # destination server parameter is not present, the server receiving the message + # must reply. + try: + destination = args[1] + except IndexError: + destination = self.irc.sid + if utils.isInternalServer(self.irc, destination): + self._send(destination, 'PONG %s :%s' % (self.irc.servers[destination].name, source)) + if not self.eob: + self._send(destination, 'EOB') + + def handle_eob(self, source, command, args): + """Handles incoming EOB commands.""" + self.irc.callHooks([source, 'ENDBURST', { + 'ts': int(time.time()), + }]) + + +Class = HybridProtocol From 7ec496241223295ce53ca9ed6419d57edf8fdd83 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sun, 27 Dec 2015 09:18:06 +1000 Subject: [PATCH 02/17] hybrid: Implement suggested changes, remove comments --- protocols/hybrid.py | 63 +++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 42 deletions(-) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index 4918d42..2871600 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -17,11 +17,13 @@ class HybridProtocol(TS6BaseProtocol): self.casemapping = 'ascii' self.sidgen = utils.TS6SIDGenerator(self.irc) self.uidgen = {} - self.eob = False self.caps = {} + # halfops is mandatory on Hybrid self.irc.prefixmodes = {'o': '@', 'h': '%', 'v': '+'} + self.hook_map = {'EOB': 'ENDBURST'} + def connect(self): """Initializes a connection to a server.""" ts = self.irc.start_ts @@ -44,17 +46,12 @@ class HybridProtocol(TS6BaseProtocol): # hybrid-specific modes: 'blockcolor': 'c', 'inviteonly': 'i', 'noctcp': 'C', 'regmoderated': 'M', 'operonly': 'O', 'regonly': 'R', - 'sslonly': 'S', 'banexception': 'e', - # # cannot handle? - # 'paranoia': 'p', 'registered': 'r', 'inviteexempt': 'I', + 'sslonly': 'S', 'banexception': 'e', 'paranoia': 'p', + 'registered': 'r', 'inviteexempt': 'I', # Now, map all the ABCD type modes: '*A': 'beI', '*B': 'k', '*C': 'l', '*D': 'cimnprstCMORS' } - if self.irc.serverdata.get('use_halfop'): - cmodes['halfop'] = 'h' - self.irc.prefixmodes['h'] = '%' - self.irc.cmodes.update(cmodes) # Same thing with umodes: @@ -63,14 +60,12 @@ class HybridProtocol(TS6BaseProtocol): umodes = { 'oper': 'o', 'invisible': 'i', 'wallops': 'w', 'chary_locops': 'l', 'cloak': 'x', 'hidechans': 'p', 'regdeaf': 'R', 'deaf': 'D', - 'callerid': 'g', - # # can't handle? - # 'webirc': 'W', 'client_connections': 'c', 'bad_client_connections': 'u', - # 'rejected_clients': 'j', 'skill_notices': 'k', 'fullauthblock': 'f', - # 'remote_client_connections': 'F', 'admin_requests': 'y', 'debug': 'd', - # 'nickchange_notices': 'n', 'hideidle': 'q', 'registered': 'r', - # 'smessages': 's', 'ssl': 'S', 'sjoins': 'e', 'botfloods': 'b', - # 'showadmin': 'a', 'softcallerid': 'G', 'hideops': 'H', + 'callerid': 'g', 'showadmin': 'a', 'softcallerid': 'G', 'hideops': 'H', + 'webirc': 'W', 'client_connections': 'c', 'bad_client_connections': 'u', + 'rejected_clients': 'j', 'skill_notices': 'k', 'fullauthblock': 'f', + 'remote_client_connections': 'F', 'admin_requests': 'y', 'debug': 'd', + 'nickchange_notices': 'n', 'hideidle': 'q', 'registered': 'r', + 'smessages': 's', 'ssl': 'S', 'sjoins': 'e', 'botfloods': 'b', # Now, map all the ABCD type modes: '*A': '', '*B': '', '*C': '', '*D': 'oiwlxpRDg' } @@ -102,6 +97,9 @@ class HybridProtocol(TS6BaseProtocol): f('SERVER %s 0 :%s' % (self.irc.serverdata["hostname"], self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc'])) + f(':%s EOB' % (self.irc.sid,)) + print('SENT DSID') + 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): @@ -130,21 +128,6 @@ class HybridProtocol(TS6BaseProtocol): "* :{realname}".format(ts=ts, host=host, nick=nick, ident=ident, uid=uid, modes=raw_modes, ip=ip, realname=realname)) - # self._send(server, "EUID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} " - # "{realhost} * :{realname}".format(ts=ts, host=host, - # nick=nick, ident=ident, uid=uid, - # modes=raw_modes, ip=ip, realname=realname, - # realhost=realhost)) - # # <- :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} " - # "{host} * {ip} :{realname}".format(ts=ts, host=host, - # nick=nick, ident=ident, uid=uid, - # modes=raw_modes, realname=realname, - # realhost=realhost, ip=encoded_ip)) - # # 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) return u def updateClient(self, numeric, field, text): @@ -211,6 +194,7 @@ class HybridProtocol(TS6BaseProtocol): command = args[0] args = args[1:] try: + command = self.hook_map.get(command.upper(), command).lower() func = getattr(self, 'handle_'+command.lower()) except AttributeError: # unhandled command # self._send(self.irc.sid, 'ERROR', 'Unknown Command') @@ -265,10 +249,6 @@ class HybridProtocol(TS6BaseProtocol): # when we get our uplink's SERVER command. self.irc.send('SVINFO 6 6 0 :%s' % int(time.time())) - def handle_svinfo(self, numeric, command, args): - # TODO: do things here? - pass - def handle_uid(self, numeric, command, args): """Handles incoming UID commands (user introduction).""" # <- :0UY UID dan 1 1451041551 +Facdeiklosuw ~ident localhost 127.0.0.1 0UYAAAAAB * :realname @@ -352,14 +332,13 @@ class HybridProtocol(TS6BaseProtocol): destination = self.irc.sid if utils.isInternalServer(self.irc, destination): self._send(destination, 'PONG %s :%s' % (self.irc.servers[destination].name, source)) - if not self.eob: - self._send(destination, 'EOB') - def handle_eob(self, source, command, args): - """Handles incoming EOB commands.""" - self.irc.callHooks([source, 'ENDBURST', { - 'ts': int(time.time()), - }]) + # empty handlers + # TODO: there's a better way to do this + def handle_svinfo(self, numeric, command, args): + pass + def handle_endburst(self, numeric, command, args): + pass Class = HybridProtocol From 24589b21c1d5ed6833f5df5b68efaab301be5e50 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sun, 27 Dec 2015 09:28:48 +1000 Subject: [PATCH 03/17] hybrid: Handle PONG --- protocols/hybrid.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index 2871600..adfb12c 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -333,6 +333,11 @@ class HybridProtocol(TS6BaseProtocol): if utils.isInternalServer(self.irc, destination): self._send(destination, 'PONG %s :%s' % (self.irc.servers[destination].name, source)) + def handle_pong(self, source, command, args): + """Handles incoming PONG commands.""" + if source == self.irc.uplink and args[1] == self.irc.sid: + self.irc.lastping = time.time() + # empty handlers # TODO: there's a better way to do this def handle_svinfo(self, numeric, command, args): From 46610d217dd4722a771ad370ffa543e8ef3a0ecf Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sun, 27 Dec 2015 09:35:45 +1000 Subject: [PATCH 04/17] hybrid: Remove silly debug print --- protocols/hybrid.py | 1 - 1 file changed, 1 deletion(-) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index adfb12c..6a10a16 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -98,7 +98,6 @@ class HybridProtocol(TS6BaseProtocol): self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc'])) f(':%s EOB' % (self.irc.sid,)) - print('SENT DSID') 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, From e914dc1e8e54b84040ae489bc6a72b15b051ac70 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sun, 27 Dec 2015 09:43:52 +1000 Subject: [PATCH 05/17] hybrid: Start making modes more consistent --- protocols/hybrid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index 6a10a16..8886004 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -47,7 +47,7 @@ class HybridProtocol(TS6BaseProtocol): 'blockcolor': 'c', 'inviteonly': 'i', 'noctcp': 'C', 'regmoderated': 'M', 'operonly': 'O', 'regonly': 'R', 'sslonly': 'S', 'banexception': 'e', 'paranoia': 'p', - 'registered': 'r', 'inviteexempt': 'I', + 'registered': 'r', 'invex': 'I', # Now, map all the ABCD type modes: '*A': 'beI', '*B': 'k', '*C': 'l', '*D': 'cimnprstCMORS' } From 6ff06cb881b8e3a0ec0878e4359ed297ab206a8f Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sun, 27 Dec 2015 09:49:32 +1000 Subject: [PATCH 06/17] hybrid: Use new CLIENT_OPERED name --- protocols/hybrid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index 8886004..d31d086 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -266,7 +266,7 @@ class HybridProtocol(TS6BaseProtocol): self.irc.servers[numeric].users.add(uid) # Call the OPERED UP hook if +o is being added to the mode list. if ('+o', None) in parsedmodes: - self.irc.callHooks([uid, 'PYLINK_CLIENT_OPERED', {'text': 'IRC_Operator'}]) + self.irc.callHooks([uid, 'CLIENT_OPERED', {'text': 'IRC_Operator'}]) return {'uid': uid, 'ts': ts, 'nick': nick, 'realname': realname, 'host': host, 'ident': ident, 'ip': ip} def handle_svstag(self, numeric, command, args): From 3cd2dbac5ae496c9cd316bde86df4eaf254dba57 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Tue, 29 Mar 2016 18:35:29 +1000 Subject: [PATCH 07/17] hybrid: Update for new methods --- protocols/hybrid.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index d31d086..f92ff3d 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -107,7 +107,7 @@ class HybridProtocol(TS6BaseProtocol): Note: No nick collision / valid nickname checks are done here; it is up to plugins to make sure they don't introduce anything invalid.""" server = server or self.irc.sid - if not utils.isInternalServer(self.irc, server): + if not self.irc.isInternalServer(server): raise ValueError('Server %r is not a PyLink internal PseudoServer!' % server) # Create an UIDGenerator instance for every SID, so that each gets # distinct values. @@ -144,16 +144,16 @@ class HybridProtocol(TS6BaseProtocol): else: raise NotImplementedError("Changing field %r of a client is unsupported by this protocol." % field) - def joinClient(self, client, channel): + def join(self, client, channel): """Joins a PyLink client to a channel.""" channel = utils.toLower(self.irc, channel) - if not utils.isInternalClient(self.irc, client): + if not self.irc.isInternalClient(client): 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) - def pingServer(self, source=None, target=None): + def ping(self, source=None, target=None): """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.""" source = source or self.irc.sid @@ -204,15 +204,6 @@ class HybridProtocol(TS6BaseProtocol): if parsed_args is not None: return [numeric, command, parsed_args] - def _getNick(self, target): - """Converts a nick argument to its matching UID. This differs from utils.nickToUid() - in that it returns the original text instead of None, if no matching nick is found.""" - target = utils.nickToUid(self.irc, target) or target - if target not in self.irc.users and not utils.isChannel(target): - log.debug("(%s) Possible desync? Got command target %s, who " - "isn't in our user list!", self.irc.name, target) - return target - # command handlers def handle_pass(self, numeric, command, args): # <- PASS $somepassword TS 6 42X @@ -329,7 +320,7 @@ class HybridProtocol(TS6BaseProtocol): destination = args[1] except IndexError: destination = self.irc.sid - if utils.isInternalServer(self.irc, destination): + if self.irc.isInternalServer(destination): self._send(destination, 'PONG %s :%s' % (self.irc.servers[destination].name, source)) def handle_pong(self, source, command, args): From a2bd0a86174debef980cfc089efe9e7cac775b40 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Tue, 29 Mar 2016 19:51:12 +1000 Subject: [PATCH 08/17] hybrid: Fix JOIN, handle JOIN (hopefully correctly), send EOB after receiving EOB --- protocols/hybrid.py | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index f92ff3d..064fc28 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -97,8 +97,6 @@ class HybridProtocol(TS6BaseProtocol): f('SERVER %s 0 :%s' % (self.irc.serverdata["hostname"], self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc'])) - f(':%s EOB' % (self.irc.sid,)) - 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): @@ -149,7 +147,7 @@ class HybridProtocol(TS6BaseProtocol): channel = utils.toLower(self.irc, channel) if not self.irc.isInternalClient(client): raise LookupError('No such PyLink client exists.') - self._send(client, "JOIN %s" % channel) + self._send(client, "JOIN 0 %s +" % channel) self.irc.channels[channel].users.add(client) self.irc.users[client].channels.add(channel) @@ -200,6 +198,7 @@ class HybridProtocol(TS6BaseProtocol): print('Unknown command.\nOffending line: {}'.format(data)) exit(1) else: + log.debug('(%s) Handling event %s - %s - %s', self.irc.name, numeric, command, str(args)) parsed_args = func(numeric, command, args) if parsed_args is not None: return [numeric, command, parsed_args] @@ -261,13 +260,37 @@ class HybridProtocol(TS6BaseProtocol): return {'uid': uid, 'ts': ts, 'nick': nick, 'realname': realname, 'host': host, 'ident': ident, 'ip': ip} def handle_svstag(self, numeric, command, args): - if args[2] in ['313']: + tag = args[2] + if tag in ['313']: return raise Exception('COULD NOT PARSE SVSTAG: {} {} {}'.format(numeric, command, args)) - def handle_sjoin(self, numeric, command, args): + def handle_join(self, numeric, command, args): """Handles incoming channel JOINs.""" # parameters: channelTS, channel, '+' (a plus sign) + # <- :0UYAAAAAF JOIN 0 #channel + + ts = int(args[0]) + uid = numeric + channel = args[1] + if channel == '0': + # /join 0; part the user from all channels + oldchans = self.irc.users[uid].channels.copy() + log.debug('(%s) Got /join 0 from %r, channel list is %r', + self.irc.name, uid, oldchans) + for channel in oldchans: + self.irc.channels[channel].users.discard(uid) + self.irc.users[uid].channels.discard(channel) + else: + channel = utils.toLower(self.irc, args[1]) + self.updateTS(channel, ts) + parsedmodes = utils.parseModes(self.irc, channel, [args[2]]) + utils.applyModes(self.irc, channel, parsedmodes) + return {'channel': channel, 'users': [uid], 'modes': + self.irc.channels[channel].modes, 'ts': ts} + + def handle_sjoin(self, numeric, command, args): + """Handles incoming channel SJOINs.""" + # parameters: channelTS, channel, modes, prefixed uids # <- :0UY SJOIN 1451041566 #channel +nt :@0UYAAAAAB ts = int(args[0]) uids = args[3].split() @@ -325,7 +348,9 @@ class HybridProtocol(TS6BaseProtocol): def handle_pong(self, source, command, args): """Handles incoming PONG commands.""" + log.debug('(%s) Ping received from %s for %s.', self.irc.name, source, args[1]) if source == self.irc.uplink and args[1] == self.irc.sid: + log.debug('(%s) Set self.irc.lastping.', self.irc.name) self.irc.lastping = time.time() # empty handlers @@ -334,6 +359,7 @@ class HybridProtocol(TS6BaseProtocol): pass def handle_endburst(self, numeric, command, args): + self.irc.send(':%s EOB' % (self.irc.sid,)) pass Class = HybridProtocol From c4608fb891ce095fa57011d438aac7f8a2fb4b69 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Wed, 30 Mar 2016 11:34:52 +1000 Subject: [PATCH 09/17] hybrid: Set prefixmodes properly, handle MODE and TMODE --- protocols/hybrid.py | 49 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index 064fc28..e7ad748 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -19,8 +19,6 @@ class HybridProtocol(TS6BaseProtocol): self.uidgen = {} self.caps = {} - # halfops is mandatory on Hybrid - self.irc.prefixmodes = {'o': '@', 'h': '%', 'v': '+'} self.hook_map = {'EOB': 'ENDBURST'} @@ -40,8 +38,8 @@ class HybridProtocol(TS6BaseProtocol): # https://github.com/grawity/irc-docs/blob/master/server/ts6.txt#L80 cmodes = { # TS6 generic modes: - 'op': 'o', 'voice': 'v', 'ban': 'b', 'key': 'k', 'limit': - 'l', 'moderated': 'm', 'noextmsg': 'n', + 'op': 'o', 'halfop': 'h', 'voice': 'v', 'ban': 'b', 'key': 'k', + 'limit': 'l', 'moderated': 'm', 'noextmsg': 'n', 'secret': 's', 'topiclock': 't', # hybrid-specific modes: 'blockcolor': 'c', 'inviteonly': 'i', 'noctcp': 'C', @@ -72,6 +70,9 @@ class HybridProtocol(TS6BaseProtocol): self.irc.umodes.update(umodes) + # halfops is mandatory on Hybrid + self.irc.prefixmodes = {'o': '@', 'h': '%', 'v': '+'} + # https://github.com/grawity/irc-docs/blob/master/server/ts6.txt#L55 f('PASS %s TS 6 %s' % (self.irc.serverdata["sendpass"], self.irc.sid)) @@ -283,8 +284,6 @@ class HybridProtocol(TS6BaseProtocol): else: channel = utils.toLower(self.irc, args[1]) self.updateTS(channel, ts) - parsedmodes = utils.parseModes(self.irc, channel, [args[2]]) - utils.applyModes(self.irc, channel, parsedmodes) return {'channel': channel, 'users': [uid], 'modes': self.irc.channels[channel].modes, 'ts': ts} @@ -353,13 +352,41 @@ class HybridProtocol(TS6BaseProtocol): log.debug('(%s) Set self.irc.lastping.', self.irc.name) self.irc.lastping = time.time() - # empty handlers - # TODO: there's a better way to do this - def handle_svinfo(self, numeric, command, args): - pass - def handle_endburst(self, numeric, command, args): self.irc.send(':%s EOB' % (self.irc.sid,)) pass + def handle_mode(self, numeric, command, args): + # <- :0UYAAAAAD MODE 0UYAAAAAD :-i + target = args[0] + modestrings = args[1:] + changedmodes = utils.parseModes(self.irc, target, modestrings) + utils.applyModes(self.irc, target, changedmodes) + # Call the OPERED UP hook if +o is being set. + if ('+o', None) in changedmodes: + otype = 'IRC Operator' + self.irc.callHooks([target, 'CLIENT_OPERED', {'text': otype}]) + return {'target': target, 'modes': changedmodes} + + def handle_tmode(self, numeric, command, args): + # <- :0UYAAAAAD TMODE 0 #a +h 0UYAAAAAD + channel = utils.toLower(self.irc, args[1]) + oldobj = self.irc.channels[channel].deepcopy() + modes = args[2:] + changedmodes = utils.parseModes(self.irc, channel, modes) + utils.applyModes(self.irc, channel, changedmodes) + ts = int(args[0]) + if ts > 0: + self.updateTS(channel, ts) + return {'target': channel, 'modes': changedmodes, 'ts': ts, + 'oldchan': oldobj} + + # empty handlers + # TODO: there's a better way to do this + def handle_globops(self, numeric, command, args): + pass + + def handle_svinfo(self, numeric, command, args): + pass + Class = HybridProtocol From c71010f1b020c89706436ec0c14ccc9733dc61e8 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Wed, 30 Mar 2016 11:38:03 +1000 Subject: [PATCH 10/17] hybrid: Reorder a little, send EOB right after sending SERVER --- protocols/hybrid.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index e7ad748..02ab2d2 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -98,6 +98,9 @@ class HybridProtocol(TS6BaseProtocol): f('SERVER %s 0 :%s' % (self.irc.serverdata["hostname"], self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc'])) + # send endburst now + self.irc.send(':%s EOB' % (self.irc.sid,)) + 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): @@ -260,12 +263,6 @@ class HybridProtocol(TS6BaseProtocol): self.irc.callHooks([uid, 'CLIENT_OPERED', {'text': 'IRC_Operator'}]) return {'uid': uid, 'ts': ts, 'nick': nick, 'realname': realname, 'host': host, 'ident': ident, 'ip': ip} - def handle_svstag(self, numeric, command, args): - tag = args[2] - if tag in ['313']: - return - raise Exception('COULD NOT PARSE SVSTAG: {} {} {}'.format(numeric, command, args)) - def handle_join(self, numeric, command, args): """Handles incoming channel JOINs.""" # parameters: channelTS, channel, '+' (a plus sign) @@ -352,10 +349,6 @@ class HybridProtocol(TS6BaseProtocol): log.debug('(%s) Set self.irc.lastping.', self.irc.name) self.irc.lastping = time.time() - def handle_endburst(self, numeric, command, args): - self.irc.send(':%s EOB' % (self.irc.sid,)) - pass - def handle_mode(self, numeric, command, args): # <- :0UYAAAAAD MODE 0UYAAAAAD :-i target = args[0] @@ -381,6 +374,15 @@ class HybridProtocol(TS6BaseProtocol): return {'target': channel, 'modes': changedmodes, 'ts': ts, 'oldchan': oldobj} + def handle_svstag(self, numeric, command, args): + tag = args[2] + if tag in ['313']: + return + raise Exception('COULD NOT PARSE SVSTAG: {} {} {}'.format(numeric, command, args)) + + def handle_endburst(self, numeric, command, args): + pass + # empty handlers # TODO: there's a better way to do this def handle_globops(self, numeric, command, args): From 89c88d9111da8f29ec1cf713f8d3e7251392ea8b Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Wed, 30 Mar 2016 13:40:35 +1000 Subject: [PATCH 11/17] hybrid: Use standard handle_events (with our special additions), don't lower() commands anymore since that isn't done now --- protocols/hybrid.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index 02ab2d2..5bd0921 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -167,19 +167,21 @@ class HybridProtocol(TS6BaseProtocol): """Event handler for the Hybrid protocol. This passes most commands to the various handle_ABCD() functions - elsewhere in this module, coersing various sender prefixes from nicks - to UIDs wherever possible. + elsewhere defined protocol modules, coersing various sender prefixes + from nicks and server names to UIDs and SIDs respectively, + whenever possible. + + Commands sent without an explicit sender prefix will have them set to + the SID of the uplink server. """ data = data.split(" ") - if not data: - # No data?? - return try: # Message starts with a SID/UID prefix. args = self.parseTS6Args(data) sender = args[0] command = args[1] args = args[2:] - # If the sender isn't in UID format, try to convert it automatically + # If the sender isn't in UID format, try to convert it automatically. + # Unreal's protocol, for example, isn't quite consistent with this yet! sender_server = self._getSid(sender) if sender_server in self.irc.servers: # Sender is a server when converted from name to SID. @@ -187,6 +189,7 @@ class HybridProtocol(TS6BaseProtocol): else: # Sender is a user. numeric = self._getNick(sender) + # parseTS6Args() will raise IndexError if the TS6 sender prefix is missing. except IndexError: # Raw command without an explicit sender; assume it's being sent by our uplink. @@ -194,8 +197,9 @@ class HybridProtocol(TS6BaseProtocol): numeric = self.irc.uplink command = args[0] args = args[1:] + try: - command = self.hook_map.get(command.upper(), command).lower() + command = self.hook_map.get(command.upper(), command) func = getattr(self, 'handle_'+command.lower()) except AttributeError: # unhandled command # self._send(self.irc.sid, 'ERROR', 'Unknown Command') From 177e690dd32f4900ac65d955543470bef868de22 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Wed, 30 Mar 2016 13:51:53 +1000 Subject: [PATCH 12/17] hybrid: Support TBURST --- protocols/hybrid.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index 5bd0921..4aff5e3 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -20,7 +20,7 @@ class HybridProtocol(TS6BaseProtocol): self.caps = {} - self.hook_map = {'EOB': 'ENDBURST'} + self.hook_map = {'EOB': 'ENDBURST', 'TBURST', 'TOPIC'} def connect(self): """Initializes a connection to a server.""" @@ -327,6 +327,17 @@ class HybridProtocol(TS6BaseProtocol): return {'channel': channel, 'users': uids, 'modes': self.irc.channels[channel].modes, 'ts': ts} + def handle_tburst(self, numeric, command, args): + """Handles incoming topic burst (TBURST) commands.""" + # <- :0UY TBURST 1459308205 #testchan 1459309379 dan!~d@localhost :sdf + channel = args[1].lower() + ts = args[2] + setter = args[3] + topic = args[-1] + self.irc.channels[channel].topic = topic + self.irc.channels[channel].topicset = True + return {'channel': channel, 'setter': setter, 'ts': ts, 'text': topic} + def handle_ping(self, source, command, args): """Handles incoming PING commands.""" # PING: From 4b14134a1739c5f333a70932c6eddf43dce46ef6 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Wed, 30 Mar 2016 13:59:04 +1000 Subject: [PATCH 13/17] hybrid: Fix TBURST, support WHOIS --- protocols/hybrid.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index 4aff5e3..e34a235 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -20,7 +20,7 @@ class HybridProtocol(TS6BaseProtocol): self.caps = {} - self.hook_map = {'EOB': 'ENDBURST', 'TBURST', 'TOPIC'} + self.hook_map = {'EOB': 'ENDBURST', 'TBURST': 'TOPIC'} def connect(self): """Initializes a connection to a server.""" @@ -338,6 +338,14 @@ class HybridProtocol(TS6BaseProtocol): self.irc.channels[channel].topicset = True return {'channel': channel, 'setter': setter, 'ts': ts, 'text': topic} + def handle_whois(self, numeric, command, args): + """Handles incoming WHOIS commands. + + Note: The core of WHOIS handling is done by coreplugin.py + (IRCd-independent), and not here.""" + # <- :0UYAAAAAH WHOIS 0T4AAAAAA :pylink + return {'target': args[0]} + def handle_ping(self, source, command, args): """Handles incoming PING commands.""" # PING: From 153b77c4bbeb1a3d6d43d5f927f87c86c8d3ba1f Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Wed, 30 Mar 2016 15:48:44 +1000 Subject: [PATCH 14/17] hybrid: Set irc.connected after receiving EOB --- protocols/hybrid.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index e34a235..d5173c5 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -225,7 +225,7 @@ class HybridProtocol(TS6BaseProtocol): self.irc.uplink = numeric def handle_capab(self, numeric, command, args): - # We only get a list of keywords here. Charybdis obviously assumes that + # We only get a list of keywords here. Hybrid obviously assumes that # we know what modes it supports (indeed, this is a standard list). # <- CAPAB :BAN CHW CLUSTER ENCAP EOPMOD EUID EX IE KLN KNOCK MLOCK QS RSFNC SAVE SERVICES TB UNKLN self.irc.caps = caps = args[0].split() @@ -233,9 +233,6 @@ class HybridProtocol(TS6BaseProtocol): # if required_cap not in caps: # raise ProtocolError('%s not found in TS6 capabilities list; this is required! (got %r)' % (required_cap, caps)) - log.debug('(%s) self.irc.connected set!', self.irc.name) - self.irc.connected.set() - def handle_server(self, numeric, command, args): # <- SERVER charybdis.midnight.vpn 1 :charybdis test server sname = args[0].lower() @@ -404,7 +401,9 @@ class HybridProtocol(TS6BaseProtocol): raise Exception('COULD NOT PARSE SVSTAG: {} {} {}'.format(numeric, command, args)) def handle_endburst(self, numeric, command, args): - pass + log.debug('(%s) end of burst received', self.irc.name) + log.debug('(%s) self.irc.connected set!', self.irc.name) + self.irc.connected.set() # empty handlers # TODO: there's a better way to do this From 9d40efc114deee49d232be5925c8e23cda4394bb Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Wed, 30 Mar 2016 16:25:03 +1000 Subject: [PATCH 15/17] hybrid: Steal some more handlers from TS6/Unreal protocols --- protocols/hybrid.py | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index d5173c5..bcb3b24 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -155,6 +155,42 @@ class HybridProtocol(TS6BaseProtocol): self.irc.channels[channel].users.add(client) self.irc.users[client].channels.add(channel) + def invite(self, numeric, target, channel): + """Sends an INVITE from a PyLink client..""" + if not self.irc.isInternalClient(numeric): + raise LookupError('No such PyLink client exists.') + self._send(numeric, 'INVITE %s %s %d' % (target, channel, int(time.time()))) + + def mode(self, numeric, target, modes, ts=None): + """Sends mode changes from a PyLink client/server.""" + # c <- :0UYAAAAAA TMODE 0 #a +o 0T4AAAAAC + # u <- :0UYAAAAAA MODE 0UYAAAAAA :-Facdefklnou + + if (not self.irc.isInternalClient(numeric)) and \ + (not self.irc.isInternalServer(numeric)): + raise LookupError('No such PyLink client/server exists.') + + utils.applyModes(self.irc, target, modes) + modes = list(modes) + + if utils.isChannel(target): + ts = ts or self.irc.channels[utils.toLower(self.irc, target)].ts + # TMODE: + # parameters: channelTS, channel, cmode changes, opt. cmode parameters... + + # On output, at most ten cmode parameters should be sent; if there are more, + # multiple TMODE messages should be sent. + # TODO(dan): this may not be required on Hybrid? + while modes[:9]: + # Seriously, though. If you send more than 10 mode parameters in + # a line, charybdis will silently REJECT the entire command! + joinedmodes = utils.joinModes(modes = [m for m in modes[:9] if m[0] not in self.irc.cmodes['*A']]) + modes = modes[9:] + self._send(numeric, 'TMODE %s %s %s' % (ts, target, joinedmodes)) + else: + joinedmodes = utils.joinModes(modes) + self._send(numeric, 'MODE %s %s' % (target, joinedmodes)) + def ping(self, source=None, target=None): """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.""" @@ -394,6 +430,18 @@ class HybridProtocol(TS6BaseProtocol): return {'target': channel, 'modes': changedmodes, 'ts': ts, 'oldchan': oldobj} + def handle_invite(self, numeric, command, args): + """Handles incoming INVITEs.""" + # <- :0UYAAAAAA INVITE 0T4AAAAAA #testchan 1459316899 + target = args[0] + channel = args[1].lower() + try: + ts = args[3] + except IndexError: + ts = int(time.time()) + # We don't actually need to process this; it's just something plugins/hooks can use + return {'target': target, 'channel': channel, 'ts': ts} + def handle_svstag(self, numeric, command, args): tag = args[2] if tag in ['313']: From 80b659a940110889105ca0f0212b4985d1d5f837 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Wed, 30 Mar 2016 17:24:26 +1000 Subject: [PATCH 16/17] hybrid: Actually set irc.connected on CAPAB, like other protocols --- protocols/hybrid.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index bcb3b24..89f6417 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -269,6 +269,9 @@ class HybridProtocol(TS6BaseProtocol): # if required_cap not in caps: # raise ProtocolError('%s not found in TS6 capabilities list; this is required! (got %r)' % (required_cap, caps)) + log.debug('(%s) self.irc.connected set!', self.irc.name) + self.irc.connected.set() + def handle_server(self, numeric, command, args): # <- SERVER charybdis.midnight.vpn 1 :charybdis test server sname = args[0].lower() @@ -450,8 +453,6 @@ class HybridProtocol(TS6BaseProtocol): def handle_endburst(self, numeric, command, args): log.debug('(%s) end of burst received', self.irc.name) - log.debug('(%s) self.irc.connected set!', self.irc.name) - self.irc.connected.set() # empty handlers # TODO: there's a better way to do this From 59809e1530c8331a008eb6db55202c7f2f782da8 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Thu, 7 Apr 2016 22:29:15 +1000 Subject: [PATCH 17/17] hybrid: Dispatch ENDBURST so it can be caught by plugins --- protocols/hybrid.py | 1 + 1 file changed, 1 insertion(+) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index 89f6417..c9a4766 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -453,6 +453,7 @@ class HybridProtocol(TS6BaseProtocol): def handle_endburst(self, numeric, command, args): log.debug('(%s) end of burst received', self.irc.name) + return {} # empty handlers # TODO: there's a better way to do this