1
- // jbnc v0.5
1
+ // jbnc v0.6
2
2
// Copyright (C) 2020 Andrew Lee <andrew@imperialfamily.com>
3
3
// All Rights Reserved.
4
4
const tls = require ( 'tls' ) ;
@@ -249,15 +249,15 @@ server = doServer(tlsOptions,function(socket) {
249
249
}
250
250
else if ( commands [ 1 ] ) {
251
251
this . irc . nick = commands [ 1 ] . trim ( ) ;
252
- /* if(this.irc.user) {
252
+ if ( this . irc . user ) {
253
253
this . hash = hash ( this . irc . nick + this . irc . user + this . irc . password + this . irc . server + this . irc . port . toString ( ) ) ;
254
254
if ( connections [ socket . hash ] ) {
255
255
clientReconnect ( this ) ;
256
256
}
257
257
else {
258
258
clientConnect ( this ) ;
259
259
}
260
- }*/
260
+ }
261
261
}
262
262
break ;
263
263
case 'USER' :
@@ -514,10 +514,10 @@ server = doServer(tlsOptions,function(socket) {
514
514
}
515
515
break ;
516
516
default :
517
- if ( typeof connections [ this . hash ] === 'undefined' )
518
- continue ;
517
+ /* if(typeof connections[this.hash] === 'undefined' )
518
+ continue;*/
519
519
// 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" ) {
521
521
command = input [ i ] . toString ( ) . trim ( ) . split ( " " ) ;
522
522
if ( ! command [ 1 ] )
523
523
break ;
@@ -652,7 +652,12 @@ function clientReconnect(socket) {
652
652
if ( connection . channels . hasOwnProperty ( key ) ) {
653
653
_channel = connection . channels [ key ] ;
654
654
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
+
656
661
_mode_params = '' ;
657
662
658
663
if ( typeof _channel . modes === 'undefined' )
@@ -857,6 +862,9 @@ function clientConnect(socket) {
857
862
this . write ( "CAP REQ :message-tags\n" ) ;
858
863
this . messagetags = true ;
859
864
}
865
+ if ( lines [ n ] . trim ( ) . indexOf ( "away-notify" ) >= 0 ) {
866
+ this . write ( "CAP REQ :away-notify\n" ) ;
867
+ }
860
868
if ( this . messagetags && lines [ n ] . trim ( ) . indexOf ( "server-time" ) >= 0 ) {
861
869
this . write ( "CAP REQ :server-time\n" ) ;
862
870
}
@@ -885,17 +893,19 @@ function clientConnect(socket) {
885
893
this . nickpassword ;
886
894
887
895
const b = Buffer . from ( auth_str , 'utf8' ) ;
888
- let b64 = b . toString ( 'base64' ) ;
896
+ const b64 = b . toString ( 'base64' ) ;
889
897
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 ;
893
904
}
894
- if ( b64 . length > 0 ) {
895
- this . write ( 'AUTHENTICATE :' + b64 + '\n' ) ;
896
- } else {
905
+
906
+ if ( b64 . length === sliceOffset )
897
907
this . write ( 'AUTHENTICATE :+\n' ) ;
898
- }
908
+
899
909
continue ;
900
910
}
901
911
@@ -913,6 +923,9 @@ function clientConnect(socket) {
913
923
}
914
924
}
915
925
926
+ if ( data [ 1 ] == "900" ) {
927
+ this . account = data [ 4 ] ;
928
+ }
916
929
let s = data [ 1 ] ;
917
930
918
931
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) {
999
1012
_mode [ i ] == 'j' ) ) {
1000
1013
if ( _mode [ i ] == 'o' || _mode [ i ] == 'v' || _mode [ i ] == 'h' ) {
1001
1014
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 ] ) {
1003
1016
switch ( _mode [ i ] ) {
1004
1017
case 'o' :
1005
1018
_this_target = _mode_target [ _mode_count ] + "!" + ( curchan . userhosts [ c ] ?curchan . userhosts [ c ] :"*@*" ) ;
@@ -1014,7 +1027,7 @@ function clientConnect(socket) {
1014
1027
case 'v' :
1015
1028
_this_target = _mode_target [ _mode_count ] + "!" + ( curchan . userhosts [ c ] ?curchan . userhosts [ c ] :"*@*" ) ;
1016
1029
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 ) {
1018
1031
if ( curchan . names [ c ] . indexOf ( "%" ) == - 1 ) {
1019
1032
curchan . names [ c ] = "+" + curchan . names [ c ] ;
1020
1033
}
@@ -1039,7 +1052,7 @@ function clientConnect(socket) {
1039
1052
case 'h' :
1040
1053
_this_target = _mode_target [ _mode_count ] + "!" + ( curchan . userhosts [ c ] ?curchan . userhosts [ c ] :"*@*" ) ;
1041
1054
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 ) {
1043
1056
curchan . names [ c ] = "%" + curchan . names [ c ] ;
1044
1057
}
1045
1058
else
@@ -1073,21 +1086,21 @@ function clientConnect(socket) {
1073
1086
}
1074
1087
}
1075
1088
else {
1076
- _regex = new RegExp ( _mode [ i ] , "g" )
1089
+ _regex = new RegExp ( _mode [ i ] , "g" ) ;
1077
1090
if ( _sender == _target && _target == this . nick || _sender == "NickServ" && _target == this . nick || _sender == "OperServ" && _target == this . nick )
1078
1091
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 )
1080
1093
curchan . modes = curchan . modes . replace ( _regex , "" ) ;
1081
1094
if ( ( _target . indexOf ( "#" ) != - 1 || _target . indexOf ( "&" ) != - 1 ) && ( _mode [ i ] == 'o' || _mode [ i ] == 'k' || _mode [ i ] == 'v' || _mode [ i ] == 'h' || _mode [ i ] == 'l' ||
1082
1095
_mode [ i ] == 'e' || _mode [ i ] == 'b' || _mode [ i ] == 'I' || _mode [ i ] == 'q' || _mode [ i ] == 'f' ||
1083
1096
_mode [ i ] == 'j' ) ) {
1084
1097
if ( _mode [ i ] == 'o' || _mode [ i ] == 'v' || _mode [ i ] == 'h' ) {
1085
1098
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 ] ) {
1087
1100
switch ( _mode [ i ] ) {
1088
1101
case 'o' :
1089
1102
_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 ( / ( & | ~ | @ ) / , "" ) ;
1091
1104
if ( _mode_target [ _mode_count ] != this . nick && curchan . aop && curchan . aop . indexOf ( _this_target ) >= 0 && this . opmode ) {
1092
1105
curchan . aop . splice ( curchan . aop . indexOf ( _this_target ) , 1 ) ;
1093
1106
}
@@ -1180,13 +1193,13 @@ function clientConnect(socket) {
1180
1193
if ( this . channels [ __channel ] ) {
1181
1194
this . channels [ __channel ] . names . push ( _nick ) ;
1182
1195
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 ) {
1184
1197
this . write ( "MODE " + this . channels [ __channel ] . name + " +o " + _nick + "\n" ) ;
1185
1198
}
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 ) {
1187
1200
this . write ( "MODE " + this . channels [ __channel ] . name + " +h " + _nick + "\n" ) ;
1188
1201
}
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 ) {
1190
1203
this . write ( "MODE " + this . channels [ __channel ] . name + " +v " + _nick + "\n" ) ;
1191
1204
}
1192
1205
}
@@ -1226,7 +1239,7 @@ function clientConnect(socket) {
1226
1239
}
1227
1240
else if ( this . channels [ _channel ] ) {
1228
1241
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 )
1230
1243
break ;
1231
1244
this . channels [ _channel ] . names . splice ( x , 1 ) ;
1232
1245
}
@@ -1239,7 +1252,7 @@ function clientConnect(socket) {
1239
1252
}
1240
1253
else if ( this . channels [ _target ] ) {
1241
1254
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 )
1243
1256
break ;
1244
1257
this . channels [ _target ] . names . splice ( x , 1 ) ;
1245
1258
this . channels [ _target ] . userhosts . splice ( x , 1 ) ;
@@ -1250,7 +1263,7 @@ function clientConnect(socket) {
1250
1263
for ( key in this . channels ) {
1251
1264
if ( this . channels . hasOwnProperty ( key ) ) {
1252
1265
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 ) {
1254
1267
this . channels [ key ] . names . splice ( x , 1 ) ;
1255
1268
this . channels [ key ] . userhosts . splice ( x , 1 ) ;
1256
1269
break ;
@@ -1300,8 +1313,8 @@ function clientConnect(socket) {
1300
1313
for ( key in this . channels ) {
1301
1314
if ( this . channels . hasOwnProperty ( key ) ) {
1302
1315
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 ) : "" ) ;
1305
1318
this . channels [ key ] . names . splice ( x , 1 ) ;
1306
1319
this . channels [ key ] . names . push ( _statut + _new ) ;
1307
1320
break ;
0 commit comments