Skip to content

Commit 393857a

Browse files
authored
Merge pull request #20 from Madriix/master
Update
2 parents 58fd8f2 + 00ae4c2 commit 393857a

File tree

3 files changed

+59
-28
lines changed

3 files changed

+59
-28
lines changed

bouncer.js

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// jbnc v0.3
1+
// jbnc v0.4
22
// Copyright (C) 2020 Andrew Lee <andrew@imperialfamily.com>
33
// All Rights Reserved.
44
const tls = require('tls');
@@ -199,8 +199,8 @@ server = doServer(tlsOptions,function(socket) {
199199
_server = _server_pass[0].split(":");
200200
this.irc.server = _server[0];
201201
this.irc.port = (_server[1] ? _server[1].trim() : 6667);
202-
if(_server_pass[1]) {
203-
this.irc.serverpassword=_server_pass[1];
202+
if(origin[0].split("||")[0]) {
203+
this.irc.serverpassword=origin[0].split("||")[0];
204204
}
205205
if(origin[2])
206206
this.clientbuffer=origin[2].trim();
@@ -448,6 +448,7 @@ server = doServer(tlsOptions,function(socket) {
448448
this.write(":*jbnc NOTICE * :Sayonara.\n");
449449
connections[this.hash].write("QUIT :jbnc gateway\n");
450450
connections[this.hash].end();
451+
delete connections[this.hash];
451452
break;
452453
case 'PASS':
453454
if(command[3]) {
@@ -600,13 +601,15 @@ function clientReconnect(socket) {
600601
socket.write(connection.motd+"\n");
601602
socket.write(":*jbnc 376 "+connection.nick+" :End of /MOTD command.\n");
602603
}
604+
605+
socket.write(":*jbnc PRIVMSG "+connection.nick+" :Attaching you to the network\n");
603606

604607
// Loop thru channels and send JOINs
605608
for(key in connection.channels) {
606609
if(connection.channels.hasOwnProperty(key)) {
607610
_channel=connection.channels[key];
608611

609-
socket.write(":"+connection.nick+"!"+connection.ircuser+"@"+connection.host+" JOIN :"+_channel.name+"\n");
612+
socket.write("@time=null;msgid=null :"+connection.nick+"!"+connection.ircuser+"@"+connection.host+" JOIN :"+_channel.name+"\n");
610613
_mode_params='';
611614
for(x=0;x<_channel.modes.length;x++) {
612615
switch(_channel.modes[x]) {
@@ -771,14 +774,21 @@ function clientConnect(socket) {
771774
this.write("CAP REQ :userhost-in-names\n");
772775
this.userhostInNames=true;
773776
}
777+
if(lines[n].trim().indexOf("server-time")>=0) {
778+
this.write("CAP REQ :server-time\n");
779+
}
780+
if(lines[n].trim().indexOf("message-tags")>=0) {
781+
this.write("CAP REQ :message-tags\n");
782+
}
774783
this.write("CAP END\n");
775784
}
776785
else {
777786
this.write("CAP END\n");
778787
}
779788
continue;
780789
}
781-
switch(data[1]) {
790+
let s = (data[2]=="JOIN" || data[2]=="PART" || data[2]=="QUIT" || data[2]=="MODE" || data[2]=="PING" || data[2]=="NICK" ? data[2] : data[1]);
791+
switch(s) {
782792
case '001':
783793
if(!this.authenticated) {
784794
this.authenticated=true;
@@ -798,19 +808,36 @@ function clientConnect(socket) {
798808
break;
799809
case '324':
800810
case 'MODE':
801-
_target=data[1]=='324'?data[3].trim():data[2].trim();
802-
_sender=data[0].substr(1).split("!")[0];
803-
_mode = data[1]=='324'?data[4].trim():data[3].trim();
804-
_mode = _mode.indexOf(":")!=-1?_mode.substr(1):_mode;
805-
_mode_target=[];
806-
if(data[1]=='324') {
807-
if(data[5])
808-
_mode_target = data.slice(5,data.length);
809-
}
810-
else {
811-
if(data[4])
812-
_mode_target = data.slice(4,data.length);
811+
if ( data[2] == "MODE" ) {
812+
_target=data[1]=='324'?data[3].trim():data[2].trim();
813+
_sender=data[1].substr(1).split("!")[0];
814+
_mode = data[1]=='324'?data[4].trim():data[3].trim();
815+
_mode = _mode.indexOf(":")!=-1?_mode.substr(1):_mode;
816+
_mode_target=[];
817+
if(data[1]=='324') {
818+
if(data[5])
819+
_mode_target = data.slice(5,data.length);
820+
}
821+
else {
822+
if(data[4])
823+
_mode_target = data.slice(4,data.length);
824+
}
825+
} else {
826+
_target=data[1]=='324'?data[3].trim():data[2].trim();
827+
_sender=data[0].substr(1).split("!")[0];
828+
_mode = data[1]=='324'?data[4].trim():data[3].trim();
829+
_mode = _mode.indexOf(":")!=-1?_mode.substr(1):_mode;
830+
_mode_target=[];
831+
if(data[1]=='324') {
832+
if(data[5])
833+
_mode_target = data.slice(5,data.length);
834+
}
835+
else {
836+
if(data[4])
837+
_mode_target = data.slice(4,data.length);
838+
}
813839
}
840+
814841
_mode_count = 0;
815842
_add = true;
816843
// walk thru modes
@@ -977,16 +1004,16 @@ function clientConnect(socket) {
9771004
this.motd+=lines[n]+"\n";
9781005
break;
9791006
case 'JOIN':
980-
_temp = data[0].substr(1).split("!");
1007+
_temp = data[1].substr(1).split("!");
9811008
_nick = _temp[0];
9821009
if(_temp[1])
9831010
_userhost = _temp[1];
9841011
if(_temp[1] && this.nick==_nick) {
9851012
this.ircuser=_temp[1].split("@")[0];
9861013
}
987-
_channels = data[2].substr(0).trim().split(",");
988-
if(data[2].indexOf(":")!=-1)
989-
_channels = data[2].substr(1).trim().split(",");
1014+
_channels = data[3].substr(0).trim().split(",");
1015+
if(data[3].indexOf(":")!=-1)
1016+
_channels = data[3].substr(1).trim().split(",");
9901017
for(x=0;x<_channels.length;x++) {
9911018
_channel=_channels[x];
9921019
__channel=_channel.toUpperCase();
@@ -1068,8 +1095,8 @@ function clientConnect(socket) {
10681095
}
10691096
break;
10701097
case 'PART':
1071-
_target=data[2].toUpperCase().trim();
1072-
_sender=data[0].substr(1).split("!")[0];
1098+
_target=data[3].toUpperCase().trim();
1099+
_sender=data[1].substr(1).split("!")[0];
10731100
if(_sender==this.nick) {
10741101
delete this.channels[_target];
10751102
}
@@ -1082,7 +1109,7 @@ function clientConnect(socket) {
10821109
}
10831110
break;
10841111
case 'QUIT':
1085-
_sender=data[0].substr(1).split("!")[0];
1112+
_sender=data[1].substr(1).split("!")[0];
10861113
for (key in this.channels) {
10871114
if (this.channels.hasOwnProperty(key)) {
10881115
for(x=0;x<this.channels[key].names.length;x++)
@@ -1115,8 +1142,8 @@ function clientConnect(socket) {
11151142
this._getnames[_channel]=false;
11161143
break;
11171144
case 'NICK':
1118-
if(data[0].substr(1).split("!")[0]==this.nick) {
1119-
this.nick=data[2].substr(1).trim();
1145+
if(data[1].substr(1).split("!")[0]==this.nick) {
1146+
this.nick=data[3].substr(1).trim();
11201147
}
11211148
break;
11221149
case '433':
@@ -1132,6 +1159,10 @@ function clientConnect(socket) {
11321159
this.write("PONG "+data[1].substr(1).trim()+"\n");
11331160
continue;
11341161
}
1162+
if(data[1] == "PING") {
1163+
this.write("PONG "+data[2].substr(1).trim()+"\n");
1164+
continue;
1165+
}
11351166
if(lines[n].length>1) {
11361167
for(m=0;m<this.parents.length;m++) {
11371168
this.parents[m].write(lines[n]+"\n");

examples/example-singleuser.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
"bouncerPort":8888,
1717
"bouncerAdmin":"JFAeiwjfe",
18-
"bouncerTimeout":1209600,
18+
"bouncerTimeout":86400,
1919
"bufferMaxSize":52428800,
2020
"bouncerDefaultOpmode":false,
2121

examples/example.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
"bouncerPort":8888,
1717
"bouncerAdmin":"",
18-
"bouncerTimeout":1209600,
18+
"bouncerTimeout":86400,
1919
"bufferMaxSize":52428800,
2020
"bouncerDefaultOpmode":false,
2121

0 commit comments

Comments
 (0)