From c898da7378d251a32faf5c413629a9e784a5bf04 Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 9 May 2017 19:57:03 -0700 Subject: [PATCH 1/3] p10: move command tokens dict into a class variable & drop _getCommand() --- protocols/p10.py | 188 +++++++++++++++++++++++------------------------ 1 file changed, 90 insertions(+), 98 deletions(-) diff --git a/protocols/p10.py b/protocols/p10.py index 62a71b5..64d0c38 100644 --- a/protocols/p10.py +++ b/protocols/p10.py @@ -63,6 +63,93 @@ class P10SIDGenerator(): return sid class P10Protocol(IRCS2SProtocol): + COMMAND_TOKENS = { + 'AC': 'ACCOUNT', + 'AD': 'ADMIN', + 'LL': 'ASLL', + 'A': 'AWAY', + 'B': 'BURST', + 'CAP': 'CAP', + 'CM': 'CLEARMODE', + 'CLOSE': 'CLOSE', + 'CN': 'CNOTICE', + 'CO': 'CONNECT', + 'CP': 'CPRIVMSG', + 'C': 'CREATE', + 'DE': 'DESTRUCT', + 'DS': 'DESYNCH', + 'DIE': 'DIE', + 'DNS': 'DNS', + 'EB': 'END_OF_BURST', + 'EA': 'EOB_ACK', + 'Y': 'ERROR', + 'GET': 'GET', + 'GL': 'GLINE', + 'HASH': 'HASH', + 'HELP': 'HELP', + 'F': 'INFO', + 'I': 'INVITE', + 'ISON': 'ISON', + 'J': 'JOIN', + 'JU': 'JUPE', + 'K': 'KICK', + 'D': 'KILL', + 'LI': 'LINKS', + 'LIST': 'LIST', + 'LU': 'LUSERS', + 'MAP': 'MAP', + 'M': 'MODE', + 'MO': 'MOTD', + 'E': 'NAMES', + 'N': 'NICK', + 'O': 'NOTICE', + 'OPER': 'OPER', + 'OM': 'OPMODE', + 'L': 'PART', + 'PA': 'PASS', + 'G': 'PING', + 'Z': 'PONG', + 'POST': 'POST', + 'P': 'PRIVMSG', + 'PRIVS': 'PRIVS', + 'PROTO': 'PROTO', + 'Q': 'QUIT', + 'REHASH': 'REHASH', + 'RESET': 'RESET', + 'RESTART': 'RESTART', + 'RI': 'RPING', + 'RO': 'RPONG', + 'S': 'SERVER', + 'SERVSET': 'SERVLIST', + 'SERVSET': 'SERVSET', + 'SET': 'SET', + 'SE': 'SETTIME', + 'U': 'SILENCE', + 'SQUERY': 'SQUERY', + 'SQ': 'SQUIT', + 'R': 'STATS', + 'TI': 'TIME', + 'T': 'TOPIC', + 'TR': 'TRACE', + 'UP': 'UPING', + 'USER': 'USER', + 'USERHOST': 'USERHOST', + 'USERIP': 'USERIP', + 'V': 'VERSION', + 'WC': 'WALLCHOPS', + 'WA': 'WALLOPS', + 'WU': 'WALLUSERS', + 'WV': 'WALLVOICES', + 'H': 'WHO', + 'W': 'WHOIS', + 'X': 'WHOWAS', + 'XQ': 'XQUERY', + 'XR': 'XREPLY', + 'SN': 'SVSNICK', + 'SJ': 'SVSJOIN', + 'SH': 'SETHOST', + 'FA': 'FAKE' + } def __init__(self, irc): super().__init__(irc) @@ -151,99 +238,6 @@ class P10Protocol(IRCS2SProtocol): ip = '0' + ip return ip - @staticmethod - def _getCommand(token): - """Returns the command name for the given token.""" - tokens = { - 'AC': 'ACCOUNT', - 'AD': 'ADMIN', - 'LL': 'ASLL', - 'A': 'AWAY', - 'B': 'BURST', - 'CAP': 'CAP', - 'CM': 'CLEARMODE', - 'CLOSE': 'CLOSE', - 'CN': 'CNOTICE', - 'CO': 'CONNECT', - 'CP': 'CPRIVMSG', - 'C': 'CREATE', - 'DE': 'DESTRUCT', - 'DS': 'DESYNCH', - 'DIE': 'DIE', - 'DNS': 'DNS', - 'EB': 'END_OF_BURST', - 'EA': 'EOB_ACK', - 'Y': 'ERROR', - 'GET': 'GET', - 'GL': 'GLINE', - 'HASH': 'HASH', - 'HELP': 'HELP', - 'F': 'INFO', - 'I': 'INVITE', - 'ISON': 'ISON', - 'J': 'JOIN', - 'JU': 'JUPE', - 'K': 'KICK', - 'D': 'KILL', - 'LI': 'LINKS', - 'LIST': 'LIST', - 'LU': 'LUSERS', - 'MAP': 'MAP', - 'M': 'MODE', - 'MO': 'MOTD', - 'E': 'NAMES', - 'N': 'NICK', - 'O': 'NOTICE', - 'OPER': 'OPER', - 'OM': 'OPMODE', - 'L': 'PART', - 'PA': 'PASS', - 'G': 'PING', - 'Z': 'PONG', - 'POST': 'POST', - 'P': 'PRIVMSG', - 'PRIVS': 'PRIVS', - 'PROTO': 'PROTO', - 'Q': 'QUIT', - 'REHASH': 'REHASH', - 'RESET': 'RESET', - 'RESTART': 'RESTART', - 'RI': 'RPING', - 'RO': 'RPONG', - 'S': 'SERVER', - 'SERVSET': 'SERVLIST', - 'SERVSET': 'SERVSET', - 'SET': 'SET', - 'SE': 'SETTIME', - 'U': 'SILENCE', - 'SQUERY': 'SQUERY', - 'SQ': 'SQUIT', - 'R': 'STATS', - 'TI': 'TIME', - 'T': 'TOPIC', - 'TR': 'TRACE', - 'UP': 'UPING', - 'USER': 'USER', - 'USERHOST': 'USERHOST', - 'USERIP': 'USERIP', - 'V': 'VERSION', - 'WC': 'WALLCHOPS', - 'WA': 'WALLOPS', - 'WU': 'WALLUSERS', - 'WV': 'WALLVOICES', - 'H': 'WHO', - 'W': 'WHOIS', - 'X': 'WHOWAS', - 'XQ': 'XQUERY', - 'XR': 'XREPLY', - 'SN': 'SVSNICK', - 'SJ': 'SVSJOIN', - 'SH': 'SETHOST', - 'FA': 'FAKE' - } - # If the token isn't in the list, return it raw. - return tokens.get(token, token) - ### COMMANDS def spawnClient(self, nick, ident='null', host='null', realhost=None, modes=set(), @@ -869,14 +863,12 @@ class P10Protocol(IRCS2SProtocol): args = args[2:] log.debug('(%s) Found message sender as %s', self.irc.name, sender) + # Convert the token given into a regular command, if present. + command = self.COMMAND_TOKENS.get(command_token, command_token) + log.debug('(%s) Translating token %s to command %s', self.irc.name, command_token, command) try: - # Convert the token given into a regular command, if present. - command = self._getCommand(command_token) - log.debug('(%s) Translating token %s to command %s', self.irc.name, command_token, command) - func = getattr(self, 'handle_'+command.lower()) - except AttributeError: # Unhandled command, ignore return From 8f14cb238b4a9e0d6447bb36605cf1eac46979e6 Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 9 May 2017 20:17:28 -0700 Subject: [PATCH 2/3] p10: rename checkCloakChange -> check_cloak_change (consistency) (#454) --- protocols/p10.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/protocols/p10.py b/protocols/p10.py index 64d0c38..4163303 100644 --- a/protocols/p10.py +++ b/protocols/p10.py @@ -749,8 +749,8 @@ class P10Protocol(IRCS2SProtocol): # P10 cloaks aren't as simple as just replacing the displayed host with the one we're # sending. Check for cloak changes properly. - # Note: we don't need to send any hooks here, checkCloakChange does that for us. - self.checkCloakChange(target) + # Note: we don't need to send any hooks here, check_cloak_change does that for us. + self.check_cloak_change(target) ### HANDLERS @@ -935,7 +935,7 @@ class P10Protocol(IRCS2SProtocol): if ('+o', None) in parsedmodes: self.irc.callHooks([uid, 'CLIENT_OPERED', {'text': 'IRC Operator'}]) - self.checkCloakChange(uid) + self.check_cloak_change(uid) return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip} @@ -949,13 +949,13 @@ class P10Protocol(IRCS2SProtocol): # Update the nick TS. return {'newnick': newnick, 'oldnick': oldnick, 'ts': ts} - def checkCloakChange(self, uid): + def check_cloak_change(self, uid): """Checks for cloak changes (ident and host) on the given UID.""" uobj = self.irc.users[uid] ident = uobj.ident modes = dict(uobj.modes) - log.debug('(%s) checkCloakChange: modes of %s are %s', self.irc.name, uid, modes) + log.debug('(%s) check_cloak_change: modes of %s are %s', self.irc.name, uid, modes) if 'x' not in modes: # +x isn't set, so cloaking is disabled. newhost = uobj.realhost @@ -1211,7 +1211,7 @@ class P10Protocol(IRCS2SProtocol): if target in self.irc.users: # Target was a user. Check for any cloak changes. - self.checkCloakChange(target) + self.check_cloak_change(target) return {'target': target, 'modes': changedmodes} # OPMODE is like SAMODE on other IRCds, and it follows the same modesetting syntax. @@ -1345,7 +1345,7 @@ class P10Protocol(IRCS2SProtocol): self.irc.callHooks([target, 'CLIENT_SERVICES_LOGIN', {'text': accountname}]) # Check for any cloak changes now. - self.checkCloakChange(target) + self.check_cloak_change(target) def handle_fake(self, numeric, command, args): """Handles incoming FAKE hostmask changes.""" @@ -1355,8 +1355,8 @@ class P10Protocol(IRCS2SProtocol): # Assume a usermode +f change, and then update the cloak checking. self.irc.applyModes(target, [('+f', text)]) - self.checkCloakChange(target) - # We don't need to send any hooks here, checkCloakChange does that for us. + self.check_cloak_change(target) + # We don't need to send any hooks here, check_cloak_change does that for us. def handle_svsnick(self, source, command, args): """Handles SVSNICK (forced nickname change attempts).""" From 08c00824305c3048ee414c4be2b7e8989cd7c8fa Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 9 May 2017 20:27:19 -0700 Subject: [PATCH 3/3] protocols: rename checkCollision -> check_nick_collision() (#454) --- protocols/hybrid.py | 2 +- protocols/inspircd.py | 2 +- protocols/ircs2s_common.py | 2 +- protocols/p10.py | 2 +- protocols/ts6.py | 2 +- protocols/unreal.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index 829e0fb..e22e85e 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -169,7 +169,7 @@ class HybridProtocol(TS6Protocol): """ # <- :0UY UID dan 1 1451041551 +Facdeiklosuw ~ident localhost 127.0.0.1 0UYAAAAAB * :realname nick = args[0] - self.checkCollision(nick) + self.check_nick_collision(nick) ts, modes, ident, host, ip, uid, account, realname = args[2:10] if account == '*': account = None diff --git a/protocols/inspircd.py b/protocols/inspircd.py index f6331e4..2525c56 100644 --- a/protocols/inspircd.py +++ b/protocols/inspircd.py @@ -575,7 +575,7 @@ class InspIRCdProtocol(TS6BaseProtocol): """Handles incoming UID commands (user introduction).""" # :70M UID 70MAAAAAB 1429934638 GL 0::1 hidden-7j810p.9mdf.lrek.0000.0000.IP gl 0::1 1429934638 +Wioswx +ACGKNOQXacfgklnoqvx :realname uid, ts, nick, realhost, host, ident, ip = args[0:7] - self.checkCollision(nick) + self.check_nick_collision(nick) realname = args[-1] self.irc.users[uid] = userobj = IrcUser(nick, ts, uid, numeric, ident, host, realname, realhost, ip) diff --git a/protocols/ircs2s_common.py b/protocols/ircs2s_common.py index 378a772..16edb50 100644 --- a/protocols/ircs2s_common.py +++ b/protocols/ircs2s_common.py @@ -14,7 +14,7 @@ class IRCS2SProtocol(Protocol): self.protocol_caps = {'can-spawn-clients', 'has-ts', 'can-host-relay', 'can-track-servers'} - def checkCollision(self, nick): + def check_nick_collision(self, nick): """ Nick collision checker. """ diff --git a/protocols/p10.py b/protocols/p10.py index 4163303..b9139c4 100644 --- a/protocols/p10.py +++ b/protocols/p10.py @@ -901,7 +901,7 @@ class P10Protocol(IRCS2SProtocol): # <- AB N GL 1 1460673049 ~gl nefarious.midnight.vpn +iw B]AAAB ABAAA :realname nick = args[0] - self.checkCollision(nick) + self.check_nick_collision(nick) ts, ident, host = args[2:5] realhost = host ip = args[-3] diff --git a/protocols/ts6.py b/protocols/ts6.py index 32fd783..8249e28 100644 --- a/protocols/ts6.py +++ b/protocols/ts6.py @@ -499,7 +499,7 @@ class TS6Protocol(TS6BaseProtocol): """Handles incoming EUID commands (user introduction).""" # <- :42X EUID GL 1 1437505322 +ailoswz ~gl 127.0.0.1 127.0.0.1 42XAAAAAB * * :realname nick = args[0] - self.checkCollision(nick) + self.check_nick_collision(nick) ts, modes, ident, host, ip, uid, realhost, accountname, realname = args[2:11] if realhost == '*': realhost = None diff --git a/protocols/unreal.py b/protocols/unreal.py index e576c3d..fbdba61 100644 --- a/protocols/unreal.py +++ b/protocols/unreal.py @@ -390,7 +390,7 @@ class UnrealProtocol(TS6BaseProtocol): # arguments: nick, hopcount?, ts, ident, real-host, UID, services account (0 if none), modes, # displayed host, cloaked (+x) host, base64-encoded IP, and realname nick = args[0] - self.checkCollision(nick) + self.check_nick_collision(nick) ts, ident, realhost, uid, accountname, modestring, host = args[2:9] if host == '*':