From 1009b2f7c2a0a3a620b102452edd37642e9ffff4 Mon Sep 17 00:00:00 2001 From: Cory Chaplin Date: Mon, 10 Aug 2015 22:20:48 +0200 Subject: [PATCH] Who support --- server/irc/channel.js | 19 ++++++++++- server/irc/commands/misc.js | 63 ++++++++++++++++++++++++++++++------- server/irc/user.js | 17 ++++++++++ 3 files changed, 86 insertions(+), 13 deletions(-) diff --git a/server/irc/channel.js b/server/irc/channel.js index afee79652..659fbdd4f 100644 --- a/server/irc/channel.js +++ b/server/irc/channel.js @@ -29,7 +29,9 @@ var IrcChannel = function(irc_connection, name) { banlist_end: onBanListEnd, topicsetby: onTopicSetBy, mode: onMode, - info: onChannelInfo + info: onChannelInfo, + who_channel: onChannelWho, + who_channel_end: onChannelWhoEnd, }; EventBinder.bindIrcEvents('channel ' + this.name, this.irc_events, this, irc_connection); }; @@ -244,6 +246,21 @@ function onNicklistEnd(event) { //updateUsersList.call(this, event.users); } +function onChannelWho(event) { + this.irc_connection.clientEvent('who_channel', { + users: event.users, + channel: this.name + }); +} + + +function onChannelWhoEnd(event) { + this.irc_connection.clientEvent('who_channel_end', { + users: event.users, + channel: this.name + }); +} + function updateUsersList(users) { var that = this; if (users) { diff --git a/server/irc/commands/misc.js b/server/irc/commands/misc.js index 935a03258..bba68dec6 100644 --- a/server/irc/commands/misc.js +++ b/server/irc/commands/misc.js @@ -40,18 +40,57 @@ var handlers = { this.emit('server ' + this.irc_connection.irc_host.hostname + ' motd_end', {}); }, - - - RPL_WHOREPLY: function (command) { - // For the time being, NOOP this command so they don't get passed - // down to the client. Waste of bandwidth since we do not use it yet - // TODO: Impliment RPL_WHOREPLY - }, - - RPL_ENDOFWHO: function (command) { - // For the time being, NOOP this command so they don't get passed - // down to the client. Waste of bandwidth since we do not use it yet - // TODO: Impliment RPL_ENDOFWHO + 'RPL_WHOREPLY': function (command) { + // This method is called once for each user in the channel - Gotta be carefull + if (typeof this.who_members === "undefined") { + this.who_members = []; + } + + var that = this, + channel = command.params[1], + nick = command.params[5], + flags = command.params[6], + realname = command.params[command.params.length - 1].substring(command.params[command.params.length - 1].indexOf(' ') + 1); // Getting rid of useless hops info + + this.who_members.push({nick: nick, realname: realname, flags: flags, channel: channel}); + }, + + 'RPL_ENDOFWHO': function (command) { + // If it's a channel WHO + if (command.params[1].substring(0, 1) === '#') { + this.irc_connection.emit('channel ' + command.params[1] + ' who_channel', { + users: this.who_members, + channel: command.params[1] + }); + this.irc_connection.emit('channel ' + command.params[1] + ' who_channel_end', { + channel: command.params[1] + }); + } else { // It's a user WHO + if(this.who_members[0] == undefined) { // Looks like there is nothing to work with here + return; + } + + var who_member = this.who_members[0], + nick = command.params[1], + realname = this.who_members[0].realname; + + if(realname == undefined) { + realname = 'U'; + } + + this.irc_connection.emit('user ' + nick + ' who_user', { + nick: nick, + realname: realname, + flags: who_member.flags, + channel: who_member.channel + }); + this.irc_connection.emit('user ' + nick + ' who_user_end', { + nick: nick + }); + + } + // Reset who_members + this.who_members = []; }, diff --git a/server/irc/user.js b/server/irc/user.js index 39bdcca2f..8d197cd7b 100755 --- a/server/irc/user.js +++ b/server/irc/user.js @@ -32,6 +32,8 @@ var IrcUser = function (irc_connection, nick) { action: onAction, ctcp_request: onCtcpRequest, mode: onMode, + who_user: onWhoUser, + who_user_end: onWhoUserEnd, wallops: onWallops }; EventBinder.bindIrcEvents('user ' + this.nick, this.irc_events, this, irc_connection); @@ -319,6 +321,21 @@ function onMode(event) { }); } +function onWhoUser(event) { + this.irc_connection.clientEvent('who_user', { + nick: event.nick, + realname: event.realname, + flags: event.flags, + channel: event.channel + }); +} + +function onWhoUserEnd(event) { + this.irc_connection.clientEvent('who_user_end', { + nick: event.nick + }); +} + function onWallops(event) { this.irc_connection.clientEvent('wallops', { nick: event.nick,