From b681a675eb0da2eb47379a26aa1439631399a5dd Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 25 Jul 2015 11:00:55 -0700 Subject: [PATCH] relay: only join users once, returning if there are no queued users at all Closes #71, prevents op floods on multiple SJOIN being sent. Also, this squashes AssertionErrors raised by protocol modules in sjoinServer, when we try to join zero users to a channel! --- plugins/relay.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/plugins/relay.py b/plugins/relay.py index 07eaaf9..8201048 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -663,13 +663,19 @@ def relayJoins(irc, channel, users, ts, modes): log.debug('Okay, spawning %s/%s everywhere', user, irc.name) assert user in irc.users, "(%s) How is this possible? %r isn't in our user database." % (irc.name, user) u = getRemoteUser(irc, remoteirc, user) - ts = irc.channels[channel].ts - # TODO: join users in batches with SJOIN, not one by one. - prefixes = getPrefixModes(irc, remoteirc, channel, user) - userpair = (prefixes, u) - queued_users.append(userpair) - log.debug('(%s) relayJoins: joining %s to %s%s', irc.name, userpair, remoteirc.name, remotechan) - remoteirc.proto.sjoinServer(remoteirc, remoteirc.sid, remotechan, queued_users, ts=ts) + # Only join users if they aren't already joined. This prevents op floods + # on charybdis from all the SJOINing. + if u not in remoteirc.channels[channel].users: + ts = irc.channels[channel].ts + prefixes = getPrefixModes(irc, remoteirc, channel, user) + userpair = (prefixes, u) + queued_users.append(userpair) + log.debug('(%s) relayJoins: joining %s to %s%s', irc.name, userpair, remoteirc.name, remotechan) + else: + log.debug('(%s) relayJoins: not joining %s to %s%s; they\'re already there!', irc.name, + u, remoteirc.name, remotechan) + if queued_users: + remoteirc.proto.sjoinServer(remoteirc, remoteirc.sid, remotechan, queued_users, ts=ts) relayModes(irc, remoteirc, irc.sid, channel, modes) def relayPart(irc, channel, user):