diff --git a/lib/server.js b/lib/server.js index 11f4674..b7b8aab 100644 --- a/lib/server.js +++ b/lib/server.js @@ -17,6 +17,7 @@ var sockets = null; var networks = []; var events = [ + "errors", "join", "kick", "mode", @@ -374,6 +375,16 @@ function event(e, data) { var channels = this.channels; switch (e) { + case "errors": + sockets.emit("msg", { + msg: new Msg({ + type: "error", + from: "-!-", + text: data.message, + }), + }); + break; + case "join": var chan = _.findWhere(channels, {name: data.channel}); if (typeof chan === "undefined") { @@ -652,53 +663,36 @@ function event(e, data) { case "whois": if (!data) { - sockets.emit("msg", { - msg: new Msg({ - type: "error", - from: "-!-", - text: "No such nick/channel.", - }), + break; + } + var chan = _.findWhere(channels, {name: data.nickname}); + if (typeof chan === "undefined") { + chan = new Chan({ + type: "query", + name: data.nickname, }); - } else { - var chan = _.findWhere(channels, {name: data.nickname}); - if (typeof chan === "undefined") { - chan = new Chan({ - type: "query", - name: data.nickname, - }); - channels.push(chan); - sockets.emit("join", { - id: this.id, - chan: chan, - }); - } - var prefix = { - hostname: "from", - realname: "is", - channels: "on", - server: "using", - }; - var i = 0; - for (var k in data) { - var key = prefix[k]; - if (!key) { - continue; - } - var msg = new Msg({ - type: "whois", - from: data.nickname, - text: key + " " + data[k], - }); - chan.messages.push(msg); - sockets.emit("msg", { - id: chan.id, - msg: msg, - }); + channels.push(chan); + sockets.emit("join", { + id: this.id, + chan: chan, + }); + } + var prefix = { + hostname: "from", + realname: "is", + channels: "on", + server: "using", + }; + var i = 0; + for (var k in data) { + var key = prefix[k]; + if (!key || data[k].toString() == "") { + continue; } var msg = new Msg({ type: "whois", from: data.nickname, - text: "End of /WHOIS list.", + text: key + " " + data[k], }); chan.messages.push(msg); sockets.emit("msg", { @@ -706,6 +700,16 @@ function event(e, data) { msg: msg, }); } + var msg = new Msg({ + type: "whois", + from: data.nickname, + text: "End of /WHOIS list.", + }); + chan.messages.push(msg); + sockets.emit("msg", { + id: chan.id, + msg: msg, + }); break; } }