From 3b948583c366430c32ff29fba94fd71dcac6e5c9 Mon Sep 17 00:00:00 2001 From: Darren Date: Sun, 27 Jul 2014 00:59:37 +0100 Subject: [PATCH] IRCd reconnection only when registered for 10+ secs Some networks may /kill a user after connected with a custom banning system, causing an ever lasting reconnection loop --- server/irc/commands/registration.js | 1 - server/irc/connection.js | 7 ++----- server/irc/server.js | 3 ++- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/server/irc/commands/registration.js b/server/irc/commands/registration.js index a19d87a..4b58c40 100644 --- a/server/irc/commands/registration.js +++ b/server/irc/commands/registration.js @@ -10,7 +10,6 @@ module.exports = function AddCommandHandlers(command_controller) { var handlers = { RPL_WELCOME: function (command) { var nick = command.params[0]; - this.irc_connection.registered = true; this.cap_negotiation = false; this.emit('server ' + this.irc_connection.irc_host.hostname + ' connect', { nick: nick diff --git a/server/irc/connection.js b/server/irc/connection.js index 97cf272..8b8e197 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -52,9 +52,6 @@ var IrcConnection = function (hostname, port, ssl, nick, user, options, state, c // Max number of lines to write a second this.write_buffer_lines_second = 2; - // If registeration with the IRCd has completed - this.registered = false; - // If we are in the CAP negotiation stage this.cap_negotiation = true; @@ -300,7 +297,7 @@ IrcConnection.prototype.connect = function () { that.socket.on('close', function socketCloseCb(had_error) { // If that.connected is false, we never actually managed to connect var was_connected = that.connected, - had_registered = that.server.registered, + safely_registered = (new Date()) - that.server.registered > 10000, // Safely = registered + 10secs after. should_reconnect = false; that.connected = false; @@ -316,7 +313,7 @@ IrcConnection.prototype.connect = function () { should_reconnect = true; // If this was an unplanned disconnect and we were originally connected OK, reconnect - } else if (!that.requested_disconnect && was_connected && had_registered) { + } else if (!that.requested_disconnect && was_connected && safely_registered) { should_reconnect = true; } else { diff --git a/server/irc/server.js b/server/irc/server.js index 2dec789..831e9bf 100755 --- a/server/irc/server.js +++ b/server/irc/server.js @@ -8,6 +8,7 @@ var IrcServer = function (irc_connection) { this.list_buffer = []; this.motd_buffer = ''; + // Date when registeration with the IRCd had completed this.registered = false; this.irc_events = { @@ -60,7 +61,7 @@ IrcServer.prototype.reset = function() { function onConnect(event) { - this.registered = true; + this.registered = new Date(); this.irc_connection.clientEvent('connect', { nick: event.nick -- 2.25.1