Fix existing identd

This commit is contained in:
Maxime Poulin 2016-04-26 16:40:27 -04:00
parent 2e967e8375
commit 9aafffd273
No known key found for this signature in database
GPG key ID: CB63C36252F40D4B
2 changed files with 17 additions and 10 deletions

View file

@ -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);

View file

@ -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({