mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-14 19:25:26 -05:00
lib/client: send BOUNCER BIND and CAP END immediately
Don't wait for auth to finish. This reduces the number of roundtrips.
This commit is contained in:
parent
bc3abbec32
commit
adefc620de
1 changed files with 24 additions and 27 deletions
|
@ -293,15 +293,6 @@ export default class Client extends EventTarget {
|
||||||
case irc.RPL_LOGGEDOUT:
|
case irc.RPL_LOGGEDOUT:
|
||||||
console.log("Logged out");
|
console.log("Logged out");
|
||||||
break;
|
break;
|
||||||
case irc.RPL_SASLSUCCESS:
|
|
||||||
console.log("SASL authentication success");
|
|
||||||
if (this.status != Client.Status.REGISTERED) {
|
|
||||||
if (this.enabledCaps["soju.im/bouncer-networks"] && this.params.bouncerNetwork) {
|
|
||||||
this.send({ command: "BOUNCER", params: ["BIND", this.params.bouncerNetwork] });
|
|
||||||
}
|
|
||||||
this.send({ command: "CAP", params: ["END"] });
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case irc.RPL_NAMREPLY:
|
case irc.RPL_NAMREPLY:
|
||||||
this.pushPendingList("NAMES " + msg.params[2], msg);
|
this.pushPendingList("NAMES " + msg.params[2], msg);
|
||||||
break;
|
break;
|
||||||
|
@ -325,6 +316,9 @@ export default class Client extends EventTarget {
|
||||||
case irc.RPL_ENDOFWHO:
|
case irc.RPL_ENDOFWHO:
|
||||||
this.endPendingList("WHO", msg);
|
this.endPendingList("WHO", msg);
|
||||||
break;
|
break;
|
||||||
|
case irc.RPL_SASLSUCCESS:
|
||||||
|
console.log("SASL authentication success");
|
||||||
|
break;
|
||||||
case irc.ERR_NICKLOCKED:
|
case irc.ERR_NICKLOCKED:
|
||||||
case irc.ERR_SASLFAIL:
|
case irc.ERR_SASLFAIL:
|
||||||
case irc.ERR_SASLTOOLONG:
|
case irc.ERR_SASLTOOLONG:
|
||||||
|
@ -398,6 +392,9 @@ export default class Client extends EventTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
authenticate(mechanism, params) {
|
authenticate(mechanism, params) {
|
||||||
|
if (!this.supportsSASL(mechanism)) {
|
||||||
|
throw new Error(`${mechanism} authentication not supported by the server`);
|
||||||
|
}
|
||||||
console.log(`Starting SASL ${mechanism} authentication`);
|
console.log(`Starting SASL ${mechanism} authentication`);
|
||||||
this.send({ command: "AUTHENTICATE", params: [mechanism] });
|
this.send({ command: "AUTHENTICATE", params: [mechanism] });
|
||||||
switch (mechanism) {
|
switch (mechanism) {
|
||||||
|
@ -576,20 +573,28 @@ export default class Client extends EventTarget {
|
||||||
case "LS":
|
case "LS":
|
||||||
this.supportsCap = true;
|
this.supportsCap = true;
|
||||||
this.addAvailableCaps(args[args.length - 1]);
|
this.addAvailableCaps(args[args.length - 1]);
|
||||||
if (args[0] != "*") {
|
if (args[0] == "*") {
|
||||||
console.log("Available server caps:", this.availableCaps);
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
let capEnd = true;
|
console.log("Available server caps:", this.availableCaps);
|
||||||
if ((this.params.saslPlain && this.supportsSASL("PLAIN")) || (this.params.saslExternal && this.supportsSASL("EXTERNAL"))) {
|
|
||||||
// CAP END is deferred after authentication finishes
|
this.requestCaps();
|
||||||
capEnd = false;
|
|
||||||
|
if (this.status !== Client.Status.REGISTERED) {
|
||||||
|
if (this.availableCaps["sasl"] !== undefined) {
|
||||||
|
if (this.params.saslPlain) {
|
||||||
|
this.authenticate("PLAIN", this.params.saslPlain);
|
||||||
|
} else if (this.params.saslExternal) {
|
||||||
|
this.authenticate("EXTERNAL");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.requestCaps();
|
if (this.availableCaps["soju.im/bouncer-networks"] !== undefined && this.params.bouncerNetwork) {
|
||||||
|
this.send({ command: "BOUNCER", params: ["BIND", this.params.bouncerNetwork] });
|
||||||
if (this.status != Client.Status.REGISTERED && capEnd) {
|
|
||||||
this.send({ command: "CAP", params: ["END"] });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.send({ command: "CAP", params: ["END"] });
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "NEW":
|
case "NEW":
|
||||||
|
@ -610,14 +615,6 @@ export default class Client extends EventTarget {
|
||||||
args[0].split(" ").forEach((cap) => {
|
args[0].split(" ").forEach((cap) => {
|
||||||
cap = cap.toLowerCase();
|
cap = cap.toLowerCase();
|
||||||
this.enabledCaps[cap] = true;
|
this.enabledCaps[cap] = true;
|
||||||
|
|
||||||
if (cap === "sasl" && this.status !== Client.Status.REGISTERED) {
|
|
||||||
if (this.params.saslPlain) {
|
|
||||||
this.authenticate("PLAIN", this.params.saslPlain);
|
|
||||||
} else if (this.params.saslExternal) {
|
|
||||||
this.authenticate("EXTERNAL");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "NAK":
|
case "NAK":
|
||||||
|
|
Loading…
Reference in a new issue