From 2b0afcacf2d756653953343655b9ce9ca8c96e2a Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 22 Apr 2020 15:18:55 +0300 Subject: [PATCH] Safeguard nick randomizer up to allowed length --- src/plugins/irc-events/error.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/irc-events/error.js b/src/plugins/irc-events/error.js index e369366a..29f95ab6 100644 --- a/src/plugins/irc-events/error.js +++ b/src/plugins/irc-events/error.js @@ -55,8 +55,14 @@ module.exports = function (irc, network) { lobby.pushMessage(client, msg, true); if (irc.connection.registered === false) { + const nickLen = parseInt(network.irc.network.options.NICKLEN, 10) || 16; const random = (data.nick || irc.user.nick) + Math.floor(Math.random() * 10); - irc.changeNick(random); + + // 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); + } } client.emit("nick", {