From 81122538d00c880207e80ff2895eae3bad28f47d Mon Sep 17 00:00:00 2001 From: Jack Allnutt Date: Wed, 27 Jul 2011 00:17:05 +0100 Subject: [PATCH] Support for some error messages (cannot join channel etc). Issue #7 --- js/front.js | 22 +++++++++++++++++- node/kiwi.js | 65 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 70 insertions(+), 17 deletions(-) diff --git a/js/front.js b/js/front.js index 3259bc9..6a16751 100644 --- a/js/front.js +++ b/js/front.js @@ -34,6 +34,7 @@ var front = { $(gateway).bind("ondebug", front.onDebug); $(gateway).bind("onctcp_request", front.onCTCPRequest); $(gateway).bind("onctcp_response", front.onCTCPResponse); + $(gateway).bind("onirc_error", front.onIRCError); this.buffer = []; @@ -149,7 +150,7 @@ var front = { chan = chans[i]; if (front.tabviews[chan.toLowerCase()] === undefined) { gateway.join(chan); - front.tabviewAdd(chan); + //front.tabviewAdd(chan); } else { front.tabviews[chan.toLowerCase()].show(); } @@ -473,6 +474,25 @@ var front = { front.tabviews[data.to.toLowerCase()].addMsg(null, ' ', '=== Redirected from ' + data.from, 'action'); }, + onIRCError: function (e, data) { + switch(data.error) { + case 'banned_from_channel': + front.tabviews.server.addMsg(null, ' ', '=== You are banned from ' + data.channel + ': ' + data.reason, 'status'); + break; + case 'bad_channel_key': + front.tabviews.server.addMsg(null, ' ', '=== Bad channel key for ' + data.channel, 'status'); + break; + case 'invite_only_channel': + front.tabviews.server.addMsg(null, ' ', '=== ' + data.channel + ' is invite only.', 'status'); + break; + case 'channel_is_full': + front.tabviews.server.addMsg(null, ' ', '=== ' + data.channel + ' is full.', 'status'); + break; + default: + front.tabviews.server.addMsg(null, ' ', '=== ' + data, 'status'); + } + }, + registerKeys: function () { $('#kiwi_msginput').bind('keydown', function (e) { var windows = $('#windows'); diff --git a/node/kiwi.js b/node/kiwi.js index 3ed8efe..6d7f54c 100644 --- a/node/kiwi.js +++ b/node/kiwi.js @@ -70,22 +70,30 @@ function changeUser(){ */ var ircNumerics = { - RPL_WELCOME: '001', - RPL_ISUPPORT: '005', - RPL_WHOISUSER: '311', - RPL_WHOISSERVER: '312', - RPL_WHOISOPERATOR: '313', - RPL_WHOISIDLE: '317', - RPL_ENDOFWHOIS: '318', - RPL_WHOISCHANNELS: '319', - RPL_TOPIC: '332', - RPL_NAMEREPLY: '353', - RPL_ENDOFNAMES: '366', - RPL_MOTD: '372', - RPL_WHOISMODES: '379', - ERR_NOSUCHNICK: '401', - ERR_LINKCHANNEL: '470', - RPL_STARTTLS: '670' + RPL_WELCOME: '001', + RPL_ISUPPORT: '005', + RPL_WHOISUSER: '311', + RPL_WHOISSERVER: '312', + RPL_WHOISOPERATOR: '313', + RPL_WHOISIDLE: '317', + RPL_ENDOFWHOIS: '318', + RPL_WHOISCHANNELS: '319', + RPL_TOPIC: '332', + RPL_NAMEREPLY: '353', + RPL_ENDOFNAMES: '366', + RPL_MOTD: '372', + RPL_WHOISMODES: '379', + ERR_NOSUCHNICK: '401', + ERR_CANNOTSENDTOCHAN: '404', + ERR_TOOMANYCHANNELS: '405', + ERR_USERNOTINCHANNEL: '441', + ERR_NOTONCHANNEL: '442', + ERR_LINKCHANNEL: '470', + ERR_CHANNELISFULL: '471', + ERR_INVITEONLYCHAN: '473', + ERR_BANNEDFROMCHAN: '474', + ERR_BADCHANNELKEY: '475', + RPL_STARTTLS: '670' }; @@ -326,6 +334,31 @@ var parseIRCMessage = function (websocket, ircSocket, data) { console.log(e); } break;*/ + case ircNumerics.ERR_CANNOTSENDTOCHAN: + websocket.emit('message', {event: 'irc_error', error: 'cannot_send_to_chan', channel: msg.params.split(" ")[1], reason: msg.trailing}); + break; + case ircNumerics.ERR_TOOMANYCHANNELS: + websocket.emit('message', {event: 'irc_error', error: 'too_many_channels', channel: msg.params.split(" ")[1], reason: msg.trailing}); + break; + case ircNumerics.ERR_USERNOTINCHANNEL: + params = msg.params.split(" "); + websocket.emit('message', {event: 'irc_error', error: 'user_not_in_channel', nick: params[0], channel: params[1], reason: msg.trainling}); + break; + case ircNumerics.ERR_NOTONCHANNEL: + websocket.emit('message', {event: 'irc_error', error: 'not_on_channel', channel: msg.params.split(" ")[1], reason: msg.trailing}); + break; + case ircNumerics.ERR_CHANNELISFULL: + websocket.emit('message', {event: 'irc_error', error: 'channel_is_full', channel: msg.params.split(" ")[1], reason: msg.trailing}); + break; + case ircNumerics.ERR_INVITEONLYCHAN: + websocket.emit('message', {event: 'irc_error', error: 'invite_only_channel', channel: msg.params.split(" ")[1], reason: msg.trailing}); + break; + case ircNumerics.ERR_BANNEDFROMCHAN: + websocket.emit('message', {event: 'irc_error', error: 'banned_from_channel', channel: msg.params.split(" ")[1], reason: msg.trailing}); + break; + case ircNumerics.ERR_BADCHANNELKEY: + websocket.emit('message', {event: 'irc_error', error: 'bad_channel_key', channel: msg.params.split(" ")[1], reason: msg.trailing}); + break; } } else { console.log("Unknown command.\r\n"); -- 2.25.1