Handle nick collision. Close #11
This commit is contained in:
parent
ba559c8fed
commit
d2c7c72c38
@ -7,6 +7,7 @@ function Network(attr) {
|
||||
_.merge(this, _.extend({
|
||||
id: global.id = ++global.id || 1,
|
||||
client: null,
|
||||
connected: false,
|
||||
host: "",
|
||||
nick: "",
|
||||
channels: [],
|
||||
@ -19,7 +20,10 @@ function Network(attr) {
|
||||
};
|
||||
|
||||
Network.prototype.toJSON = function() {
|
||||
var clone = _.omit(this, "client");
|
||||
var clone = _.omit(this, [
|
||||
"client",
|
||||
"connected",
|
||||
]);
|
||||
clone.name = clone.host.split(".")[1] || clone.host;
|
||||
return clone;
|
||||
};
|
||||
|
@ -387,6 +387,12 @@ function event(e, data) {
|
||||
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;
|
||||
|
||||
case "join":
|
||||
@ -662,7 +668,17 @@ function event(e, data) {
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
case "whois":
|
||||
|
Loading…
Reference in New Issue
Block a user