Skip to content

Commit 8968051

Browse files
authored
Merge pull request #63 from Madriix/master
Update bouncer.js
2 parents d07885b + b5f4442 commit 8968051

File tree

1 file changed

+43
-24
lines changed

1 file changed

+43
-24
lines changed

bouncer.js

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// jbnc v0.7
1+
// jbnc v0.8
22
// Copyright (C) 2020 Andrew Lee <andrew@imperialfamily.com>
33
// All Rights Reserved.
44
const tls = require('tls');
@@ -862,35 +862,54 @@ function clientConnect(socket) {
862862
console.log("> "+lines[n]);
863863
data = lines[n].trim().split(" ");
864864
if(data[1]=="CAP") {
865-
if(data[3] && data[3]=='LS') {
866-
if(lines[n].trim().indexOf("multi-prefix")>=0) {
867-
this.write("CAP REQ :multi-prefix\n");
868-
}
869-
if(lines[n].trim().indexOf("userhost-in-names")>=0) {
870-
this.write("CAP REQ :userhost-in-names\n");
865+
866+
// :irc.example.net CAP * LS :invite-notify ...
867+
// :irc.example.net CAP * NEW :invite-notify ...
868+
if(data[3] && (data[3]=='LS' || data[3]==='NEW')) {
869+
870+
let wantedCaps = new Set([
871+
'server-time',
872+
'multi-prefix',
873+
'away-notify',
874+
'account-notify',
875+
'account-tag',
876+
'invite-notify',
877+
'extended-join',
878+
'userhost-in-names',
879+
'cap-notify',
880+
'sasl',
881+
'message-tags',
882+
]);
883+
884+
let offeredCaps = lines[n].trim().split(' ');
885+
886+
887+
let requestingCaps = offeredCaps
888+
.filter((cap) => (
889+
wantedCaps.has(cap.split('=')[0].toLowerCase())
890+
))
891+
.map((cap) => cap.split('=')[0]);
892+
893+
// <- :irc.example.net CAP testor LIST :away-notify ...
894+
895+
if (requestingCaps.includes("userhost-in-names"))
871896
this.userhostInNames=true;
872-
}
873-
if(lines[n].trim().indexOf("message-tags")>=0) {
874-
this.write("CAP REQ :message-tags\n");
897+
898+
if (requestingCaps.includes("message-tags"))
875899
this.messagetags=true;
876-
}
877-
if(lines[n].trim().indexOf("away-notify")>=0) {
878-
this.write("CAP REQ :away-notify\n");
879-
}
880-
if(this.messagetags && lines[n].trim().indexOf("server-time")>=0) {
881-
this.write("CAP REQ :server-time\n");
882-
}
883-
if(lines[n].trim().indexOf("sasl")>=0) {
884-
this.write("CAP REQ :sasl\n");
900+
901+
if (requestingCaps.includes("sasl"))
885902
this.sasl=true;
886-
}
887-
if (!this.sasl)
903+
904+
if (data[3]!=='NEW' && requestingCaps.length === 0) {
888905
this.write("CAP END\n");
906+
} else {
907+
this.write(`CAP REQ :${requestingCaps.join(' ')}\n`);
908+
}
909+
889910
}
890911
else if(this.sasl && data[3] && data[3]=='ACK') {
891-
if(lines[n].trim().indexOf("sasl")>=0) {
892-
this.write("AUTHENTICATE :PLAIN\n");
893-
}
912+
this.write("AUTHENTICATE :PLAIN\n");
894913
}
895914
else {
896915
if (!this.sasl)

0 commit comments

Comments
 (0)