@@ -68,17 +68,16 @@ function iphash(data) {
68
68
return crypto . createHash ( 'md5' ) . update ( data ) . digest ( 'hex' ) . substr ( 0 , 6 ) ;
69
69
}
70
70
71
- String . prototype . hexEncode = function ( ) {
72
- var hex , i ;
73
-
74
- var result = "" ;
75
- for ( i = 0 ; i < this . length ; i ++ ) {
76
- hex = this . charCodeAt ( i ) . toString ( 16 ) ;
77
- result += ( "000" + hex ) . slice ( - 4 ) ;
78
- }
79
-
80
- return result
81
- }
71
+ function generateMD5AndGetSubstring ( data ) {
72
+ const md5Hash = crypto . createHash ( 'md5' ) . update ( data ) . digest ( 'hex' ) ;
73
+ // Retrieve the first 4 and the last 4 characters of the hash
74
+ const first4Characters = md5Hash . slice ( 0 , 4 ) ;
75
+ const last4Characters = md5Hash . slice ( - 4 ) ;
76
+ return {
77
+ first4 : first4Characters ,
78
+ last4 : last4Characters
79
+ } ;
80
+ }
82
81
// Bouncer Server
83
82
let server ;
84
83
let doServer ;
@@ -249,7 +248,7 @@ server = doServer(tlsOptions,function(socket) {
249
248
}
250
249
else if ( commands [ 1 ] ) {
251
250
this . irc . nick = commands [ 1 ] . trim ( ) ;
252
- if ( false && this . irc . user ) {
251
+ if ( this . irc . user ) {
253
252
this . hash = hash ( this . irc . nick + this . irc . user + this . irc . password + this . irc . server + this . irc . port . toString ( ) ) ;
254
253
if ( connections [ socket . hash ] ) {
255
254
clientReconnect ( this ) ;
@@ -638,6 +637,10 @@ server = doServer(tlsOptions,function(socket) {
638
637
console . log ( err ) ;
639
638
this . end ( ) ;
640
639
} ) ;
640
+ socket . on ( 'end' , function ( ) {
641
+ console . log ( 'Connection finished: socket' ) ;
642
+ return ;
643
+ } ) ;
641
644
} ) ;
642
645
643
646
// IRC Client
@@ -846,9 +849,16 @@ function clientConnect(socket) {
846
849
} catch ( e ) {
847
850
_reverse_ip = this . host ;
848
851
}
849
- if ( false ) { // My server irc
850
- _vhost = iphash ( this . nick ) ;
851
- this . write ( 'WEBIRC ' + SERVER_WEBIRC + ' ' + this . user + ' galaxy-' + this . host + '.cloud-' + ( _vhost ?_vhost :'0' ) + '.jbnc ' + this . host + ' :secure\n' ) ;
852
+ if ( false ) { // My server irc
853
+ let isIPv6 = this . host . includes ( ':' ) ;
854
+ let ip = isIPv6 ? this . host . split ( ':' ) . slice ( 0 , 4 ) . join ( ':' ) : this . host ;
855
+ let cleanIp = ip . replace ( / : / g, '' ) ;
856
+ let md5Hash = generateMD5AndGetSubstring ( cleanIp ) ;
857
+ let vhost = iphash ( this . accountsasl ) || '0' ;
858
+
859
+ let webircMessage = `WEBIRC ${ SERVER_WEBIRC } ${ this . user } galaxy-${ cleanIp } .ip${ md5Hash . first4 } ${ md5Hash . last4 } .cloud-${ vhost } .jbnc ${ this . host } :secure\n` ;
860
+
861
+ this . write ( webircMessage ) ;
852
862
}
853
863
else if ( SERVER_WEBIRCHASHIP && ! SERVER_WEBIRCPROXY ) {
854
864
this . write ( 'WEBIRC ' + SERVER_WEBIRC + ' ' + this . user + ' jbnc.' + iphash ( this . hostonce ) + " " + this . host + "\n" ) ;
@@ -1072,60 +1082,64 @@ function clientConnect(socket) {
1072
1082
_mode [ i ] == 'e' || _mode [ i ] == 'b' || _mode [ i ] == 'I' || _mode [ i ] == 'q' || _mode [ i ] == 'f' ||
1073
1083
_mode [ i ] == 'j' ) ) {
1074
1084
if ( _mode [ i ] == 'o' || _mode [ i ] == 'v' || _mode [ i ] == 'h' ) {
1075
- for ( c = 0 ; c < curchan . names . length ; c ++ ) {
1076
- if ( curchan . names [ c ] . replace ( / ( & | ~ | @ | % | \+ ) / , "" ) == _mode_target [ _mode_count ] ) {
1077
- switch ( _mode [ i ] ) {
1078
- case 'o' :
1079
- _this_target = _mode_target [ _mode_count ] + "!" + ( curchan . userhosts [ c ] ?curchan . userhosts [ c ] :"*@*" ) ;
1080
- if ( curchan . names [ c ] . indexOf ( "@" ) == - 1 ) {
1081
- curchan . names [ c ] = "@" + curchan . names [ c ] ;
1082
- if ( _mode_target [ _mode_count ] != this . nick && curchan . aop && curchan . aop . indexOf ( _this_target ) < 0 && this . opmode ) {
1083
- curchan . aop . push ( _this_target ) ;
1085
+ if ( curchan && curchan . names ) {
1086
+ for ( c = 0 ; c < curchan . names . length ; c ++ ) {
1087
+ if ( curchan . names [ c ] . replace ( / ( & | ~ | @ | % | \+ ) / , "" ) == _mode_target [ _mode_count ] ) {
1088
+ switch ( _mode [ i ] ) {
1089
+ case 'o' :
1090
+ _this_target = _mode_target [ _mode_count ] + "!" + ( curchan . userhosts [ c ] ?curchan . userhosts [ c ] :"*@*" ) ;
1091
+ if ( curchan . names [ c ] . indexOf ( "@" ) == - 1 ) {
1092
+ curchan . names [ c ] = "@" + curchan . names [ c ] ;
1093
+ if ( _mode_target [ _mode_count ] != this . nick && curchan . aop && curchan . aop . indexOf ( _this_target ) < 0 && this . opmode ) {
1094
+ curchan . aop . push ( _this_target ) ;
1095
+ }
1084
1096
}
1085
- }
1086
- if ( _mode_target [ _mode_count ] == this . nick ) curchan . isop = true ;
1087
- break ;
1088
- case 'v' :
1089
- _this_target = _mode_target [ _mode_count ] + "!" + ( curchan . userhosts [ c ] ?curchan . userhosts [ c ] :"*@*" ) ;
1090
- if ( curchan . names [ c ] . indexOf ( "+" ) == - 1 ) {
1091
- if ( curchan . names [ c ] . indexOf ( "&" ) == - 1 || curchan . names [ c ] . indexOf ( "~" ) == - 1 || curchan . names [ c ] . indexOf ( "@" ) == - 1 ) {
1092
- if ( curchan . names [ c ] . indexOf ( "%" ) == - 1 ) {
1093
- curchan . names [ c ] = "+" + curchan . names [ c ] ;
1097
+ if ( _mode_target [ _mode_count ] == this . nick ) curchan . isop = true ;
1098
+ break ;
1099
+ case 'v' :
1100
+ _this_target = _mode_target [ _mode_count ] + "!" + ( curchan . userhosts [ c ] ?curchan . userhosts [ c ] :"*@*" ) ;
1101
+ if ( curchan . names [ c ] . indexOf ( "+" ) == - 1 ) {
1102
+ if ( curchan . names [ c ] . indexOf ( "&" ) == - 1 || curchan . names [ c ] . indexOf ( "~" ) == - 1 || curchan . names [ c ] . indexOf ( "@" ) == - 1 ) {
1103
+ if ( curchan . names [ c ] . indexOf ( "%" ) == - 1 ) {
1104
+ curchan . names [ c ] = "+" + curchan . names [ c ] ;
1105
+ }
1106
+ else {
1107
+ curchan . names [ c ] = curchan . names [ c ] . substr ( 0 , 1 ) + "+" + curchan . names [ c ] . substr ( 1 ) ;
1108
+ }
1094
1109
}
1095
1110
else {
1096
- curchan . names [ c ] = curchan . names [ c ] . substr ( 0 , 1 ) + "+" + curchan . names [ c ] . substr ( 1 ) ;
1111
+ if ( curchan . names [ c ] . indexOf ( "%" ) == - 1 ) {
1112
+ curchan . names [ c ] = curchan . names [ c ] . substr ( 0 , 1 ) + "+" + curchan . names [ c ] . substr ( 1 ) ;
1113
+ }
1114
+ else {
1115
+ curchan . names [ c ] = curchan . names [ c ] . substr ( 0 , 2 ) + "+" + curchan . names [ c ] . substr ( 2 ) ;
1116
+ }
1117
+ }
1118
+ if ( _mode_target [ _mode_count ] != this . nick && curchan . aov && curchan . aov . indexOf ( _this_target ) < 0 && this . opmode ) {
1119
+ curchan . aov . push ( _mode_target [ _this_target ] ) ;
1097
1120
}
1098
1121
}
1099
- else {
1100
- if ( curchan . names [ c ] . indexOf ( "%" ) == - 1 ) {
1101
- curchan . names [ c ] = curchan . names [ c ] . substr ( 0 , 1 ) + "+" + curchan . names [ c ] . substr ( 1 ) ;
1122
+ if ( _mode_target [ _mode_count ] == this . nick ) curchan . isvoice = true ;
1123
+ break ;
1124
+ case 'h' :
1125
+ _this_target = _mode_target [ _mode_count ] + "!" + ( curchan . userhosts [ c ] ?curchan . userhosts [ c ] :"*@*" ) ;
1126
+ if ( curchan . names [ c ] . indexOf ( "%" ) == - 1 ) {
1127
+ if ( curchan . names [ c ] . indexOf ( "&" ) == - 1 || curchan . names [ c ] . indexOf ( "~" ) == - 1 || curchan . names [ c ] . indexOf ( "@" ) == - 1 ) {
1128
+ curchan . names [ c ] = "%" + curchan . names [ c ] ;
1102
1129
}
1103
- else {
1104
- curchan . names [ c ] = curchan . names [ c ] . substr ( 0 , 2 ) + "+" + curchan . names [ c ] . substr ( 2 ) ;
1130
+ else
1131
+ curchan . names [ c ] = curchan . names [ c ] . substr ( 0 , 1 ) + "%" + curchan . names [ c ] . substr ( 1 ) ;
1132
+ if ( _mode_target [ _mode_count ] != this . nick && curchan . aoh && curchan . aoh . indexOf ( _this_target ) < 0 && this . opmode ) {
1133
+ curchan . aoh . push ( _mode_target [ _this_target ] ) ;
1105
1134
}
1106
1135
}
1107
- if ( _mode_target [ _mode_count ] != this . nick && curchan . aov && curchan . aov . indexOf ( _this_target ) < 0 && this . opmode ) {
1108
- curchan . aov . push ( _mode_target [ _this_target ] ) ;
1109
- }
1110
- }
1111
- if ( _mode_target [ _mode_count ] == this . nick ) curchan . isvoice = true ;
1112
- break ;
1113
- case 'h' :
1114
- _this_target = _mode_target [ _mode_count ] + "!" + ( curchan . userhosts [ c ] ?curchan . userhosts [ c ] :"*@*" ) ;
1115
- if ( curchan . names [ c ] . indexOf ( "%" ) == - 1 ) {
1116
- if ( curchan . names [ c ] . indexOf ( "&" ) == - 1 || curchan . names [ c ] . indexOf ( "~" ) == - 1 || curchan . names [ c ] . indexOf ( "@" ) == - 1 ) {
1117
- curchan . names [ c ] = "%" + curchan . names [ c ] ;
1118
- }
1119
- else
1120
- curchan . names [ c ] = curchan . names [ c ] . substr ( 0 , 1 ) + "%" + curchan . names [ c ] . substr ( 1 ) ;
1121
- if ( _mode_target [ _mode_count ] != this . nick && curchan . aoh && curchan . aoh . indexOf ( _this_target ) < 0 && this . opmode ) {
1122
- curchan . aoh . push ( _mode_target [ _this_target ] ) ;
1123
- }
1124
- }
1125
- if ( _mode_target [ _mode_count ] == this . nick ) curchan . ishop = true ;
1126
- break ;
1136
+ if ( _mode_target [ _mode_count ] == this . nick ) curchan . ishop = true ;
1137
+ break ;
1138
+ }
1127
1139
}
1128
1140
}
1141
+ } else {
1142
+ console . error ( "curchan or curchan.names is undefined." ) ;
1129
1143
}
1130
1144
_mode_count ++ ;
1131
1145
continue ;
@@ -1156,35 +1170,39 @@ function clientConnect(socket) {
1156
1170
_mode [ i ] == 'e' || _mode [ i ] == 'b' || _mode [ i ] == 'I' || _mode [ i ] == 'q' || _mode [ i ] == 'f' ||
1157
1171
_mode [ i ] == 'j' ) ) {
1158
1172
if ( _mode [ i ] == 'o' || _mode [ i ] == 'v' || _mode [ i ] == 'h' ) {
1159
- for ( c = 0 ; c < curchan . names . length ; c ++ ) {
1160
- if ( curchan . names [ c ] . replace ( / ( & | ~ | @ | % | \+ ) / , "" ) == _mode_target [ _mode_count ] ) {
1161
- switch ( _mode [ i ] ) {
1162
- case 'o' :
1163
- _this_target = _mode_target [ _mode_count ] + "!" + ( curchan . userhosts [ c ] ?curchan . userhosts [ c ] :"*@*" ) ;
1164
- curchan . names [ c ] = curchan . names [ c ] . replace ( / ( & | ~ | @ ) / , "" ) ;
1165
- if ( _mode_target [ _mode_count ] != this . nick && curchan . aop && curchan . aop . indexOf ( _this_target ) >= 0 && this . opmode ) {
1166
- curchan . aop . splice ( curchan . aop . indexOf ( _this_target ) , 1 ) ;
1167
- }
1168
- if ( _mode_target [ _mode_count ] == this . nick ) this . isop = false ;
1169
- break ;
1170
- case 'v' :
1171
- _this_target = _mode_target [ _mode_count ] + "!" + ( curchan . userhosts [ c ] ?curchan . userhosts [ c ] :"*@*" ) ;
1172
- curchan . names [ c ] = curchan . names [ c ] . replace ( "+" , "" ) ;
1173
- if ( _mode_target [ _mode_count ] != this . nick && curchan . aov && curchan . aov . indexOf ( _this_target ) >= 0 && this . opmode ) {
1174
- curchan . aov . splice ( curchan . aov . indexOf ( _this_target ) , 1 ) ;
1175
- }
1176
- if ( _mode_target [ _mode_count ] == this . nick ) this . isvoice = false ;
1177
- break ;
1178
- case 'h' :
1179
- _this_target = _mode_target [ _mode_count ] + "!" + ( curchan . userhosts [ c ] ?curchan . userhosts [ c ] :"*@*" ) ;
1180
- curchan . names [ c ] = curchan . names [ c ] . replace ( "%" , "" ) ;
1181
- if ( _mode_target [ _mode_count ] != this . nick && curchan . aoh && curchan . aoh . indexOf ( _this_target ) >= 0 && this . opmode ) {
1182
- curchan . aoh . splice ( curchan . aoh . indexOf ( _this_target ) , 1 ) ;
1183
- }
1184
- if ( _mode_target [ _mode_count ] == this . nick ) this . ishop = false ;
1185
- break ;
1173
+ if ( curchan && curchan . names ) {
1174
+ for ( c = 0 ; c < curchan . names . length ; c ++ ) {
1175
+ if ( curchan . names [ c ] . replace ( / ( & | ~ | @ | % | \+ ) / , "" ) == _mode_target [ _mode_count ] ) {
1176
+ switch ( _mode [ i ] ) {
1177
+ case 'o' :
1178
+ _this_target = _mode_target [ _mode_count ] + "!" + ( curchan . userhosts [ c ] ?curchan . userhosts [ c ] :"*@*" ) ;
1179
+ curchan . names [ c ] = curchan . names [ c ] . replace ( / ( & | ~ | @ ) / , "" ) ;
1180
+ if ( _mode_target [ _mode_count ] != this . nick && curchan . aop && curchan . aop . indexOf ( _this_target ) >= 0 && this . opmode ) {
1181
+ curchan . aop . splice ( curchan . aop . indexOf ( _this_target ) , 1 ) ;
1182
+ }
1183
+ if ( _mode_target [ _mode_count ] == this . nick ) this . isop = false ;
1184
+ break ;
1185
+ case 'v' :
1186
+ _this_target = _mode_target [ _mode_count ] + "!" + ( curchan . userhosts [ c ] ?curchan . userhosts [ c ] :"*@*" ) ;
1187
+ curchan . names [ c ] = curchan . names [ c ] . replace ( "+" , "" ) ;
1188
+ if ( _mode_target [ _mode_count ] != this . nick && curchan . aov && curchan . aov . indexOf ( _this_target ) >= 0 && this . opmode ) {
1189
+ curchan . aov . splice ( curchan . aov . indexOf ( _this_target ) , 1 ) ;
1190
+ }
1191
+ if ( _mode_target [ _mode_count ] == this . nick ) this . isvoice = false ;
1192
+ break ;
1193
+ case 'h' :
1194
+ _this_target = _mode_target [ _mode_count ] + "!" + ( curchan . userhosts [ c ] ?curchan . userhosts [ c ] :"*@*" ) ;
1195
+ curchan . names [ c ] = curchan . names [ c ] . replace ( "%" , "" ) ;
1196
+ if ( _mode_target [ _mode_count ] != this . nick && curchan . aoh && curchan . aoh . indexOf ( _this_target ) >= 0 && this . opmode ) {
1197
+ curchan . aoh . splice ( curchan . aoh . indexOf ( _this_target ) , 1 ) ;
1198
+ }
1199
+ if ( _mode_target [ _mode_count ] == this . nick ) this . ishop = false ;
1200
+ break ;
1201
+ }
1186
1202
}
1187
1203
}
1204
+ } else {
1205
+ console . error ( "curchan or curchan.names is undefined." ) ;
1188
1206
}
1189
1207
_mode_count ++ ;
1190
1208
continue ;
@@ -1230,28 +1248,30 @@ function clientConnect(socket) {
1230
1248
__channel = _channel . toLowerCase ( ) ;
1231
1249
if ( _nick == this . nick ) {
1232
1250
if ( ! this . channels [ __channel ] ) {
1233
- this . channels [ __channel ] = { } ;
1234
- this . channels [ __channel ] . modes = '' ;
1235
- this . channels [ __channel ] . topic = '' ;
1236
- this . channels [ __channel ] . topic_set = '' ;
1237
- this . channels [ __channel ] . topic_time = 0 ;
1238
- this . channels [ __channel ] . key = null ;
1239
- this . channels [ __channel ] . limit = null ;
1240
- this . channels [ __channel ] . forward = null ;
1241
- this . channels [ __channel ] . throttle = null ;
1242
- this . channels [ __channel ] . names = [ ] ;
1243
- this . channels [ __channel ] . userhosts = [ ] ;
1244
- this . channels [ __channel ] . name = _channel ;
1245
- this . channels [ __channel ] . aop = [ ] ;
1246
- this . channels [ __channel ] . aoh = [ ] ;
1247
- this . channels [ __channel ] . aov = [ ] ;
1248
- this . channels [ __channel ] . isop = false ;
1249
- this . channels [ __channel ] . ishop = false ;
1250
- this . channels [ __channel ] . isvoice = false ;
1251
+ this . channels [ __channel ] = {
1252
+ modes :'' ,
1253
+ topic :'' ,
1254
+ topic_set :'' ,
1255
+ topic_time :0 ,
1256
+ key :null ,
1257
+ limit :null ,
1258
+ forward :null ,
1259
+ throttle :null ,
1260
+ names :[ ] ,
1261
+ userhosts :[ ] ,
1262
+ name :_channel ,
1263
+ aop :[ ] ,
1264
+ aoh :[ ] ,
1265
+ aov :[ ] ,
1266
+ isop :false ,
1267
+ ishop :false ,
1268
+ isvoice :false
1269
+ } ;
1251
1270
}
1252
1271
if ( this . channels [ __channel ] ) {
1253
1272
this . channels [ __channel ] . name = _channel ;
1254
1273
}
1274
+ this . write ( `MODE ${ _channel } \n` ) ;
1255
1275
}
1256
1276
else {
1257
1277
if ( this . channels [ __channel ] ) {
@@ -1447,6 +1467,10 @@ function clientConnect(socket) {
1447
1467
connection . on ( 'error' , function ( err ) {
1448
1468
this . end ( ) ;
1449
1469
} ) ;
1470
+ connection . on ( 'end' , function ( ) {
1471
+ console . log ( 'Connection finished : connection' ) ;
1472
+ return ;
1473
+ } ) ;
1450
1474
}
1451
1475
else {
1452
1476
socket . end ( ) ;
0 commit comments