From 516de5b3eaa120fe3ec1f286bc89c06d64a223d0 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 25 Aug 2020 11:42:40 +0200 Subject: [PATCH] Better handle registration errors --- lib/client.js | 20 ++++++++++++++++---- lib/irc.js | 10 +++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/client.js b/lib/client.js index cb37a51..1a325a9 100644 --- a/lib/client.js +++ b/lib/client.js @@ -93,10 +93,6 @@ export default class Client extends EventTarget { console.log("Registration complete"); this.registered = true; break; - case irc.ERR_PASSWDMISMATCH: - this.dispatchEvent(new CustomEvent("error", { detail: "Password mismatch" })); - this.close(); - break; case "CAP": this.handleCap(msg); break; @@ -148,6 +144,22 @@ export default class Client extends EventTarget { deleteBatch = name; } break; + case "ERROR": + this.dispatchEvent(new CustomEvent("error", { detail: "Fatal IRC error: " + msg.params[0] })); + this.close(); + break; + case irc.ERR_PASSWDMISMATCH: + case irc.ERR_ERRONEUSNICKNAME: + case irc.ERR_NICKNAMEINUSE: + case irc.ERR_NICKCOLLISION: + case irc.ERR_UNAVAILRESOURCE: + case irc.ERR_NOPERMFORHOST: + case irc.ERR_YOUREBANNEDCREEP: + this.dispatchEvent(new CustomEvent("error", { detail: "Error (" + msg.command + "): " + msg.params[msg.params.length - 1] })); + if (!this.registered) { + this.close(); + } + break; } this.dispatchEvent(new CustomEvent("message", { diff --git a/lib/irc.js b/lib/irc.js index 0d8ceb7..68e883c 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -1,3 +1,4 @@ +// RFC 1459 export const RPL_WELCOME = "001"; export const RPL_YOURHOST = "002"; export const RPL_CREATED = "003"; @@ -9,8 +10,15 @@ export const RPL_WHOREPLY = "352"; export const RPL_NAMREPLY = "353"; export const RPL_ENDOFNAMES = "366"; export const ERR_NOMOTD = "422"; +export const ERR_ERRONEUSNICKNAME = "432"; +export const ERR_NICKNAMEINUSE = "433"; +export const ERR_NICKCOLLISION = "436"; +export const ERR_NOPERMFORHOST = "463"; export const ERR_PASSWDMISMATCH = "464"; -// https://ircv3.net/specs/extensions/sasl-3.1 +export const ERR_YOUREBANNEDCREEP = "465"; +// RFC 2812 +export const ERR_UNAVAILRESOURCE = "437"; +// IRCv3 SASL: https://ircv3.net/specs/extensions/sasl-3.1 export const RPL_LOGGEDIN = "900"; export const RPL_LOGGEDOUT = "901"; export const ERR_NICKLOCKED = "902";