Allow binding to a local IP

This commit is contained in:
XeonCore 2014-10-11 17:17:41 +11:00
parent 9eff230463
commit dbd423e5a1
4 changed files with 24 additions and 2 deletions

View File

@ -26,6 +26,14 @@ module.exports = {
// //
port: 9000, port: 9000,
//
// Set the local IP to bind to.
//
// @type string
// @default "0.0.0.0"
//
bind: undefined,
// //
// Set the default theme. // Set the default theme.
// //

View File

@ -116,6 +116,7 @@ Client.prototype.find = function(id) {
}; };
Client.prototype.connect = function(args) { Client.prototype.connect = function(args) {
var config = Helper.getConfig();
var client = this; var client = this;
var server = { var server = {
host: args.host || "irc.freenode.org", host: args.host || "irc.freenode.org",
@ -124,7 +125,17 @@ Client.prototype.connect = function(args) {
rejectUnauthorized: false 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); var stream = args.tls ? tls.connect(server) : net.connect(server);
stream.on("error", function(e) { stream.on("error", function(e) {
console.log("Client#connect():\n" + e); console.log("Client#connect():\n" + e);
stream.end(); stream.end();

View File

@ -6,6 +6,7 @@ var Helper = require("../helper");
program program
.option("-H, --host <ip>", "host") .option("-H, --host <ip>", "host")
.option("-p, --port <port>", "port") .option("-p, --port <port>", "port")
.option("-B, --bind <ip>", "bind")
.option(" --public", "mode") .option(" --public", "mode")
.option(" --private", "mode") .option(" --private", "mode")
.command("start") .command("start")
@ -27,6 +28,7 @@ program
} else { } else {
var host = program.host || process.env.IP || config.host; var host = program.host || process.env.IP || config.host;
var port = program.port || process.env.PORT || config.port; 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);
} }
}); });

View File

@ -11,11 +11,12 @@ var config = {};
var sockets = null; var sockets = null;
var manager = new ClientManager(); var manager = new ClientManager();
module.exports = function(port, host, isPublic) { module.exports = function(port, host, isPublic, localIp) {
config = Helper.getConfig(); config = Helper.getConfig();
config.port = port; config.port = port;
config.host = host; config.host = host;
config.public = isPublic; config.public = isPublic;
config.bind = localIp;
var app = express() var app = express()
.use(index) .use(index)