Handle nick collision. Close #11

This commit is contained in:
Mattias Erming 2014-06-14 17:57:26 +02:00
parent ba559c8fed
commit d2c7c72c38
2 changed files with 22 additions and 2 deletions

View file

@ -7,6 +7,7 @@ function Network(attr) {
_.merge(this, _.extend({ _.merge(this, _.extend({
id: global.id = ++global.id || 1, id: global.id = ++global.id || 1,
client: null, client: null,
connected: false,
host: "", host: "",
nick: "", nick: "",
channels: [], channels: [],
@ -19,7 +20,10 @@ function Network(attr) {
}; };
Network.prototype.toJSON = function() { Network.prototype.toJSON = function() {
var clone = _.omit(this, "client"); var clone = _.omit(this, [
"client",
"connected",
]);
clone.name = clone.host.split(".")[1] || clone.host; clone.name = clone.host.split(".")[1] || clone.host;
return clone; return clone;
}; };

View file

@ -387,6 +387,12 @@ function event(e, data) {
text: data.message, text: data.message,
}), }),
}); });
if (!this.connected) {
if (data.cmd == "ERR_NICKNAMEINUSE") {
var random = config.defaults.nick + Math.floor(10 + (Math.random() * 89));
this.client.nick(random);
}
}
break; break;
case "join": case "join":
@ -662,7 +668,17 @@ function event(e, data) {
break; break;
case "welcome": case "welcome":
// Leaving this empty for now. this.connected = true;
var chan = channels[0];
var msg = new Msg({
from: "-!-",
text: "You're now known as " + data,
});
chan.messages.push(msg);
sockets.emit("msg", {
id: chan.id,
msg: msg,
});
break; break;
case "whois": case "whois":