From: Darren Date: Tue, 23 Oct 2012 23:27:59 +0000 (+0100) Subject: Rehashing new clients #92 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1286229acd859577c331a51a2b412860460d0adc;p=KiwiIRC.git Rehashing new clients #92 --- 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;