From 9aafffd273a8839e27868859433054619125e68d Mon Sep 17 00:00:00 2001 From: Maxime Poulin Date: Tue, 26 Apr 2016 16:40:27 -0400 Subject: [PATCH] Fix existing identd --- src/identd.js | 17 +++++++++++------ src/plugins/irc-events/connection.js | 10 ++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/identd.js b/src/identd.js index 3d626dad..f598052a 100644 --- a/src/identd.js +++ b/src/identd.js @@ -2,26 +2,31 @@ var _ = require("lodash"); var net = require("net"); var users = {}; +var enabled = false; module.exports.start = function(port) { port = port || 113; log.info("Starting identd server on port", port); net.createServer(init).listen(port); + enabled = true; }; module.exports.hook = function(stream, user) { - var id = ""; var socket = stream.socket || stream; - socket.on("connect", function() { - var ports = _.pick(socket, "localPort", "remotePort"); - id = _.values(ports).join(", "); - users[id] = user; - }); + var ports = _.pick(socket, "localPort", "remotePort"); + var id = _.values(ports).join(", "); + + users[id] = user; + socket.on("close", function() { delete users[id]; }); }; +module.exports.isEnabled = function() { + return enabled; +}; + function init(socket) { socket.on("data", function(data) { respond(socket, data); diff --git a/src/plugins/irc-events/connection.js b/src/plugins/irc-events/connection.js index 597e1db3..a4226693 100644 --- a/src/plugins/irc-events/connection.js +++ b/src/plugins/irc-events/connection.js @@ -9,10 +9,6 @@ module.exports = function(irc, network) { text: "Network created, connecting to " + network.host + ":" + network.port + "..." })); - irc.on("raw socket connected", function() { - identd.hook(irc.connection.socket, network.username); - }); - irc.on("socket connected", function() { network.channels[0].pushMessage(client, new Msg({ text: "Connected to the network." @@ -25,6 +21,12 @@ module.exports = function(irc, network) { })); }); + if (identd.isEnabled()) { + irc.on("socket connected", function() { + identd.hook(irc.connection.socket, client.name || network.username); + }); + } + irc.on("socket error", function(err) { log.debug("IRC socket error", err); network.channels[0].pushMessage(client, new Msg({