Skip to content

Commit 253e473

Browse files
authored
Merge pull request #55 from Madriix/master
Update bouncer.js
2 parents 3e9559f + d80118d commit 253e473

File tree

1 file changed

+43
-30
lines changed

1 file changed

+43
-30
lines changed

bouncer.js

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// jbnc v0.5
1+
// jbnc v0.6
22
// Copyright (C) 2020 Andrew Lee <andrew@imperialfamily.com>
33
// All Rights Reserved.
44
const tls = require('tls');
@@ -249,15 +249,15 @@ server = doServer(tlsOptions,function(socket) {
249249
}
250250
else if(commands[1]) {
251251
this.irc.nick=commands[1].trim();
252-
/*if(this.irc.user) {
252+
if(this.irc.user) {
253253
this.hash=hash(this.irc.nick+this.irc.user+this.irc.password+this.irc.server+this.irc.port.toString());
254254
if(connections[socket.hash]) {
255255
clientReconnect(this);
256256
}
257257
else {
258258
clientConnect(this);
259259
}
260-
}*/
260+
}
261261
}
262262
break;
263263
case 'USER':
@@ -514,10 +514,10 @@ server = doServer(tlsOptions,function(socket) {
514514
}
515515
break;
516516
default:
517-
if(typeof connections[this.hash] === 'undefined' )
518-
continue;
517+
/*if(typeof connections[this.hash] === 'undefined' )
518+
continue;*/
519519
// supress joins of channels we are already in because some clients dont react properly.
520-
if(input[i].toString().substr(0,4)=="JOIN") {
520+
if(input[i] && connections[this.hash] && input[i].toString().substr(0,4)=="JOIN") {
521521
command=input[i].toString().trim().split(" ");
522522
if(!command[1])
523523
break;
@@ -652,7 +652,12 @@ function clientReconnect(socket) {
652652
if(connection.channels.hasOwnProperty(key)) {
653653
_channel=connection.channels[key];
654654

655-
socket.write("@time=2020-07-26T09:20:54.103Z;msgid=null :"+connection.nick+"!"+connection.ircuser+"@"+connection.host+" JOIN :"+_channel.name+"\n");
655+
if (_channel.name != "undefined" || typeof _channel.name !== 'undefined') {
656+
socket.write("@time="+new Date().toISOString()+";msgid=back :"+connection.nick+"!"+connection.ircuser+"@"+connection.host+" JOIN :"+_channel.name+"\n");
657+
} else {
658+
continue;
659+
}
660+
656661
_mode_params='';
657662

658663
if ( typeof _channel.modes === 'undefined' )
@@ -857,6 +862,9 @@ function clientConnect(socket) {
857862
this.write("CAP REQ :message-tags\n");
858863
this.messagetags=true;
859864
}
865+
if(lines[n].trim().indexOf("away-notify")>=0) {
866+
this.write("CAP REQ :away-notify\n");
867+
}
860868
if(this.messagetags && lines[n].trim().indexOf("server-time")>=0) {
861869
this.write("CAP REQ :server-time\n");
862870
}
@@ -885,17 +893,19 @@ function clientConnect(socket) {
885893
this.nickpassword;
886894

887895
const b = Buffer.from(auth_str, 'utf8');
888-
let b64 = b.toString('base64');
896+
const b64 = b.toString('base64');
889897

890-
while (b64.length >= 400) {
891-
this.write('AUTHENTICATE :' + b64.slice(0, 399) + '\n');
892-
b64 = b64.slice(399);
898+
const singleAuthCommandLength = 400;
899+
let sliceOffset = 0;
900+
901+
while (b64.length > sliceOffset) {
902+
this.write('AUTHENTICATE ' + b64.substr(sliceOffset, singleAuthCommandLength) + '\n');
903+
sliceOffset += singleAuthCommandLength;
893904
}
894-
if (b64.length > 0) {
895-
this.write('AUTHENTICATE :' + b64 + '\n');
896-
} else {
905+
906+
if (b64.length === sliceOffset)
897907
this.write('AUTHENTICATE :+\n');
898-
}
908+
899909
continue;
900910
}
901911

@@ -913,6 +923,9 @@ function clientConnect(socket) {
913923
}
914924
}
915925

926+
if(data[1]=="900") {
927+
this.account = data[4];
928+
}
916929
let s = data[1];
917930

918931
if ( this.messagetags && (data[2]=="JOIN" || data[2]=="PART" || data[2]=="QUIT" || data[2]=="MODE" || data[2]=="PING" || data[2]=="NICK" || data[2]=="KICK") ) {
@@ -999,7 +1012,7 @@ function clientConnect(socket) {
9991012
_mode[i]=='j')) {
10001013
if(_mode[i]=='o' || _mode[i]=='v' || _mode[i]=='h') {
10011014
for(c=0;c<curchan.names.length;c++) {
1002-
if(curchan.names[c].replace("@","").replace("+","").replace("%","")==_mode_target[_mode_count]) {
1015+
if(curchan.names[c].replace(/(&|~|@|%|\+)/,"")==_mode_target[_mode_count]) {
10031016
switch(_mode[i]) {
10041017
case 'o':
10051018
_this_target = _mode_target[_mode_count] + "!" + (curchan.userhosts[c]?curchan.userhosts[c]:"*@*");
@@ -1014,7 +1027,7 @@ function clientConnect(socket) {
10141027
case 'v':
10151028
_this_target = _mode_target[_mode_count] + "!" + (curchan.userhosts[c]?curchan.userhosts[c]:"*@*");
10161029
if(curchan.names[c].indexOf("+")==-1) {
1017-
if(curchan.names[c].indexOf("@")==-1) {
1030+
if(curchan.names[c].indexOf("&")==-1 || curchan.names[c].indexOf("~")==-1 || curchan.names[c].indexOf("@")==-1) {
10181031
if(curchan.names[c].indexOf("%")==-1) {
10191032
curchan.names[c]="+"+curchan.names[c];
10201033
}
@@ -1039,7 +1052,7 @@ function clientConnect(socket) {
10391052
case 'h':
10401053
_this_target = _mode_target[_mode_count] + "!" + (curchan.userhosts[c]?curchan.userhosts[c]:"*@*");
10411054
if(curchan.names[c].indexOf("%")==-1) {
1042-
if(curchan.names[c].indexOf("@")==-1) {
1055+
if(curchan.names[c].indexOf("&")==-1 || curchan.names[c].indexOf("~")==-1 || curchan.names[c].indexOf("@")==-1) {
10431056
curchan.names[c]="%"+curchan.names[c];
10441057
}
10451058
else
@@ -1073,21 +1086,21 @@ function clientConnect(socket) {
10731086
}
10741087
}
10751088
else {
1076-
_regex = new RegExp(_mode[i],"g")
1089+
_regex = new RegExp(_mode[i],"g");
10771090
if(_sender==_target && _target==this.nick || _sender=="NickServ" && _target==this.nick || _sender=="OperServ" && _target==this.nick)
10781091
this.umode=this.umode.replace(_regex,"");
1079-
else if(curchan != null && (_mode[i]!='o' && _mode[i]!='v' && _mode[i]!='h'))
1092+
else if(curchan != null && (_mode[i]!='o' && _mode[i]!='v' && _mode[i]!='h') && curchan.modes)
10801093
curchan.modes=curchan.modes.replace(_regex,"");
10811094
if((_target.indexOf("#")!=-1||_target.indexOf("&")!=-1) && (_mode[i]=='o' || _mode[i]=='k' || _mode[i]=='v' || _mode[i]=='h' || _mode[i]=='l' ||
10821095
_mode[i]=='e' || _mode[i]=='b' || _mode[i]=='I' || _mode[i]=='q' || _mode[i]=='f' ||
10831096
_mode[i]=='j')) {
10841097
if(_mode[i]=='o' || _mode[i]=='v' || _mode[i]=='h') {
10851098
for(c=0;c<curchan.names.length;c++) {
1086-
if(curchan.names[c].replace(/\@/,"").replace(/\%/,"").replace(/\+/,"")==_mode_target[_mode_count]) {
1099+
if(curchan.names[c].replace(/(&|~|@|%|\+)/,"")==_mode_target[_mode_count]) {
10871100
switch(_mode[i]) {
10881101
case 'o':
10891102
_this_target = _mode_target[_mode_count] + "!" + (curchan.userhosts[c]?curchan.userhosts[c]:"*@*");
1090-
curchan.names[c]=curchan.names[c].replace("@","");
1103+
curchan.names[c]=curchan.names[c].replace(/(&|~|@)/,"");
10911104
if(_mode_target[_mode_count]!=this.nick && curchan.aop && curchan.aop.indexOf(_this_target)>=0 && this.opmode) {
10921105
curchan.aop.splice(curchan.aop.indexOf(_this_target),1);
10931106
}
@@ -1180,13 +1193,13 @@ function clientConnect(socket) {
11801193
if(this.channels[__channel]) {
11811194
this.channels[__channel].names.push(_nick);
11821195
this.channels[__channel].userhosts.push(this.userHostInNames?_userhost:"*@*");
1183-
if(this.channels[__channel].isop && this.channels[__channel].aop.indexOf(_nick+"!"+_userhost)>=0 && this.opmode) {
1196+
if(this.channels[__channel].isop && this.channels[__channel].aop && this.channels[__channel].aop.indexOf(_nick+"!"+_userhost)>=0 && this.opmode) {
11841197
this.write("MODE "+this.channels[__channel].name+" +o "+_nick+"\n");
11851198
}
1186-
if((this.channels[__channel].isop || this.channels[__channel].ishop) && this.channels[__channel].aoh.indexOf(_nick+"!"+_userhost)>=0 && this.opmode) {
1199+
if((this.channels[__channel].isop || this.channels[__channel].ishop) && this.channels[__channel].aoh && this.channels[__channel].aoh.indexOf(_nick+"!"+_userhost)>=0 && this.opmode) {
11871200
this.write("MODE "+this.channels[__channel].name+" +h "+_nick+"\n");
11881201
}
1189-
if((this.channels[__channel].isop || this.channels[__channel].ishop) && this.channels[__channel].aov.indexOf(_nick+"!"+_userhost)>=0 && this.opmode) {
1202+
if((this.channels[__channel].isop || this.channels[__channel].ishop) && this.channels[__channel].aov && this.channels[__channel].aov.indexOf(_nick+"!"+_userhost)>=0 && this.opmode) {
11901203
this.write("MODE "+this.channels[__channel].name+" +v "+_nick+"\n");
11911204
}
11921205
}
@@ -1226,7 +1239,7 @@ function clientConnect(socket) {
12261239
}
12271240
else if(this.channels[_channel]) {
12281241
for(x=0;x<this.channels[_channel].names.length;x++)
1229-
if(this.channels[_channel].names[x].replace("@","").replace("+","").replace("~","").replace("%","")==_target)
1242+
if(this.channels[_channel].names[x].replace(/(&|~|@|%|\+)/,"")==_target)
12301243
break;
12311244
this.channels[_channel].names.splice(x,1);
12321245
}
@@ -1239,7 +1252,7 @@ function clientConnect(socket) {
12391252
}
12401253
else if(this.channels[_target]) {
12411254
for(x=0;x<this.channels[_target].names.length;x++)
1242-
if(this.channels[_target].names[x].replace("@","").replace("+","").replace("~","").replace("%","")==_sender)
1255+
if(this.channels[_target].names[x].replace(/(&|~|@|%|\+)/,"")==_sender)
12431256
break;
12441257
this.channels[_target].names.splice(x,1);
12451258
this.channels[_target].userhosts.splice(x,1);
@@ -1250,7 +1263,7 @@ function clientConnect(socket) {
12501263
for (key in this.channels) {
12511264
if (this.channels.hasOwnProperty(key)) {
12521265
for(x=0;x<this.channels[key].names.length;x++) {
1253-
if(this.channels[key].names[x].replace("@","").replace("+","").replace("~","").replace("%","")==_sender) {
1266+
if(this.channels[key].names[x].replace(/(&|~|@|%|\+)/,"")==_sender) {
12541267
this.channels[key].names.splice(x,1);
12551268
this.channels[key].userhosts.splice(x,1);
12561269
break;
@@ -1300,8 +1313,8 @@ function clientConnect(socket) {
13001313
for (key in this.channels) {
13011314
if (this.channels.hasOwnProperty(key)) {
13021315
for(x=0;x<this.channels[key].names.length;x++) {
1303-
if(this.channels[key].names[x].replace("@","").replace("+","").replace("~","").replace("%","")==_sender) {
1304-
_statut = ( /(@|%|\+)/.test(this.channels[key].names[x].substr(0,1)) ? this.channels[key].names[x].substr(0,1) : "" );
1316+
if(this.channels[key].names[x].replace(/(&|~|@|%|\+)/,"")==_sender) {
1317+
_statut = ( /(&|~|@|%|\+)/.test(this.channels[key].names[x].substr(0,1)) ? this.channels[key].names[x].substr(0,1) : "" );
13051318
this.channels[key].names.splice(x,1);
13061319
this.channels[key].names.push(_statut+_new);
13071320
break;

0 commit comments

Comments
 (0)