diff --git a/config.js b/config.js index 4f1abb47..23959838 100644 --- a/config.js +++ b/config.js @@ -26,6 +26,14 @@ module.exports = { // port: 9000, + // + // Set the local IP to bind to. + // + // @type string + // @default "0.0.0.0" + // + bind: undefined, + // // Set the default theme. // diff --git a/src/client.js b/src/client.js index 55ef0996..fb6b9c0d 100644 --- a/src/client.js +++ b/src/client.js @@ -116,6 +116,7 @@ Client.prototype.find = function(id) { }; Client.prototype.connect = function(args) { + var config = Helper.getConfig(); var client = this; var server = { host: args.host || "irc.freenode.org", @@ -124,7 +125,17 @@ Client.prototype.connect = function(args) { rejectUnauthorized: false }; + if(config.bind) { + server.localAddress = config.bind; + + if(args.tls) { + var socket = net.connect(server); + server.socket = socket; + } + } + var stream = args.tls ? tls.connect(server) : net.connect(server); + stream.on("error", function(e) { console.log("Client#connect():\n" + e); stream.end(); diff --git a/src/command-line/start.js b/src/command-line/start.js index 8f5d9b92..2c73810b 100644 --- a/src/command-line/start.js +++ b/src/command-line/start.js @@ -6,6 +6,7 @@ var Helper = require("../helper"); program .option("-H, --host ", "host") .option("-p, --port ", "port") + .option("-B, --bind ", "bind") .option(" --public", "mode") .option(" --private", "mode") .command("start") @@ -27,6 +28,7 @@ program } else { var host = program.host || process.env.IP || config.host; var port = program.port || process.env.PORT || config.port; - shout(port, host, mode); + var bind = program.bind || process.env.BIND || config.bind; + shout(port, host, mode, bind); } }); diff --git a/src/server.js b/src/server.js index 1292a21c..b2711122 100644 --- a/src/server.js +++ b/src/server.js @@ -11,11 +11,12 @@ var config = {}; var sockets = null; var manager = new ClientManager(); -module.exports = function(port, host, isPublic) { +module.exports = function(port, host, isPublic, localIp) { config = Helper.getConfig(); config.port = port; config.host = host; config.public = isPublic; + config.bind = localIp; var app = express() .use(index)