4
4
class ClientReconnect {
5
5
constructor ( socket , client ) {
6
6
this . connections = client . connections ;
7
+ this . connection = null ;
7
8
this . init ( socket ) ;
8
9
}
9
10
@@ -12,50 +13,51 @@ class ClientReconnect {
12
13
if ( socket . connected )
13
14
_success = false ;
14
15
if ( _success ) {
15
- let connection = this . connections [ socket . hash ] ;
16
- connection . parents [ connection . parents . length ] = socket ;
17
- clearTimeout ( connection . gone ) ;
16
+ this . connection = this . connections [ socket . hash ] ;
17
+ this . connection . parents [ this . connection . parents . length ] = socket ;
18
+ clearTimeout ( this . connection . gone ) ;
18
19
socket . connected = true ;
19
20
let newdevice = false ;
20
- if ( ! connection . buffers [ socket . clientbuffer ] ) {
21
- connection . buffers [ socket . clientbuffer ] = { data : '' , connected : true , privmsgnotice : [ ] } ;
21
+ if ( ! this . connection . buffers [ socket . clientbuffer ] ) {
22
+ this . connection . buffers [ socket . clientbuffer ] = { data : '' , connected : true , privmsgnotice : [ ] } ;
22
23
newdevice = true ;
23
24
}
24
25
else
25
- connection . buffers [ socket . clientbuffer ] . connected = true ;
26
- socket . write ( connection . connectbuf + "\n" ) ;
26
+ this . connection . buffers [ socket . clientbuffer ] . connected = true ;
27
+ this . write ( socket , this . connection . connectbuf + "\n" ) ;
27
28
28
- if ( connection . nick != socket . irc . nick )
29
- socket . write ( ":" + connection . nick_original + " NICK " + connection . nick + "\n" ) ;
29
+ if ( this . connection . nick != socket . irc . nick )
30
+ this . write ( socket , ":" + this . connection . nick_original + " NICK " + this . connection . nick + "\n" ) ;
30
31
31
- if ( connection . ircv3Monitor )
32
- connection . write ( "MONITOR S\n" ) ;
32
+ if ( this . connection . ircv3Monitor )
33
+ this . write ( this . connection , "MONITOR S\n" ) ;
33
34
34
- if ( ! connection . connected ) {
35
- connection . write ( "AWAY\n" ) ;
36
- connection . connected = true ;
35
+ if ( ! this . connection . connected ) {
36
+ this . write ( this . connection , "AWAY\n" ) ;
37
+ this . connection . connected = true ;
37
38
}
38
39
if ( newdevice ) {
39
- connection . write ( "LUSERS\n" ) ;
40
- socket . write ( ":*jbnc 375 " + connection . nick + " :- Message of the Day - \n" ) ;
41
- socket . write ( connection . motd + "\n" ) ;
42
- socket . write ( ":*jbnc 376 " + connection . nick + " :End of /MOTD command.\n" ) ;
40
+ this . write ( this . connection , "LUSERS\n" ) ;
41
+ this . write ( socket , ":*jbnc PRIVMSG " + this . connection . nick + " :Attaching you to the network \n" ) ;
42
+ this . write ( socket , this . connection . motd + "\n" ) ;
43
+ this . write ( socket , ":*jbnc 376 " + this . connection . nick + " :End of /MOTD command.\n" ) ;
43
44
}
44
45
45
- socket . write ( ":*jbnc PRIVMSG " + connection . nick + " :Attaching you to the network\n" ) ;
46
+ this . write ( socket , ":*jbnc PRIVMSG " + this . connection . nick + " :Attaching you to the network\n" ) ;
46
47
47
48
// Loop thru channels and send JOINs
48
- for ( let key in connection . channels ) {
49
- if ( Object . prototype . hasOwnProperty . call ( connection . channels , key ) ) {
50
- let _channel = connection . channels [ key ] ;
49
+ for ( let key in this . connection . channels ) {
50
+ if ( Object . prototype . hasOwnProperty . call ( this . connection . channels , key ) ) {
51
+ let _channel = this . connection . channels [ key ] ;
51
52
52
53
if ( _channel && _channel . name ) {
53
- if ( connection . ircv3_extendedjoin )
54
- socket . write ( "@time=" + new Date ( ) . toISOString ( ) + ";msgid=back :" + connection . nick + "!" + connection . ircuser + "@" + connection . host + " JOIN " + _channel . name + " " + ( connection . account ? connection . account : '*' ) + " :" + connection . realname + "\n" ) ;
54
+ if ( this . connection . ircv3_extendedjoin )
55
+ this . write ( socket , "@time=" + new Date ( ) . toISOString ( ) + ";msgid=back :" + this . connection . nick + "!" + this . connection . ircuser + "@" + this . connection . host + " JOIN " + _channel . name + " " + ( this . connection . account ? this . connection . account : '*' ) + " :" + this . connection . realname + "\n" ) ;
55
56
else
56
- socket . write ( "@time=" + new Date ( ) . toISOString ( ) + ";msgid=back :" + connection . nick + "!" + connection . ircuser + "@" + connection . host + " JOIN :" + _channel . name + "\n" ) ;
57
+ this . write ( socket , "@time=" + new Date ( ) . toISOString ( ) + ";msgid=back :" + this . connection . nick + "!" + this . connection . ircuser + "@" + this . connection . host + " JOIN :" + _channel . name + "\n" ) ;
57
58
} else {
58
59
console . error ( `${ parseInt ( Number ( new Date ( ) ) / 1000 ) } Probleme bug undefined on join : ${ JSON . stringify ( _channel ) } ` ) ;
60
+ //socket.write(`PRIVMSG #!bug-log! Bug du undefined on join - ${_channel.name}\n`);
59
61
continue ;
60
62
}
61
63
@@ -83,65 +85,69 @@ class ClientReconnect {
83
85
break ;
84
86
}
85
87
}
86
- socket . write ( ":*jbnc 324 " + connection . nick + " " + key + " +" + _channel . modes + " " + _mode_params + "\n" ) ;
88
+ this . write ( socket , ":*jbnc 324 " + this . connection . nick + " " + key + " +" + _channel . modes + " " + _mode_params + "\n" ) ;
87
89
if ( _channel . topic . length > 0 ) {
88
- socket . write ( ":*jbnc 332 " + connection . nick + " " + key + " :" + _channel . topic + "\n" ) ;
89
- socket . write ( ":*jbnc 333 " + connection . nick + " " + key + " " + _channel . topic_set + " " + _channel . topic_time + "\n" ) ;
90
+ this . write ( socket , ":*jbnc 332 " + this . connection . nick + " " + key + " :" + _channel . topic + "\n" ) ;
91
+ this . write ( socket , ":*jbnc 333 " + this . connection . nick + " " + key + " " + _channel . topic_set + " " + _channel . topic_time + "\n" ) ;
90
92
}
91
93
if ( global . DEBUG ) {
92
- console . log ( ":*jbnc 324 " + connection . nick + " " + key + " +" + _channel . modes + " " + _mode_params ) ;
94
+ console . log ( ":*jbnc 324 " + this . connection . nick + " " + key + " +" + _channel . modes + " " + _mode_params ) ;
93
95
if ( _channel . topic . length > 0 ) {
94
- console . log ( ":*jbnc 332 " + connection . nick + " " + key + " :" + _channel . topic ) ;
95
- console . log ( ":*jbnc 333 " + connection . nick + " " + key + " " + _channel . topic_set + " " + _channel . topic_time ) ;
96
+ console . log ( ":*jbnc 332 " + this . connection . nick + " " + key + " :" + _channel . topic ) ;
97
+ console . log ( ":*jbnc 333 " + this . connection . nick + " " + key + " " + _channel . topic_set + " " + _channel . topic_time ) ;
96
98
}
97
99
}
98
100
99
101
for ( let x = 0 ; x < _channel . names . length ; x ++ ) {
100
102
if ( x % 53 == 0 ) {
101
- socket . write ( "\n" ) ;
102
- socket . write ( ":*jbnc 353 " + connection . nick + " = " + key + " :" ) ;
103
+ this . write ( socket , "\n" ) ;
104
+ this . write ( socket , ":*jbnc 353 " + this . connection . nick + " = " + key + " :" ) ;
103
105
if ( global . DEBUG )
104
- console . log ( ":*jbnc 353 " + connection . nick + " = " + key + " :" ) ;
106
+ console . log ( ":*jbnc 353 " + this . connection . nick + " = " + key + " :" ) ;
105
107
}
106
- socket . write ( _channel . names [ x ] ) ;
108
+ this . write ( socket , _channel . names [ x ] ) ;
107
109
if ( global . DEBUG )
108
110
console . log ( _channel . names [ x ] ) ;
109
111
if ( x + 1 < _channel . names . length ) {
110
- socket . write ( " " ) ;
112
+ this . write ( socket , " " ) ;
111
113
}
112
114
}
113
115
if ( global . DEBUG )
114
- console . log ( "\n:*jbnc 366 " + connection . nick + " " + key + " :End of /NAMES list.\n" ) ;
115
- socket . write ( "\n:*jbnc 366 " + connection . nick + " " + key + " :End of /NAMES list.\n" ) ;
116
+ console . log ( "\n:*jbnc 366 " + this . connection . nick + " " + key + " :End of /NAMES list.\n" ) ;
117
+ this . write ( socket , "\n:*jbnc 366 " + this . connection . nick + " " + key + " :End of /NAMES list.\n" ) ;
116
118
}
117
119
}
118
120
119
- socket . write ( ":" + connection . nick + " MODE " + connection . nick + " :+" + connection . umode + "\n" ) ;
121
+ this . write ( socket , ":" + this . connection . nick + " MODE " + this . connection . nick + " :+" + this . connection . umode + "\n" ) ;
120
122
if ( global . DEBUG )
121
- console . log ( ":" + connection . nick + " MODE " + connection . nick + " :+" + connection . umode ) ;
123
+ console . log ( ":" + this . connection . nick + " MODE " + this . connection . nick + " :+" + this . connection . umode ) ;
122
124
123
- if ( global . MSG_REDISTRIBUTION && connection . messagetags && connection . buffers [ socket . clientbuffer ] && connection . buffers [ socket . clientbuffer ] . privmsgnotice && connection . buffers [ socket . clientbuffer ] . privmsgnotice . length > 0 ) {
124
- socket . write ( ":*jbnc PRIVMSG " + connection . nick + " :Retrieving all privmsgs/notices\n" ) ;
125
- for ( let x = 0 ; x < connection . buffers [ socket . clientbuffer ] . privmsgnotice . length ; x ++ ) {
126
- socket . write ( connection . buffers [ socket . clientbuffer ] . privmsgnotice [ x ] . line ) ;
125
+ if ( global . MSG_REDISTRIBUTION && this . connection . messagetags && this . connection . buffers [ socket . clientbuffer ] && this . connection . buffers [ socket . clientbuffer ] . privmsgnotice && this . connection . buffers [ socket . clientbuffer ] . privmsgnotice . length > 0 ) {
126
+ this . write ( socket , ":*jbnc PRIVMSG " + this . connection . nick + " :Retrieving all privmsgs/notices\n" ) ;
127
+ for ( let x = 0 ; x < this . connection . buffers [ socket . clientbuffer ] . privmsgnotice . length ; x ++ ) {
128
+ this . write ( socket , this . connection . buffers [ socket . clientbuffer ] . privmsgnotice [ x ] . line ) ;
127
129
}
128
- connection . buffers [ socket . clientbuffer ] . privmsgnotice . length = 0 ;
129
- socket . write ( `:*jbnc PRIVMSG ${ connection . nick } :End of retrieving all privmsgs/notices\n` ) ;
130
+ this . connection . buffers [ socket . clientbuffer ] . privmsgnotice . length = 0 ;
131
+ this . write ( socket , `:*jbnc PRIVMSG ${ this . connection . nick } :End of retrieving all privmsgs/notices\n` ) ;
130
132
}
131
- else if ( ! global . MSG_REDISTRIBUTION && connection . buffers [ socket . clientbuffer ] && connection . buffers [ socket . clientbuffer ] . data && connection . buffers [ socket . clientbuffer ] . data . length > 0 ) {
132
- socket . write ( ":*jbnc PRIVMSG " + connection . nick + " :Retrieving all messages\n" ) ;
133
- socket . write ( connection . buffers [ socket . clientbuffer ] . data + "\n" ) ;
134
- connection . buffers [ socket . clientbuffer ] . data = '' ;
135
- socket . write ( ":*jbnc PRIVMSG " + connection . nick + " :End of retrieving all messages\n" ) ;
133
+ else if ( ! global . MSG_REDISTRIBUTION && this . connection . buffers [ socket . clientbuffer ] && this . connection . buffers [ socket . clientbuffer ] . data && this . connection . buffers [ socket . clientbuffer ] . data . length > 0 ) {
134
+ this . write ( socket , ":*jbnc PRIVMSG " + this . connection . nick + " :Retrieving all messages\n" ) ;
135
+ this . write ( socket , this . connection . buffers [ socket . clientbuffer ] . data + "\n" ) ;
136
+ this . connection . buffers [ socket . clientbuffer ] . data = '' ;
137
+ this . write ( socket , ":*jbnc PRIVMSG " + this . connection . nick + " :End of retrieving all messages\n" ) ;
136
138
}
137
139
else
138
- socket . write ( ":*jbnc PRIVMSG " + connection . nick + " :There is no new message\n" ) ;
140
+ this . write ( socket , ":*jbnc PRIVMSG " + this . connection . nick + " :There is no new message\n" ) ;
139
141
140
- if ( connection . buffers [ socket . clientbuffer ] && connection . buffers [ socket . clientbuffer ] . data && connection . buffers [ socket . clientbuffer ] . data . length > 0 ) {
141
- connection . buffers [ socket . clientbuffer ] . data = '' ;
142
+ if ( this . connection . buffers [ socket . clientbuffer ] && this . connection . buffers [ socket . clientbuffer ] . data && this . connection . buffers [ socket . clientbuffer ] . data . length > 0 ) {
143
+ this . connection . buffers [ socket . clientbuffer ] . data = '' ;
142
144
}
143
145
}
144
146
}
147
+
148
+ write ( type , line ) {
149
+ type . write ( line ) ;
150
+ }
145
151
}
146
152
147
153
module . exports = ClientReconnect ;
0 commit comments