Skip to content

Commit 9d7a8ea

Browse files
committed
Update
1 parent bc3eb9b commit 9d7a8ea

File tree

3 files changed

+79
-69
lines changed

3 files changed

+79
-69
lines changed

lib/ClientConnect.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ class ClientConnect {
8484
this.client.messagetags = false;
8585
this.client.ircv3Monitor = false;
8686
this.client.ircv3_extendedjoin = false;
87-
this.client.quitBefore005 = null;
87+
88+
// Default is null, false is reconnecting, and true is disconnected before 005.
89+
this.client.preConnectionLogout = false;
8890

8991
// Temp Buffer
9092
this.client._buffer = '';
@@ -100,10 +102,10 @@ class ClientConnect {
100102

101103
let _reverse_ip = this.host;
102104
try {
103-
_reverse_ip = await reverse(this.host);
104-
} catch(e) {
105+
_reverse_ip = await reverse(this.host);
106+
} catch (e) {
105107
}
106-
if(global.WEBIRCSPECIAL) { // My server irc
108+
if (global.WEBIRCSPECIAL) { // My server irc
107109
let isIPv6 = this.client.host.includes(':');
108110
let ip = isIPv6 ? this.client.host.split(':').slice(0, 4).join(':') : this.client.host;
109111
let cleanIp = ip.replace(/:/g, '');
@@ -114,14 +116,14 @@ class ClientConnect {
114116

115117
this.client.write(webircMessage);
116118
}
117-
else if(global.SERVER_WEBIRCHASHIP && !global.SERVER_WEBIRCPROXY) {
118-
this.client.write('WEBIRC '+global.SERVER_WEBIRC+' '+this.client.user+' jbnc.'+iphash(this.client.hostonce)+" "+this.client.host+"\n");
119+
else if (global.SERVER_WEBIRCHASHIP && !global.SERVER_WEBIRCPROXY) {
120+
this.client.write('WEBIRC ' + global.SERVER_WEBIRC + ' ' + this.client.user + ' jbnc.' + iphash(this.client.hostonce) + " " + this.client.host + "\n");
119121
}
120-
else if(global.SERVER_WEBIRCHASHIP && global.SERVER_WEBIRCPROXY) {
121-
this.client.write('WEBIRC '+global.SERVER_WEBIRC+' '+this.client.user+' jbnc.'+iphash(this.client.host)+" "+this.client.host+"\n");
122+
else if (global.SERVER_WEBIRCHASHIP && global.SERVER_WEBIRCPROXY) {
123+
this.client.write('WEBIRC ' + global.SERVER_WEBIRC + ' ' + this.client.user + ' jbnc.' + iphash(this.client.host) + " " + this.client.host + "\n");
122124
}
123125
else
124-
this.client.write('WEBIRC '+global.SERVER_WEBIRC+' '+this.client.user+' '+_reverse_ip+" "+this.client.host+"\n");
126+
this.client.write('WEBIRC ' + global.SERVER_WEBIRC + ' ' + this.client.user + ' ' + _reverse_ip + " " + this.client.host + "\n");
125127
}
126128
if (this.client.serverpassword) {
127129
this.client.write('PASS ' + this.client.serverpassword + '\n');
@@ -134,7 +136,7 @@ class ClientConnect {
134136
});
135137
this.client.on('data', (d) => {
136138
let _d = this.client._buffer + d.toString();
137-
let lines = _d.toString().split('\n');
139+
let lines = _d.toString().split('\r\n');
138140
if (lines[lines.length - 1] !== '') {
139141
this.client._buffer = lines.pop();
140142
} else {
@@ -143,8 +145,8 @@ class ClientConnect {
143145
}
144146

145147
for (let n = 0; n < lines.length; n++) {
146-
if (this.client.quitBefore005) {
147-
console.log("detection du quit de Before005", this.client.quitBefore005);
148+
if (this.client.preConnectionLogout) {
149+
console.log("detection du quit avant Before005", this.client.preConnectionLogout);
148150
try {
149151
this.connections[this.client.hash].end();
150152
} catch (e) { }
@@ -311,7 +313,7 @@ class ClientConnect {
311313
break;
312314
case '005': // RPL_ISUPPORT
313315
this.client.connectbuf += lines[n] + "\n";
314-
this.client.quitBefore005 = false;
316+
this.client.preConnectionLogout = null;
315317
break;
316318
case '324': // RPL_CHANNELMODEIS
317319
case 'MODE':
@@ -878,6 +880,8 @@ class ClientConnect {
878880
}
879881
}
880882

883+
884+
881885
});
882886
this.client.on('close', () => {
883887
for (let x = 0; x < this.client.parents.length; x++) {

lib/ClientReconnect.js

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
class ClientReconnect {
55
constructor(socket, client) {
66
this.connections = client.connections;
7+
this.connection = null;
78
this.init(socket);
89
}
910

@@ -12,50 +13,51 @@ class ClientReconnect {
1213
if (socket.connected)
1314
_success = false;
1415
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);
1819
socket.connected = true;
1920
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: [] };
2223
newdevice = true;
2324
}
2425
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");
2728

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");
3031

31-
if (connection.ircv3Monitor)
32-
connection.write("MONITOR S\n");
32+
if (this.connection.ircv3Monitor)
33+
this.write(this.connection, "MONITOR S\n");
3334

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;
3738
}
3839
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");
4344
}
4445

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");
4647

4748
// 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];
5152

5253
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");
5556
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");
5758
} else {
5859
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`);
5961
continue;
6062
}
6163

@@ -83,65 +85,69 @@ class ClientReconnect {
8385
break;
8486
}
8587
}
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");
8789
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");
9092
}
9193
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);
9395
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);
9698
}
9799
}
98100

99101
for (let x = 0; x < _channel.names.length; x++) {
100102
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 + " :");
103105
if (global.DEBUG)
104-
console.log(":*jbnc 353 " + connection.nick + " = " + key + " :");
106+
console.log(":*jbnc 353 " + this.connection.nick + " = " + key + " :");
105107
}
106-
socket.write(_channel.names[x]);
108+
this.write(socket, _channel.names[x]);
107109
if (global.DEBUG)
108110
console.log(_channel.names[x]);
109111
if (x + 1 < _channel.names.length) {
110-
socket.write(" ");
112+
this.write(socket, " ");
111113
}
112114
}
113115
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");
116118
}
117119
}
118120

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");
120122
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);
122124

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);
127129
}
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`);
130132
}
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");
136138
}
137139
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");
139141

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 = '';
142144
}
143145
}
144146
}
147+
148+
write(type, line) {
149+
type.write(line);
150+
}
145151
}
146152

147153
module.exports = ClientReconnect;

lib/Server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,8 @@ class Server {
723723
// Track connection type
724724
socket.on('end', () => {
725725
console.log('Connection finished: socket');
726-
if (this.connections[socket.hash] && this.connections[socket.hash].quitBefore005 == null) {
727-
this.connections[socket.hash].quitBefore005 = true;
726+
if (this.connections[socket.hash] && this.connections[socket.hash].preConnectionLogout == false) {
727+
this.connections[socket.hash].preConnectionLogout = true;
728728
}
729729
});
730730
});

0 commit comments

Comments
 (0)