mirror of
https://github.com/thelounge/thelounge
synced 2024-11-29 23:40:28 +00:00
Handle nick collision. Close #11
This commit is contained in:
parent
ba559c8fed
commit
d2c7c72c38
2 changed files with 22 additions and 2 deletions
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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":
|
||||||
|
|
Loading…
Reference in a new issue