Merged prawnsalad's master branch, additional cleaning up.
authorJack Allnutt <m2ys4u@Gmail.com>
Thu, 8 Sep 2011 00:58:36 +0000 (01:58 +0100)
committerJack Allnutt <m2ys4u@Gmail.com>
Thu, 8 Sep 2011 00:58:36 +0000 (01:58 +0100)
1  2 
js/front.js
js/gateway.js
js/util.js
node/app.js

diff --cc js/front.js
index 25ba6768a7f2a72f7fb1959deffcdc5d59128448,68f32f0f662b3910a013b59e3fbaca55d82ae46a..47a2a4c24d49e3f3c5d2a3f6647017d534ef53a6
@@@ -1,5 -1,5 +1,5 @@@
 -/*jslint undef: true, browser: true, continue: true, sloppy: true, evil: true, forin: true, newcap: false, plusplus: true, maxerr: 50, indent: 4 */
 -/*global gateway, io, $, iScroll, agent, touchscreen*/
 +/*jslint devel: true, undef: true, browser: true, continue: true, sloppy: true, forin: true, newcap: true, plusplus: true, maxerr: 50, indent: 4 */
- /*global gateway, io, $, iScroll, agent, touchscreen, init_data, plugs, registerTouches, randomString */
++/*global gateway, io, $, iScroll, agent, touchscreen, init_data, plugs, plugins, registerTouches, randomString */
  var front = {
      revision: 38,
      
              front.joinChannel($(this).text());
              return false;
          });
-         
 -
 -
 -        for(var i in plugins) plugs.loadPlugin(plugins[i]);
 -        
++        (function () {
++            var i;
++            for (i in plugins) {
++                plugs.loadPlugin(plugins[i]);
++            }
++        }());
      },
      
      doLayoutSize: function () {
diff --cc js/gateway.js
Simple merge
diff --cc js/util.js
index 85988b088782a21c121140a59aa3fc3c7ae960b4,9ad8760c19759c37c177662059f5d7203e97e4ba..c840c62024b569c1a669e912dcecab526384afa1
@@@ -221,8 -201,19 +221,20 @@@ var plugins = 
                  break;
              }
              return false;
-         }
-     }
++
+               }
+       },
+       {
+               name: "kiwitest",
 -              oninit: function(event, opts) {
++              oninit: function (event, opts) {
+                       console.log('registering namespace');
 -                      $(gateway).bind("kiwi.lol.browser", function(e, data){
++                      $(gateway).bind("kiwi.lol.browser", function (e, data) {
+                               console.log('YAY kiwitest');
+                               console.log(data);
+                       });
+               }
+       }
  ];
  
  
@@@ -299,18 -280,13 +311,7 @@@ plugs.run = function (event_name, event
      return ret;
  };
  
- (function () {
-     var i;
-     for (i in plugins) {
-         plugs.loadPlugin(plugins[i]);
-     }
- }());
  
 -
 -
 -
 -
 -
 -
  /*
   * jQuery Templates Plugin 1.0.0pre
   * http://github.com/jquery/jquery-tmpl
diff --cc node/app.js
index 670e110e256f89132852e39429e245cd2155ca4d,ff023f4b8080c5e9f6b55d6aba4c3b6fce33292b..72355c50960355b31c83dbbbd3d93aa3f42c97a4
@@@ -1,3 -1,3 +1,5 @@@
++/*jslint continue: true, forin: true, regexp: true, undef: false, node: true, nomen: true, plusplus: true, maxerr: 50, indent: 4 */
++/*globals kiwi_root */
  var tls = null;
  var net = null;
  var http = null;
@@@ -28,7 -28,7 +30,7 @@@ this.init = function (objs) 
        _ = objs._;
        starttls = objs.starttls;
        kiwi = require('./kiwi.js');
--}
++};
  
  
  
