fix: STARTTLS had some nick issues
This commit is contained in:
@@ -108,6 +108,7 @@ class WTVIRC {
|
|||||||
this.clientpeak = 0;
|
this.clientpeak = 0;
|
||||||
this.globalpeak = 0;
|
this.globalpeak = 0;
|
||||||
this.socketpeak = 0;
|
this.socketpeak = 0;
|
||||||
|
this.max_message_len = 512; // IRC Standard maximum message length
|
||||||
this.totalConnections = 0;
|
this.totalConnections = 0;
|
||||||
this.supported_channel_modes = "Ibe,k,l,CNOQRSTVZcimnprt";
|
this.supported_channel_modes = "Ibe,k,l,CNOQRSTVZcimnprt";
|
||||||
this.supported_user_modes = "BRZciorswxz";
|
this.supported_user_modes = "BRZciorswxz";
|
||||||
@@ -202,7 +203,6 @@ class WTVIRC {
|
|||||||
await this.initializeSocket(socket);
|
await this.initializeSocket(socket);
|
||||||
socket.emit('data', firstChunk.toString('ascii'));
|
socket.emit('data', firstChunk.toString('ascii'));
|
||||||
socket.resume();
|
socket.resume();
|
||||||
this.clients.push(socket);
|
|
||||||
this.clientpeak = Math.max(this.clientpeak, this.clients.length);
|
this.clientpeak = Math.max(this.clientpeak, this.clients.length);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,7 @@ class WTVIRC {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async initializeSocket(socket, secure = false) {
|
async initializeSocket(socket, secure = false, oldSocket = null) {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
// debug output for socket data
|
// debug output for socket data
|
||||||
const originalWrite = socket.write;
|
const originalWrite = socket.write;
|
||||||
@@ -230,22 +230,40 @@ class WTVIRC {
|
|||||||
return originalWrite.apply(socket, args);
|
return originalWrite.apply(socket, args);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.registered = false;
|
if (oldSocket) {
|
||||||
socket.nickname = '';
|
socket.registered = oldSocket.registered;
|
||||||
socket.username = '';
|
socket.nickname = oldSocket.nickname;
|
||||||
socket.isserver = false;
|
socket.username = oldSocket.username;
|
||||||
socket.is_srv_authorized = false;
|
socket.isserver = oldSocket.isserver;
|
||||||
socket.signedoff = false;
|
socket.is_srv_authorized = oldSocket.is_srv_authorized;
|
||||||
socket.hostname_resolved = false;
|
socket.signedoff = oldSocket.signedoff;
|
||||||
socket.realhost = socket.remoteAddress;
|
socket.hostname_resolved = oldSocket.hostname_resolved;
|
||||||
socket.upgrading_to_tls = false;
|
socket.realhost = oldSocket.realhost;
|
||||||
socket.client_version = '';
|
socket.upgrading_to_tls = false;
|
||||||
socket.client_caps = [];
|
socket.client_version = oldSocket.client_version;
|
||||||
this.filterHostname(socket, socket.remoteAddress);
|
socket.client_caps = oldSocket.client_caps || [];
|
||||||
socket.timestamp = this.getDate();
|
socket.host = oldSocket.host;
|
||||||
socket.secure = secure;
|
socket.timestamp = oldSocket.timestamp;
|
||||||
socket.uniqueId = `${this.serverId}${this.generateUniqueId(socket)}`;
|
socket.secure = secure;
|
||||||
|
socket.uniqueId = oldSocket.uniqueId;
|
||||||
|
} else {
|
||||||
|
socket.registered = false;
|
||||||
|
socket.nickname = '';
|
||||||
|
socket.username = '';
|
||||||
|
socket.isserver = false;
|
||||||
|
socket.is_srv_authorized = false;
|
||||||
|
socket.signedoff = false;
|
||||||
|
socket.hostname_resolved = false;
|
||||||
|
socket.realhost = socket.remoteAddress;
|
||||||
|
socket.upgrading_to_tls = false;
|
||||||
|
socket.client_version = '';
|
||||||
|
socket.client_caps = [];
|
||||||
|
socket.host = this.filterHostname(socket, socket.remoteAddress);
|
||||||
|
socket.timestamp = this.getDate();
|
||||||
|
socket.secure = secure;
|
||||||
|
socket.uniqueId = `${this.serverId}${this.generateUniqueId(socket)}`;
|
||||||
|
}
|
||||||
await this.doInitialHandshake(socket);
|
await this.doInitialHandshake(socket);
|
||||||
|
|
||||||
socket.on('data', async data => {
|
socket.on('data', async data => {
|
||||||
@@ -1165,46 +1183,12 @@ class WTVIRC {
|
|||||||
secureSocket.on('secure', async () => {
|
secureSocket.on('secure', async () => {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
console.log('Secure connection established');
|
console.log('Secure connection established');
|
||||||
}
|
|
||||||
if (this.debug) {
|
|
||||||
const originalWrite = secureSocket.write;
|
|
||||||
secureSocket.write = function (...args) {
|
|
||||||
var log_args = args.map(arg => {
|
|
||||||
if (typeof arg === 'string') {
|
|
||||||
return arg.replace(/\r\n/g, '').replace(/\n/g, '');
|
|
||||||
}
|
|
||||||
return arg;
|
|
||||||
});
|
|
||||||
console.log('<', ...log_args);
|
|
||||||
return originalWrite.apply(secureSocket, args);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
socket.removeAllListeners('error');
|
socket.removeAllListeners('error');
|
||||||
secureSocket.registered = socket.registered;
|
await this.initializeSocket(secureSocket, true, socket);
|
||||||
secureSocket.nickname = socket.nickname
|
// Remove the original socket from clients
|
||||||
secureSocket.username = socket.username
|
this.clients = this.clients.filter(c => c !== socket);
|
||||||
secureSocket.isserver = socket.isserver
|
this.clientpeak = Math.max(this.clientpeak, this.clients.length);
|
||||||
secureSocket.is_srv_authorized = socket.is_srv_authorized
|
|
||||||
secureSocket.signedoff = socket.signedoff
|
|
||||||
secureSocket.client_version = socket.client_version
|
|
||||||
secureSocket.client_caps = socket.client_caps || [];
|
|
||||||
secureSocket.hostname_resolved = socket.hostname_resolved;
|
|
||||||
secureSocket.realhost = socket.realhost
|
|
||||||
secureSocket.upgrading_to_tls = false;
|
|
||||||
secureSocket.host = socket.host;
|
|
||||||
secureSocket.timestamp = socket.timestamp;
|
|
||||||
secureSocket.secure = true;
|
|
||||||
secureSocket.uniqueId = socket.uniqueId;
|
|
||||||
// Push the secure socket to clients
|
|
||||||
this.clients.push(secureSocket);
|
|
||||||
this.clientpeak = Math.max(this.clientpeak, this.clients.length);
|
|
||||||
secureSocket.on('data', async data => {
|
|
||||||
await this.processSocketData(secureSocket, data);
|
|
||||||
});
|
|
||||||
secureSocket.on('end', () => {
|
|
||||||
this.terminateSession(secureSocket, false);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
secureSocket.resume();
|
secureSocket.resume();
|
||||||
} else {
|
} else {
|
||||||
@@ -1414,13 +1398,17 @@ class WTVIRC {
|
|||||||
socket.write(`:${this.servername} 331 ${socket.nickname} ${channel} :${topic}\r\n`);
|
socket.write(`:${this.servername} 331 ${socket.nickname} ${channel} :${topic}\r\n`);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "AWAY":
|
case 'AWAY':
|
||||||
if (!socket.registered) {
|
if (!socket.registered) {
|
||||||
socket.write(`:${this.servername} 451 ${socket.uniqueId} ${command} :You have not registered\r\n`);
|
socket.write(`:${this.servername} 451 ${socket.uniqueId} ${command} :You have not registered\r\n`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this.usertimestamps.set(socket.nickname, this.getDate());
|
this.usertimestamps.set(socket.nickname, this.getDate());
|
||||||
if (params.length > 0) {
|
if (params.length > 0) {
|
||||||
|
if (params.length > this.awaylen) {
|
||||||
|
socket.write(`:${this.servername} 417 ${socket.nickname} ${channel} :Away message is too long\r\n`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
socket.write(`:${this.servername} 306 ${socket.nickname} :You are now marked as away\r\n`);
|
socket.write(`:${this.servername} 306 ${socket.nickname} :You are now marked as away\r\n`);
|
||||||
let awayMsg = params.join(' ');
|
let awayMsg = params.join(' ');
|
||||||
if (awayMsg.startsWith(':')) {
|
if (awayMsg.startsWith(':')) {
|
||||||
@@ -1731,13 +1719,11 @@ class WTVIRC {
|
|||||||
if (new_nickname.length > this.nicklen) {
|
if (new_nickname.length > this.nicklen) {
|
||||||
socket.write(`:${this.servername} 432 * ${new_nickname} :Erroneus nickname (too long)\r\n`);
|
socket.write(`:${this.servername} 432 * ${new_nickname} :Erroneus nickname (too long)\r\n`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (this.nicknames.size > 0) {
|
if (this.findUser(new_nickname)) {
|
||||||
var result = Array.from(this.nicknames.keys()).find(s => this.nicknames.get(s).toLowerCase() === new_nickname.toLowerCase());
|
console.log(this.findUser(new_nickname))
|
||||||
if (result) {
|
socket.write(`:${this.servername} 433 * ${new_nickname} :Nickname is already in use\r\n`);
|
||||||
socket.write(`:${this.servername} 433 * ${new_nickname} :Nickname is already in use\r\n`);
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (const prefix of this.channelprefixes) {
|
for (const prefix of this.channelprefixes) {
|
||||||
if (new_nickname.startsWith(prefix)) {
|
if (new_nickname.startsWith(prefix)) {
|
||||||
@@ -1780,12 +1766,6 @@ class WTVIRC {
|
|||||||
this.nicknames.set(socket, socket.nickname);
|
this.nicknames.set(socket, socket.nickname);
|
||||||
if (socket.nickname && socket.nickname !== new_nickname) {
|
if (socket.nickname && socket.nickname !== new_nickname) {
|
||||||
socket.write(`:${socket.nickname}!${socket.username}@${socket.host} NICK :${new_nickname}\r\n`);
|
socket.write(`:${socket.nickname}!${socket.username}@${socket.host} NICK :${new_nickname}\r\n`);
|
||||||
if (this.usernames.has(socket.nickname)) {
|
|
||||||
this.usernames.delete(socket.nickname);
|
|
||||||
}
|
|
||||||
if (this.uniqueids.has(socket.nickname)) {
|
|
||||||
this.deleteUserUniqueId(socket.nickname);
|
|
||||||
}
|
|
||||||
this.broadcastUser(socket.nickname, `:${socket.nickname}!${socket.username}@${socket.host} NICK :${new_nickname}\r\n`, socket);
|
this.broadcastUser(socket.nickname, `:${socket.nickname}!${socket.username}@${socket.host} NICK :${new_nickname}\r\n`, socket);
|
||||||
this.processNickChange(socket, new_nickname);
|
this.processNickChange(socket, new_nickname);
|
||||||
this.broadcastToAllServers(`:${socket.uniqueId} NICK ${new_nickname} :${this.getDate()}\r\n`);
|
this.broadcastToAllServers(`:${socket.uniqueId} NICK ${new_nickname} :${this.getDate()}\r\n`);
|
||||||
@@ -3547,6 +3527,7 @@ class WTVIRC {
|
|||||||
this.usernames.set(newNick, this.usernames.get(socket.nickname) || socket.nickname);
|
this.usernames.set(newNick, this.usernames.get(socket.nickname) || socket.nickname);
|
||||||
this.usernames.delete(socket.nickname);
|
this.usernames.delete(socket.nickname);
|
||||||
this.nicknames.set(socket, newNick);
|
this.nicknames.set(socket, newNick);
|
||||||
|
this.nicknames.delete(socket.nickname);
|
||||||
this.addUserUniqueId(newNick, socket.uniqueId);
|
this.addUserUniqueId(newNick, socket.uniqueId);
|
||||||
this.deleteUserUniqueId(socket.nickname);
|
this.deleteUserUniqueId(socket.nickname);
|
||||||
this.usertimestamps.set(newNick, this.getDate());
|
this.usertimestamps.set(newNick, this.getDate());
|
||||||
|
|||||||
Reference in New Issue
Block a user