purge user channel permissions when part/quit

This commit is contained in:
zefie
2025-06-17 13:50:36 -04:00
parent 352ea42a13
commit afb04cd14e
2 changed files with 48 additions and 9 deletions

View File

@@ -2402,7 +2402,7 @@ Object.keys(minisrv_config.services).forEach(function (k) {
if (minisrv_config.config.irc) { if (minisrv_config.config.irc) {
if (minisrv_config.config.irc.enabled && minisrv_config.config.irc.port > 0) { if (minisrv_config.config.irc.enabled && minisrv_config.config.irc.port > 0) {
if (!wtvirc) { if (!wtvirc) {
wtvirc = new WTVIRC(minisrv_config, minisrv_config.config.bind_ip, minisrv_config.config.irc.port); wtvirc = new WTVIRC(minisrv_config, minisrv_config.config.bind_ip, minisrv_config.config.irc.port, minisrv_config.config.irc.debug || false);
wtvirc.start(); wtvirc.start();
console.log(" * Configured Service: IRC Server on", minisrv_config.config.bind_ip + ":" + minisrv_config.config.irc.port); console.log(" * Configured Service: IRC Server on", minisrv_config.config.bind_ip + ":" + minisrv_config.config.irc.port);
} }

View File

@@ -666,6 +666,16 @@ class WTVIRC {
var user_name = this.usernames.get(nick_name) || nick_name; var user_name = this.usernames.get(nick_name) || nick_name;
var message = parts.slice(2).join(' ').slice(1); // Remove leading ':' var message = parts.slice(2).join(' ').slice(1); // Remove leading ':'
for (const [channel, users] of this.channels.entries()) { for (const [channel, users] of this.channels.entries()) {
if (this.channelops.has(channel) && this.channelops.get(channel) instanceof Set) {
this.channelops.get(channel).delete(nick_name);
}
if (this.channelhalfops.has(channel) && this.channelhalfops.get(channel) instanceof Set) {
this.channelhalfops.get(channel).delete(nick_name);
}
if (this.channelvoices.has(channel) && this.channelvoices.get(channel) instanceof Set) {
this.channelvoices.get(channel).delete(nick_name);
}
if (users.has(nick_name)) { if (users.has(nick_name)) {
this.broadcastChannel(channel, `:${nick_name}!${user_name}@${this.servername} QUIT :${message}\r\n`); this.broadcastChannel(channel, `:${nick_name}!${user_name}@${this.servername} QUIT :${message}\r\n`);
} }
@@ -714,6 +724,16 @@ class WTVIRC {
} }
var channel = parts[2]; var channel = parts[2];
var nickname = this.findUserByUniqueId(sourceUniqueId); var nickname = this.findUserByUniqueId(sourceUniqueId);
if (this.channelops.has(channel) && this.channelops.get(channel) instanceof Set) {
this.channelops.get(channel).delete(nickname);
}
if (this.channelhalfops.has(channel) && this.channelhalfops.get(channel) instanceof Set) {
this.channelhalfops.get(channel).delete(nickname);
}
if (this.channelvoices.has(channel) && this.channelvoices.get(channel) instanceof Set) {
this.channelvoices.get(channel).delete(nickname);
}
var username = this.usernames.get(nickname) || nickname; var username = this.usernames.get(nickname) || nickname;
var hostname = this.hostnames.get(nickname); var hostname = this.hostnames.get(nickname);
this.broadcastChannel(channel, `:${nickname}!${username}@${hostname} PART ${channel} :${parts.slice(4).join(' ')}\r\n`, userSocket); this.broadcastChannel(channel, `:${nickname}!${username}@${hostname} PART ${channel} :${parts.slice(4).join(' ')}\r\n`, userSocket);
@@ -1971,11 +1991,20 @@ class WTVIRC {
socket.write(`:${this.servername} 451 ${socket.nickname} :You have not registered\r\n`); socket.write(`:${this.servername} 451 ${socket.nickname} :You have not registered\r\n`);
break; break;
} }
channel = params[0]; channel = this.findChannel(params[0]);
if (!this.channels.has(channel) || !this.channels.get(channel).has(socket.nickname)) { if (!this.channels.has(channel) || !this.channels.get(channel).has(socket.nickname)) {
socket.write(`:${this.servername} 442 ${socket.nickname} ${channel} :You're not on that channel\r\n`); socket.write(`:${this.servername} 442 ${socket.nickname} ${channel} :You're not on that channel\r\n`);
break; break;
} }
if (this.channelops.has(channel) && this.channelops.get(channel) instanceof Set) {
this.channelops.get(channel).delete(socket.nickname);
}
if (this.channelhalfops.has(channel) && this.channelhalfops.get(channel) instanceof Set) {
this.channelhalfops.get(channel).delete(socket.nickname);
}
if (this.channelvoices.has(channel) && this.channelvoices.get(channel) instanceof Set) {
this.channelvoices.get(channel).delete(socket.nickname);
}
this.usertimestamps.set(socket.nickname, this.getDate()); this.usertimestamps.set(socket.nickname, this.getDate());
if (params.length == 2) { if (params.length == 2) {
let reason = params.join(' '); let reason = params.join(' ');
@@ -2343,7 +2372,7 @@ class WTVIRC {
if (msg.startsWith('\x01VERSION')) { if (msg.startsWith('\x01VERSION')) {
socket.client_version = msg.replace('\x01VERSION ', '').replace('\x01', ''); socket.client_version = msg.replace('\x01VERSION ', '').replace('\x01', '');
if (this.clientIsWebTV(socket)) { if (this.clientIsWebTV(socket)) {
this.sendWebTVNoticeTo(socket.nickname, "Welcome, WebTV user! You are now connected to the server."); this.sendWebTVNoticeTo(socket, "Welcome, WebTV user! You are now connected to the server.");
} }
break; break;
} }
@@ -2572,6 +2601,19 @@ class WTVIRC {
if (!socket.registered) { if (!socket.registered) {
socket.write(`:${this.servername} 451 ${socket.nickname} :You have not registered\r\n`); socket.write(`:${this.servername} 451 ${socket.nickname} :You have not registered\r\n`);
} else { } else {
for (const [ch, users] of this.channels.entries()) {
if (users.has(socket.nickname)) {
if (this.channelops.has(ch) && this.channelops.get(ch) instanceof Set) {
this.channelops.get(ch).delete(socket.nickname);
}
if (this.channelhalfops.has(ch) && this.channelhalfops.get(ch) instanceof Set) {
this.channelhalfops.get(ch).delete(socket.nickname);
}
if (this.channelvoices.has(ch) && this.channelvoices.get(ch) instanceof Set) {
this.channelvoices.get(ch).delete(socket.nickname);
}
}
}
if (params.length > 0) { if (params.length > 0) {
let reason = params.join(' '); let reason = params.join(' ');
if (reason.startsWith(':')) { if (reason.startsWith(':')) {
@@ -2751,11 +2793,8 @@ class WTVIRC {
this.broadcast(`:${this.servername} NOTICE * :${message}\r\n`); this.broadcast(`:${this.servername} NOTICE * :${message}\r\n`);
} }
sendWebTVNoticeTo(username, message) { sendWebTVNoticeTo(socket, message) {
const socket = Array.from(this.nicknames.keys()).find(s => this.nicknames.get(s).toLowerCase() === username.toLowerCase()); socket.write(`:${this.servername} NOTICE * :${message}\r\n`);
if (socket) {
socket.write(`:${this.servername} NOTICE * :${message}\r\n`);
}
} }
sendToChannelAs(username, channel, message) { sendToChannelAs(username, channel, message) {