First Kiwi CTCP command structure implemented for initial testing. Socket writing...
authorDarren <darren@darrenwhitlen.com>
Wed, 7 Sep 2011 22:24:34 +0000 (23:24 +0100)
committerDarren <darren@darrenwhitlen.com>
Wed, 7 Sep 2011 22:24:34 +0000 (23:24 +0100)
js/front.js
js/gateway.js
js/util.js
node/app.js

index fd5c2796a1703330c569f80bdf8d7336125a4f66..68f32f0f662b3910a013b59e3fbaca55d82ae46a 100644 (file)
@@ -35,6 +35,7 @@ var front = {
         $(gateway).bind("onpart", front.onPart);
         $(gateway).bind("onkick", front.onKick);
         $(gateway).bind("onquit", front.onQuit);
+        $(gateway).bind("onmode", front.onMode);
         $(gateway).bind("onwhois", front.onWhois);
         $(gateway).bind("onsync", front.onSync);
         $(gateway).bind("onchannel_redirect", front.onChannelRedirect);
@@ -42,6 +43,7 @@ var front = {
         $(gateway).bind("onctcp_request", front.onCTCPRequest);
         $(gateway).bind("onctcp_response", front.onCTCPResponse);
         $(gateway).bind("onirc_error", front.onIRCError);
+        $(gateway).bind("onkiwi", front.onKiwi);
         
         this.buffer = [];
         
@@ -167,6 +169,10 @@ var front = {
             front.joinChannel($(this).text());
             return false;
         });
+
+
+
+        for(var i in plugins) plugs.loadPlugin(plugins[i]);
         
     },
     
@@ -351,6 +357,11 @@ var front = {
                     //gateway.raw('TOPIC ' + front.cur_channel.name + ' :' + msg.split(' ', 2)[1]);
                 }
                 break;
+
+            case '/kiwi':
+                gateway.kiwi(front.cur_channel.name, msg.substring(6));
+                break;
+
             default:
                 //front.cur_channel.addMsg(null, ' ', '--> Invalid command: '+parts[0].substring(1));
                 gateway.raw(msg.substring(1));
@@ -450,6 +461,10 @@ var front = {
     
     onCTCPResponse: function (e, data) {
     },
+
+    onKiwi: function (e, data) {
+        //console.log(data);
+    },
     
     onConnect: function (e, data) {
         if (data.connected) {
@@ -501,6 +516,9 @@ var front = {
             front.cur_channel.addMsg(null, data.nick, 'idle for ' + data.idle + ' seconds', 'whois');
         }
     },
+    onMode: function (e, data) {
+        console.log(data);
+    },
     onUserList: function (e, data) {
         var ul, nick, mode;
         if (front.tabviews[data.channel.toLowerCase()] === undefined) {
index 675d9a39fba5f9eb347f7b33abf3a64c66176914..c93a5924bd5ff3b87c2848e85153f6efceb130d8 100644 (file)
@@ -35,7 +35,6 @@ var gateway = {
                 console.log(e);
             });
             gateway.socket.on('connect', function () {
-                console.log('connect event');
                 gateway.sendData = function (data, callback) {
                     gateway.socket.emit('message', {sid: this.session_id, data: $.toJSON(data)}, callback);
                 };
@@ -74,7 +73,7 @@ var gateway = {
     parse: function (item) {
         if (item.event !== undefined) {
             $(gateway).trigger("on" + item.event, item);
-        
+            
             switch (item.event) {
             case 'options':
                 $.each(item.options, function (name, value) {
@@ -98,6 +97,10 @@ var gateway = {
                     gateway.onSync(item);
                 }
                 break;
+
+            case 'kiwi':
+                $(gateway).trigger('kiwi.' + item.namespace, item.data);
+                break;
             }
         }
     },
@@ -153,6 +156,18 @@ var gateway = {
     },
 
 
+    kiwi: function (s_target, s_data, callback) {
+        var data = {
+            method: 'kiwi',
+            args: {
+                target: s_target,
+                data: s_data
+            }
+        };
+        gateway.sendData(data, callback);
+    },
+
+
     notice: function (s_target, s_msg, callback) {
         var data = {
             method: 'notice',
index 37ac40a8700a41c0eba45e5bcc4ef5628f22b070..9ad8760c19759c37c177662059f5d7203e97e4ba 100644 (file)
@@ -202,6 +202,17 @@ var plugins = [
             }
             return false;
                }
+       },
+
+       {
+               name: "kiwitest",
+               oninit: function(event, opts) {
+                       console.log('registering namespace');
+                       $(gateway).bind("kiwi.lol.browser", function(e, data){
+                               console.log('YAY kiwitest');
+                               console.log(data);
+                       });
+               }
        }
 ];
 
@@ -270,9 +281,6 @@ plugs.run = function (event_name, event_data, opts) {
 };
 
 
-for(var i in plugins) plugs.loadPlugin(plugins[i]);
-
-
 
 
 
index 6434022d3ccdd6dd0146d3f95a37820a60eac67d..ff023f4b8080c5e9f6b55d6aba4c3b6fce33292b 100644 (file)
@@ -293,6 +293,11 @@ this.parseIRCMessage = function (websocket, ircSocket, data) {
                 // 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)});
+                } else if (msg.trailing.substr(1, 4) === 'KIWI') {
+                    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, 7) === 'VERSION') {
                     ircSocket.write('NOTICE ' + msg.nick + ' :' + String.fromCharCode(1) + 'VERSION KiwiIRC' + String.fromCharCode(1) + '\r\n');
                 } else {
@@ -618,7 +623,10 @@ this.websocketConnection = function (websocket) {
 
         websocket.sendServerLine = function (data, eol) {
             eol = (typeof eol === 'undefined') ? '\r\n' : eol;
-            websocket.ircSocket.write(data + eol);
+
+            try {
+                websocket.ircSocket.write(data + eol);
+            } catch (e) { }
         };
 
         websocket.on('irc connect', kiwi.websocketIRCConnect);
@@ -695,6 +703,13 @@ this.websocketMessage = function (websocket, msg, callback) {
                 websocket.sendServerLine('PRIVMSG ' + args.target + ' :\001ACTION ' + args.msg + '\001');
             }
             break;
+
+        case 'kiwi':
+            if ((args.target) && (args.data)) {
+                websocket.sendServerLine('PRIVMSG ' + args.target + ' :\001KIWI ' + args.data + '\001');
+            }
+            break;
+
         case 'raw':
             websocket.sendServerLine(args.data);
             break;