+// Create a plugin interface
+global.modules = new modules.Publisher();
+
+// Register as the active interface
+modules.registerPublisher(global.modules);
+
+// Load any modules in the config
+if (global.config.module_dir) {
+ (global.config.modules || []).forEach(function (module_name) {
+ if (modules.load(global.config.module_dir + module_name + '.js')) {
+ console.log('Module ' + module_name + ' loaded successfuly');
+ } else {
+ console.log('Module ' + module_name + ' failed to load');
+ }
+ });
+}
+
+
+
+
+// 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;
+ }
+ }
+};
+
+
+