+// Holder for all the connected clients
+global.clients = {
+ clients: Object.create(null),
+ addresses: Object.create(null),
+
+ add: function (client) {
+ this.clients[client.hash] = client;
+ if (typeof this.addresses[client.real_address] === 'undefined') {
+ this.addresses[client.real_address] = Object.create(null);
+ }
+ this.addresses[client.real_address][client.hash] = client;
+ },
+
+ remove: function (client) {
+ if (typeof this.clients[client.hash] !== 'undefined') {
+ delete this.clients[client.hash];
+ delete this.addresses[client.real_address][client.hash];
+ if (Object.keys(this.addresses[client.real_address]).length < 1) {
+ delete this.addresses[client.real_address];
+ }
+ }
+ },
+
+ numOnAddress: function (addr) {
+ if (typeof this.addresses[addr] !== 'undefined') {
+ return Object.keys(this.addresses[addr]).length;
+ } else {
+ return 0;
+ }
+ }
+};
+
+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;
+ }
+ }
+};
+
+