2022-06-19 00:25:21 +00:00
|
|
|
import {IrcEventHandler} from "../../client";
|
2016-10-09 19:14:02 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
import Msg, {MessageType} from "../../models/msg";
|
|
|
|
import Config from "../../config";
|
2014-09-13 21:29:45 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
export default <IrcEventHandler>function (irc, network) {
|
2017-11-10 20:44:14 +00:00
|
|
|
const client = this;
|
2016-03-20 18:03:18 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
irc.on("irc error", function (data) {
|
2017-11-10 20:44:14 +00:00
|
|
|
const msg = new Msg({
|
2022-06-19 00:25:21 +00:00
|
|
|
type: MessageType.ERROR,
|
2020-02-04 20:31:55 +00:00
|
|
|
error: data.error,
|
2017-07-28 08:53:36 +00:00
|
|
|
showInActive: true,
|
2020-02-04 20:31:55 +00:00
|
|
|
nick: data.nick,
|
|
|
|
channel: data.channel,
|
|
|
|
reason: data.reason,
|
|
|
|
command: data.command,
|
2014-09-13 21:29:45 +00:00
|
|
|
});
|
2019-02-22 12:04:33 +00:00
|
|
|
|
2023-02-27 17:30:33 +00:00
|
|
|
let target = network.getLobby();
|
2019-02-22 12:04:33 +00:00
|
|
|
|
|
|
|
// If this error is channel specific and a channel
|
|
|
|
// with this name exists, put this error in that channel
|
|
|
|
if (data.channel) {
|
|
|
|
const channel = network.getChannel(data.channel);
|
|
|
|
|
|
|
|
if (typeof channel !== "undefined") {
|
|
|
|
target = channel;
|
|
|
|
msg.showInActive = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
target.pushMessage(client, msg, true);
|
2016-03-08 09:54:17 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
irc.on("nick in use", function (data) {
|
2019-09-15 19:35:18 +00:00
|
|
|
let message = data.nick + ": " + (data.reason || "Nickname is already in use.");
|
|
|
|
|
2022-05-01 19:12:39 +00:00
|
|
|
if (irc.connection.registered === false && !Config.values.public) {
|
2019-09-15 19:35:18 +00:00
|
|
|
message += " An attempt to use it will be made when this nick quits.";
|
|
|
|
|
|
|
|
// Clients usually get nick in use on connect when reconnecting to a network
|
|
|
|
// after a network failure (like ping timeout), and as a result of that,
|
|
|
|
// TL will append a random number to the nick.
|
|
|
|
// keepNick will try to set the original nick name back if it sees a QUIT for that nick.
|
|
|
|
network.keepNick = irc.user.nick;
|
|
|
|
}
|
|
|
|
|
2023-02-27 17:30:33 +00:00
|
|
|
const lobby = network.getLobby();
|
2017-11-10 20:44:14 +00:00
|
|
|
const msg = new Msg({
|
2022-06-19 00:25:21 +00:00
|
|
|
type: MessageType.ERROR,
|
2019-09-15 19:35:18 +00:00
|
|
|
text: message,
|
2017-07-28 08:53:36 +00:00
|
|
|
showInActive: true,
|
2016-03-08 09:54:17 +00:00
|
|
|
});
|
2016-09-25 06:41:10 +00:00
|
|
|
lobby.pushMessage(client, msg, true);
|
2016-03-08 09:54:17 +00:00
|
|
|
|
2016-04-10 08:55:58 +00:00
|
|
|
if (irc.connection.registered === false) {
|
2020-04-22 12:18:55 +00:00
|
|
|
const nickLen = parseInt(network.irc.network.options.NICKLEN, 10) || 16;
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
2018-03-26 07:00:46 +00:00
|
|
|
const random = (data.nick || irc.user.nick) + Math.floor(Math.random() * 10);
|
2020-04-22 12:18:55 +00:00
|
|
|
|
|
|
|
// Safeguard nick changes up to allowed length
|
|
|
|
// Some servers may send "nick in use" error even for randomly generated nicks
|
|
|
|
if (random.length <= nickLen) {
|
|
|
|
irc.changeNick(random);
|
|
|
|
}
|
2016-04-10 08:55:58 +00:00
|
|
|
}
|
2016-10-01 16:46:36 +00:00
|
|
|
|
|
|
|
client.emit("nick", {
|
2018-04-26 09:06:01 +00:00
|
|
|
network: network.uuid,
|
2017-11-15 06:35:15 +00:00
|
|
|
nick: irc.user.nick,
|
2016-10-01 16:46:36 +00:00
|
|
|
});
|
2014-09-13 21:29:45 +00:00
|
|
|
});
|
2016-04-03 10:26:17 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
irc.on("nick invalid", function (data) {
|
2023-02-27 17:30:33 +00:00
|
|
|
const lobby = network.getLobby();
|
2017-11-10 20:44:14 +00:00
|
|
|
const msg = new Msg({
|
2022-06-19 00:25:21 +00:00
|
|
|
type: MessageType.ERROR,
|
2016-04-04 18:32:21 +00:00
|
|
|
text: data.nick + ": " + (data.reason || "Nickname is invalid."),
|
2017-07-28 08:53:36 +00:00
|
|
|
showInActive: true,
|
2016-04-03 10:26:17 +00:00
|
|
|
});
|
2016-09-25 06:41:10 +00:00
|
|
|
lobby.pushMessage(client, msg, true);
|
2016-04-03 10:26:17 +00:00
|
|
|
|
2016-04-10 08:55:58 +00:00
|
|
|
if (irc.connection.registered === false) {
|
2022-05-01 19:12:39 +00:00
|
|
|
irc.changeNick(Config.getDefaultNick());
|
2016-04-10 08:55:58 +00:00
|
|
|
}
|
2016-10-01 16:46:36 +00:00
|
|
|
|
|
|
|
client.emit("nick", {
|
2018-04-26 09:06:01 +00:00
|
|
|
network: network.uuid,
|
2017-11-15 06:35:15 +00:00
|
|
|
nick: irc.user.nick,
|
2016-10-01 16:46:36 +00:00
|
|
|
});
|
2016-04-03 10:26:17 +00:00
|
|
|
});
|
2014-09-13 21:29:45 +00:00
|
|
|
};
|