STDIN included in recoding
authorDarren <darren@darrenwhitlen.com>
Sun, 28 Aug 2011 17:28:08 +0000 (18:28 +0100)
committerDarren <darren@darrenwhitlen.com>
Sun, 28 Aug 2011 17:28:08 +0000 (18:28 +0100)
node/app.js
node/kiwi.js

index 47857c27cd578d629cabc9667f4b9289fa295312..c7c5ee30d0f6cf3b1c259371ac70bc8088ee951b 100644 (file)
@@ -797,37 +797,42 @@ this.rehash = function () {
 /*
  * KiwiIRC controlling via STDIN
  */
-this.startControll = function () {
-       process.stdin.resume();
-       process.stdin.on('data', function (chunk) {
-        var parts = chunk.toString().trim().split(' ');
-           switch (parts[0]) {
-           case 'rehash':
-               console.log('Rehashing...');
-               console.log(kiwi.rehash() ? 'Rehash complete' : 'Rehash failed');
-               break;
-
-               case 'recode':
-               console.log('Recoding...');
-               console.log(kiwi.recode() ? 'Recode complete' : 'Recode failed');
-               break;
-
-        case 'mod':
-            if (parts[1] === 'reload') {
-                console.log('Reloading module (' + parts[2] + ')..');
-                kiwi.kiwi_mod.reloadModule(parts[2]);
-            }
-            break;
+this.manageControll = function (data) {
+    var parts = data.toString().trim().split(' ');
+    switch (parts[0]) {
+    case 'rehash':
+        console.log('Rehashing...');
+        console.log(kiwi.rehash() ? 'Rehash complete' : 'Rehash failed');
+        break;
+
+       case 'recode':
+        console.log('Recoding...');
+        console.log(kiwi.recode() ? 'Recode complete' : 'Recode failed');
+        break;
+
+    case 'mod':
+        if (parts[1] === 'reload') {
+            console.log('Reloading module (' + parts[2] + ')..');
+            kiwi.kiwi_mod.reloadModule(parts[2]);
+        }
+        break;
 
-        case 'cache':
-            if (parts[1] === 'clear') {
-                kiwi.cache.html = {};
-                console.log('HTML cache cleared');
-            }
-            break;
+    case 'cache':
+        if (parts[1] === 'clear') {
+            kiwi.cache.html = {};
+            console.log('HTML cache cleared');
+        }
+        break;
+
+    case 'status':
+        var connections_cnt = 0;
+        for (var i in kiwi.connections) {
+            connections_cnt = connections_cnt + parseInt(kiwi.connections[i].count, 10);
+        }
+        console.log(connections_cnt.toString() + ' connected clients');
+        break;
 
-           default:
-               console.log('Unknown command \'' + parts[0] + '\'');
-           }
-       });
+    default:
+        console.log('Unknown command \'' + parts[0] + '\'');
+    }
 };
\ No newline at end of file
index 189301f414747387b51b654a378e4a9f2e1a9d40..e58607c313e114d9132a91fe955f7ace3f83ae17 100644 (file)
@@ -205,7 +205,9 @@ this.websocketListen(this.config.port, this.config.bind_address, this.httpHandle
 app.changeUser();
 
 // Listen for controll messages
-app.startControll();
+process.stdin.resume();
+process.stdin.on('data', function (data) { app.manageControll(data); });
+