New configuration setting: conf.max_server_conns.
Limit is ignored if there is a WEBIRC password set for the server or if the server is running
in restricted mode.
// Max connections per connection. 0 to disable
conf.max_client_conns = 5;
+// Max connections per server. 0 to disable.
+// Setting is ignored if there is a WEBIRC password configured for the server or kiwi is running in restricted server mode.
+conf.max_server_conns = 0;
+
/*
* Client side plugins
if (irc_connection) {
irc_connection.end('QUIT :' + (global.config.quit_message || ''));
irc_connection.dispose();
+ global.servers.removeConnection(irc_connection);
cons[i] = null;
}
});
this);
} else {
+ if ((global.config.max_server_conns > 0) && (!(global.config.webirc_pass && global.config.webirc_passs[hostname]))) {
+ if (global.servers.numOnHost(hostname) >= global.config.max_server_conns) {
+ return callback('Too many connections to host', {host: hostname, limit: global.config.max_server_conns});
+ }
+ }
con = new IrcConnection(
hostname,
port,
new IrcCommands(con, con_num, this).bindEvents();
con.on('connected', function () {
+ global.servers.addConnection(this);
return callback(null, con_num);
});
con.on('close', function () {
that.irc_connections[con_num] = null;
+ global.servers.removeConnection(this);
});
};
}
};
+global.servers = {
+ servers: Object.create(null),
+
+ addConnection: function (connection) {
+ var host = connection.irc_host.hostname;
+ if (!this.servers[host]) {
+ this.servers[host] = [];
+ }
+ this.servers[host].push(connection);
+ },
+
+ removeConnection: function (connection) {
+ var host = connection.irc_host.hostname
+ if (this.servers[host]) {
+ this.servers[host] = _.without(this.servers[host], connection);
+ if (this.servers[host].length === 0) {
+ delete this.servers[host];
+ }
+ }
+ },
+
+ numOnHost: function (host) {
+ if (this.servers[host]) {
+ return this.servers[host].length;
+ } else {
+ return 0;
+ }
+ }
+};
+