From d62bbe08fe2a45aae6324102efe2fb8c5f237969 Mon Sep 17 00:00:00 2001 From: Jack Allnutt Date: Wed, 16 Nov 2011 14:42:38 +0000 Subject: [PATCH] Fixed kiwi not disconnecting from the IRC server when the websocket connection disconnected --- server/app.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/app.js b/server/app.js index ea1c1ff..d6a6b7c 100644 --- a/server/app.js +++ b/server/app.js @@ -907,6 +907,7 @@ this.IRCConnection = function (websocket, nick, host, port, ssl, password, callb websocket.sendServerLine('NICK ' + nick); websocket.sendServerLine('USER kiwi_' + nick.replace(/[^0-9a-zA-Z\-_.]/, '') + ' 0 0 :' + nick); + that.connected = true; that.emit('connect'); }); }; @@ -930,7 +931,9 @@ this.IRCConnection = function (websocket, nick, host, port, ssl, password, callb }); ircSocket.on('error', function (e) { + that.connected = false; that.emit('error', e); + that.destroySoon(); }); if (typeof callback === 'function') { @@ -986,15 +989,18 @@ this.IRCConnection = function (websocket, nick, host, port, ssl, password, callb } ircSocket.on('end', function () { + that.connected = false; that.emit('disconnect', false); }); ircSocket.on('close', function (had_error) { + that.connected = false; that.emit('disconnect', had_error); }); ircSocket.on('timeout', function () { ircSocket.destroy(); + that.connected = false; that.emit('error', {message: 'Connection timed out'}); }); @@ -1003,6 +1009,7 @@ this.IRCConnection = function (websocket, nick, host, port, ssl, password, callb }; this.end = function (data, encoding, callback) { + that.connected = false; ircSocket.end(data, encoding, callback); }; @@ -1131,11 +1138,11 @@ this.websocketMessage = function (websocket, msg, callback) { this.websocketDisconnect = function (websocket) { var con; - if ((!websocket.sentQUIT) && (websocket.ircSocket)) { + if ((!websocket.sentQUIT) && (websocket.ircConnection.connected)) { try { - websocket.ircSocket.end('QUIT :' + kiwi.config.quit_message + '\r\n'); + websocket.ircConnection.end('QUIT :' + kiwi.config.quit_message + '\r\n'); websocket.sentQUIT = true; - websocket.ircSocket.destroySoon(); + websocket.ircConnection.destroySoon(); } catch (e) { } } -- 2.25.1