From 1286229acd859577c331a51a2b412860460d0adc Mon Sep 17 00:00:00 2001 From: Darren Date: Wed, 24 Oct 2012 00:27:59 +0100 Subject: [PATCH] Rehashing new clients #92 --- server/kiwi.js | 12 +++++++++++- server/rehash.js | 31 +++++++++++++++++++++++++++++++ server/weblistener.js | 11 ++++++++++- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 server/rehash.js diff --git a/server/kiwi.js b/server/kiwi.js index 9cc2a17..87e83d7 100755 --- a/server/kiwi.js +++ b/server/kiwi.js @@ -1,7 +1,8 @@ var fs = require('fs'), _ = require('underscore'), WebListener = require('./weblistener.js'), - config = require('./configuration.js'); + config = require('./configuration.js'), + rehash = require('./rehash.js'); @@ -91,6 +92,15 @@ process.stdin.on('data', function (buffered) { break; + + case 'rehash': + (function () { + rehash.rehashAll(); + console.log('Rehashed'); + })(); + + break; + default: console.log('Unrecognised command: ' + data); } diff --git a/server/rehash.js b/server/rehash.js new file mode 100644 index 0000000..0823eda --- /dev/null +++ b/server/rehash.js @@ -0,0 +1,31 @@ +var util = require('util'), + events = require('events'), + _ = require('underscore'); + + + +function Rehash() {} +util.inherits(Rehash, events.EventEmitter); + +Rehash.prototype.rehashAll = function () { + var files = [ + './client.js', + './clientcommands.js', + //'./configuration.js', + './httphandler.js', + './irc/commands.js', + './irc/connection.js', + './weblistener.js' + ]; + + _.each(files, function (file) { + delete require.cache[require.resolve(file)]; + require(file); + }); + + this.emit('rehashed', [files]); +}; + + + +module.exports = new Rehash(); \ No newline at end of file diff --git a/server/weblistener.js b/server/weblistener.js index 7b72a73..b024542 100644 --- a/server/weblistener.js +++ b/server/weblistener.js @@ -8,8 +8,17 @@ var ws = require('socket.io'), url = require('url'), _ = require('underscore'), config = require('./configuration.js'), - Client = require('./client.js').Client, + Client = require('./client.js').Client, + HttpHandler = require('./httphandler.js').HttpHandler, + rehash = require('./rehash.js'); + + + +rehash.on('rehashed', function (files) { + Client = require('./client.js').Client; HttpHandler = require('./httphandler.js').HttpHandler; +}); + // Instance of HttpHandler var http_handler; -- 2.25.1