|
1 |
| -// jbnc v0.7 |
| 1 | +// jbnc v0.8 |
2 | 2 | // Copyright (C) 2020 Andrew Lee <andrew@imperialfamily.com>
|
3 | 3 | // All Rights Reserved.
|
4 | 4 | const tls = require('tls');
|
@@ -862,35 +862,54 @@ function clientConnect(socket) {
|
862 | 862 | console.log("> "+lines[n]);
|
863 | 863 | data = lines[n].trim().split(" ");
|
864 | 864 | 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")) |
871 | 896 | 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")) |
875 | 899 | 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")) |
885 | 902 | this.sasl=true;
|
886 |
| - } |
887 |
| - if (!this.sasl) |
| 903 | + |
| 904 | + if (data[3]!=='NEW' && requestingCaps.length === 0) { |
888 | 905 | this.write("CAP END\n");
|
| 906 | + } else { |
| 907 | + this.write(`CAP REQ :${requestingCaps.join(' ')}\n`); |
| 908 | + } |
| 909 | + |
889 | 910 | }
|
890 | 911 | 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"); |
894 | 913 | }
|
895 | 914 | else {
|
896 | 915 | if (!this.sasl)
|
|
0 commit comments