+ },
+
+ broadcastKiwiCommand: function (command, data, callback) {
+ var clients = [];
+
+ // Get an array of clients for us to work with
+ for (var client in global.clients.clients) {
+ clients.push(global.clients.clients[client]);
+ }
+
+
+ // Sending of the command in batches
+ var sendCommandBatch = function (list) {
+ var batch_size = 100,
+ cutoff;
+
+ if (list.length >= batch_size) {
+ // If we have more clients than our batch size, call ourself with the next batch
+ setTimeout(function () {
+ sendCommandBatch(list.slice(batch_size));
+ }, 200);
+
+ cutoff = batch_size;
+
+ } else {
+ cutoff = list.length;
+ }
+
+ list.slice(0, cutoff).forEach(function (client) {
+ if (!client.disposed) {
+ client.sendKiwiCommand(command, data);
+ }
+ });
+
+ if (cutoff === list.length && typeof callback === 'function') {
+ callback();
+ }
+ };
+
+ sendCommandBatch(clients);
+ }
+};
+
+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;
+ }