From 194a62fceac3b3e03d9e4f5844e2b5974577fb76 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 17 Dec 2016 23:46:30 -0800 Subject: [PATCH] protocols: implement basic nick collision detection in UID handlers Closes #285. Closes #375. --- protocols/hybrid.py | 1 + protocols/inspircd.py | 1 + protocols/ircs2s_common.py | 12 ++++++++++++ protocols/nefarious.py | 1 + protocols/ts6.py | 1 + protocols/unreal.py | 1 + 6 files changed, 17 insertions(+) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index fe19d8a..065c80a 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -171,6 +171,7 @@ class HybridProtocol(TS6Protocol): """ # <- :0UY UID dan 1 1451041551 +Facdeiklosuw ~ident localhost 127.0.0.1 0UYAAAAAB * :realname nick = args[0] + self.checkCollision(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 fa53f4a..0eeb004 100644 --- a/protocols/inspircd.py +++ b/protocols/inspircd.py @@ -562,6 +562,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) realname = args[-1] self.irc.users[uid] = userobj = IrcUser(nick, ts, uid, ident, host, realname, realhost, ip) diff --git a/protocols/ircs2s_common.py b/protocols/ircs2s_common.py index c0e92ba..c8542fb 100644 --- a/protocols/ircs2s_common.py +++ b/protocols/ircs2s_common.py @@ -7,6 +7,18 @@ from pylinkirc.log import log class IRCS2SProtocol(Protocol): + def checkCollision(self, nick): + """ + Nick collision checker. + """ + uid = self.irc.nickToUid(nick) + # If there is a nick collision, we simply alert plugins. Relay will purposely try to + # lose fights and tag nicks instead, while other plugins can choose how to handle this. + if uid: + log.info('(%s) Nick collision on %s/%s, forwarding this to plugins', self.irc.name, + uid, nick) + self.irc.callHooks([self.irc.sid, 'SAVE', {'target': uid}]) + def handle_kill(self, source, command, args): """Handles incoming KILLs.""" killed = args[0] diff --git a/protocols/nefarious.py b/protocols/nefarious.py index 5e18f9a..235777a 100644 --- a/protocols/nefarious.py +++ b/protocols/nefarious.py @@ -827,6 +827,7 @@ class P10Protocol(IRCS2SProtocol): # <- AB N GL 1 1460673049 ~gl nefarious.midnight.vpn +iw B]AAAB ABAAA :realname nick = args[0] + self.checkCollision(nick) ts, ident, host = args[2:5] realhost = host ip = args[-3] diff --git a/protocols/ts6.py b/protocols/ts6.py index 036c8ef..4f0b2fb 100644 --- a/protocols/ts6.py +++ b/protocols/ts6.py @@ -499,6 +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) 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 a8fb35a..9b670df 100644 --- a/protocols/unreal.py +++ b/protocols/unreal.py @@ -338,6 +338,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) ts, ident, realhost, uid, accountname, modestring, host = args[2:9] if host == '*':