From 423a590e28fd2fda857e7c5c58ee897ec60fd534 Mon Sep 17 00:00:00 2001 From: Jack Allnutt Date: Fri, 22 Jul 2011 01:45:27 +0100 Subject: [PATCH] CTCP handling --- js/front.js | 19 +++++++++++++++++++ node/kiwi.js | 20 ++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/js/front.js b/js/front.js index 97b01e1..27cb232 100644 --- a/js/front.js +++ b/js/front.js @@ -32,6 +32,8 @@ var front = { $(gateway).bind("onsync", front.onSync); $(gateway).bind("onchannel_redirect", front.onChannelRedirect); $(gateway).bind("ondebug", front.onDebug); + $(dateway).bind("onctcp_request", front.onCTCPRequest); + $(dateway).bind("onctcp_response", front.onCTCPResponse); this.buffer = []; @@ -318,6 +320,23 @@ var front = { front.tabviews.server.addMsg(null, nick, data.msg, 'notice'); } }, + + onCTCPRequest: function (e, data) { + var msg = data.msg.split(" ", 2); + switch (msg[0]) { + case 'PING': + gateway.notice(data.nick, '\001PING ' + msg[1] + '\001'); + break; + case 'TIME'; + gateway.notice(data.nick, '\001TIME ' + (new Date()).toLocaleString() + '\001'); + break; + } + front.tabviews.server.addMsg(null, data.server, data.msg, 'ctcp'); + }, + + on CTCPResponse: function(e, data) { + }, + onConnect: function (e, data) { if (data.connected) { front.tabviews.server.addMsg(null, ' ', '=== Connected OK :)', 'status'); diff --git a/node/kiwi.js b/node/kiwi.js index 824e884..22a806c 100644 --- a/node/kiwi.js +++ b/node/kiwi.js @@ -155,7 +155,12 @@ var parseIRCMessage = function (websocket, ircSocket, data) { websocket.emit('message', {event: 'quit', nick: msg.nick, ident: msg.ident, hostname: msg.hostname, message: msg.trailing}); break; case 'NOTICE': - websocket.emit('message', {event: 'notice', nick: msg.nick, ident: msg.ident, hostname: msg.hostname, channel: msg.params.trim(), msg: msg.trailing}); + if ((msg.trailing.charAt(0) === '\001') && (msg.trailing.charAt(msg.trailing.length - 1) === '\001')) { + // It's a CTCP response + websocket.emit('message', {event: 'ctcp_response', nick: msg.nick, ident: msg.ident, hostname: msg.hostname, channel: msg.params.trim(), msg: msg.trailing.substr(1, msg.trailing.length - 2)}); + } else { + websocket.emit('message', {event: 'notice', nick: msg.nick, ident: msg.ident, hostname: msg.hostname, channel: msg.params.trim(), msg: msg.trailing}); + } break; case 'NICK': websocket.emit('message', {event: 'nick', nick: msg.nick, ident: msg.ident, hostname: msg.hostname, newnick: msg.trailing}); @@ -187,7 +192,18 @@ var parseIRCMessage = function (websocket, ircSocket, data) { websocket.emit('message', params); break; case 'PRIVMSG': - websocket.emit('message', {event: 'msg', nick: msg.nick, ident: msg.ident, hostname: msg.hostname, channel: msg.params.trim(), msg: msg.trailing}); + if ((msg.trailing.charAt(0) === '\001') && (msg.trailing.charAt(msg.trailing.length - 1) === '\001')) { + // It's a CTCP request + if (msg.trailing.substr(1, 6) === 'ACTION') { + websocket.emit('message', {event: 'action', nick: msg.nick, ident: msg.ident, hostname: msg.hostname, channel: msg.params.trim(), msg: msg.trailing.substr(1, msg.trailing.length - 2)}); + } else if (msg.trailing.substr(1, 7) === 'VERSION') { + ircSocket.write('NOTICE ' + msg.nick + ':\001VERSION Kiwi IRC\001\r\n'); + } else { + websocket.emit('message', {event: 'ctcp_request', nick: msg.nick, ident: msg.ident, hostname: msg.hostname, channel: msg.params.trim(), msg: msg.trailing.substr(1, msg.trailing.length - 2)}); + } + } else { + websocket.emit('message', {event: 'msg', nick: msg.nick, ident: msg.ident, hostname: msg.hostname, channel: msg.params.trim(), msg: msg.trailing}); + } break; case 'CAP': caps = config.cap_options; -- 2.25.1