@@@ -40,7 -40,7 +42,7 @@@
   */
  this.setTitle = function () {
        process.title = 'kiwiirc';
--}
++};
  
  this.changeUser = function () {
      if (typeof kiwi.config.group !== 'undefined' && kiwi.config.group !== '') {
@@@ -106,7 -106,7 +108,7 @@@ var ircNumerics = 
  
  this.parseIRCMessage = function (websocket, ircSocket, data) {
      /*global ircSocketDataHandler */
--    var msg, regex, opts, options, opt, i, j, matches, nick, users, chan, channel, params, prefix, prefixes, nicklist, caps, rtn, obj;
++    var msg, regex, opts, options, opt, i, j, matches, nick, users, chan, channel, params, prefix, prefixes, nicklist, caps, rtn, obj, tmp, namespace;
      //regex = /^(?::(?:([a-z0-9\x5B-\x60\x7B-\x7D\.\-]+)|([a-z0-9\x5B-\x60\x7B-\x7D\.\-]+)!([a-z0-9~\.\-_|]+)@?([a-z0-9\.\-:\/]+)?) )?([a-z0-9]+)(?:(?: ([^:]+))?(?: :(.+))?)$/i;
      //regex = /^(?::(\S+) )?(\S+)(?: (?!:)(.+?))?(?: :(.+))?$/i;
      regex = /^(?::(?:([a-z0-9\x5B-\x60\x7B-\x7D\.\-]+)|([a-z0-9\x5B-\x60\x7B-\x7D\.\-]+)!([a-z0-9~\.\-_|]+)@?([a-z0-9\.\-:\/]+)?) )?(\S+)(?: (?!:)(.+?))?(?: :(.+))?$/i;
                  // It's a CTCP request
                  if (msg.trailing.substr(1, 6) === 'ACTION') {
                      websocket.sendClientEvent('action', {nick: msg.nick, ident: msg.ident, hostname: msg.hostname, channel: msg.params.trim(), msg: msg.trailing.substr(7, msg.trailing.length - 2)});
 -                    var tmp = msg.trailing.substr(6, msg.trailing.length - 2);
 -                    var namespace = tmp.split(' ', 1)[0];
 -                    websocket.sendClientEvent('kiwi', {namespace: namespace, data: tmp.substr(namespace.length+1)});
+                 } else if (msg.trailing.substr(1, 4) === 'KIWI') {
++                    tmp = msg.trailing.substr(6, msg.trailing.length - 2);
++                    namespace = tmp.split(' ', 1)[0];
++                    websocket.sendClientEvent('kiwi', {namespace: namespace, data: tmp.substr(namespace.length + 1)});
+                     
                  } else if (msg.trailing.substr(1, 7) === 'VERSION') {
                      ircSocket.write('NOTICE ' + msg.nick + ' :' + String.fromCharCode(1) + 'VERSION KiwiIRC' + String.fromCharCode(1) + '\r\n');
                  } else {
@@@ -610,7 -615,7 +617,9 @@@ this.websocketConnection = function (we
  
          websocket.sendClientEvent = function (event_name, data) {
              var ev = kiwi.kiwi_mod.run(event_name, data, {websocket: this});
--            if(ev === null) return;
++            if (ev === null) {
++                return;
++            }
  
              data.event = event_name;
              websocket.emit('message', data);
@@@ -692,9 -700,16 +704,16 @@@ this.websocketMessage = function (webso
              break;
          case 'action':
              if ((args.target) && (args.msg)) {
-                 websocket.sendServerLine('PRIVMSG ' + args.target + ' :\ 1' + String.fromCharCode(1) + 'ACTION ' + args.msg + String.fromCharCode(1));
 -                websocket.sendServerLine('PRIVMSG ' + args.target + ' :\001ACTION ' + args.msg + '\001');
++                websocket.sendServerLine('PRIVMSG ' + args.target + ' :' + String.fromCharCode(1) + 'ACTION ' + args.msg + String.fromCharCode(1));
              }
              break;
 -                websocket.sendServerLine('PRIVMSG ' + args.target + ' :\001KIWI ' + args.data + '\001');
+         case 'kiwi':
+             if ((args.target) && (args.data)) {
++                websocket.sendServerLine('PRIVMSG ' + args.target + ' :' + String.fromCharCode(1) + 'KIWI ' + args.data + String.fromCharCode(1));
+             }
+             break;
          case 'raw':
              websocket.sendServerLine(args.data);
              break;
@@@ -817,7 -832,7 +836,9 @@@ this.rehash = function () 
   * KiwiIRC controlling via STDIN
   */
  this.manageControll = function (data) {
--    var parts = data.toString().trim().split(' ');
++    var parts = data.toString().trim().split(' '),
++        connections_cnt = 0,
++        i;
      switch (parts[0]) {
      case 'rehash':
          console.log('Rehashing...');
          break;
  
      case 'status':
--        var connections_cnt = 0;
--        for (var i in kiwi.connections) {
++        for (i in kiwi.connections) {
              connections_cnt = connections_cnt + parseInt(kiwi.connections[i].count, 10);
          }
          console.log(connections_cnt.toString() + ' connected clients');
      default:
          console.log('Unknown command \'' + parts[0] + '\'');
      }
--};
++};