This commit is contained in:
zefie
2025-06-14 13:35:33 -04:00
parent 0aa8dc5a20
commit 435da4daa5

View File

@@ -151,17 +151,6 @@ class WTVIRC {
socket.write(`:${this.servername} 451 ${nickname} :You have not registered\r\n`);
break;
}
if (params.length < 2) {
socket.write(`:${this.servername} 461 ${nickname} KICK :Not enough parameters\r\n`);
break;
}
this.usertimestamps.set(nickname, Date.now());
channel = params[0];
const targetNick = params[1];
if (!this.channels.has(channel)) {
socket.write(`:${this.servername} 403 ${nickname} ${channel} :No such channel\r\n`);
break;
}
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
break;
@@ -171,13 +160,36 @@ class WTVIRC {
break;
}
}
if (params.length < 2) {
socket.write(`:${this.servername} 461 ${nickname} KICK :Not enough parameters\r\n`);
break;
}
this.usertimestamps.set(nickname, Date.now());
channel = params[0];
const targetNick = params[1];
if (!this.channels.has(channel)) {
socket.write(`:${this.servername} 403 ${nickname} ${channel} :No such channel\r\n`);
break;
}
if (!this.channels.get(channel).has(targetNick)) {
socket.write(`:${this.servername} 441 ${nickname} ${targetNick} :They aren't on that channel\r\n`);
socket.write(`:${this.servername} 441 ${nickname} ${targetNick} :They aren't on that channel\r\n`);
break;
}
this.channels.get(channel).delete(targetNick);
socket.write(`:${nickname}!${username}@${socket.host} KICK ${channel} ${targetNick}\r\n`);
this.broadcastUser(nickname, `:${nickname}!${username}@${socket.host} KICK ${channel} ${targetNick}\r\n`, socket);
var targetSocket = Array.from(this.clients).find(s => this.nicknames.get(s) === targetNick);
if (params.length > 2) {
let reason = params.slice(2).join(' ');
if (reason.startsWith(':')) {
reason = reason.slice(1);
}
targetSocket.write(`:${nickname}!${username}@${socket.host} KICK ${channel} ${targetNick} :${reason}\r\n`);
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} KICK ${channel} ${targetNick} :${reason}\r\n`);
break;
} else {
targetSocket.write(`:${nickname}!${username}@${socket.host} KICK ${channel} ${targetNick}\r\n`);
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} KICK ${channel} ${targetNick}\r\n`);
}
break;
case 'TOPIC':
if (!registered) {
@@ -222,7 +234,7 @@ class WTVIRC {
}
this.usertimestamps.set(nickname, Date.now());
if (params.length > 0) {
socket.write(`:${this.servername} 301 ${nickname} :You are now marked as away\r\n`);
socket.write(`:${this.servername} 306 ${nickname} :You are now marked as away\r\n`);
let awayMsg = params.join(' ');
if (awayMsg.startsWith(':')) {
awayMsg = awayMsg.slice(1);
@@ -795,6 +807,9 @@ class WTVIRC {
this.broadcastChannel(target, `:${nickname}!${username}@${socket.host} PRIVMSG ${target} :${msg}\r\n`, socket);
break;
} else {
if (this.awaymsgs.has(target)) {
socket.write(`:${this.servername} 301 ${nickname} ${target} :${this.awaymsgs.get(target)}\r\n`);
}
const targetSock = Array.from(this.nicknames.keys()).find(s => this.nicknames.get(s) === target);
if (!targetSock) {
socket.write(`:${this.servername} 401 ${nickname} ${target} :No such nick/channel\r\n`);
@@ -919,7 +934,7 @@ class WTVIRC {
if (cleanKillReason.startsWith(':')) {
cleanKillReason = cleanKillReason.slice(1);
}
const targetSocket = Array.from(this.nicknames.keys()).find(s => this.nicknames.get(s) === target_nick);
var targetSocket = Array.from(this.nicknames.keys()).find(s => this.nicknames.get(s) === target_nick);
if (!targetSocket) {
socket.write(`:${this.servername} 401 ${nickname} ${target_nick} :No such nick/channel\r\n`);
break;
@@ -1303,12 +1318,7 @@ class WTVIRC {
// This method parses and applies multiple channel mode changes in one call.
processChannelModeBatch(nickname, channel, modeString, params) {
const socket = Array.from(this.nicknames.keys()).find(s => this.nicknames.get(s) === nickname);
const username = this.usernames.get(nickname);
if (!this.channelops.has(channel) || this.channelops.get(channel) === true || !this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
// Parse mode string and parameters
let adding = true;
@@ -1329,7 +1339,7 @@ class WTVIRC {
// If the mode is 'b', 'e', or 'I', allow it with or without a param
if ((c === 'b' || c === 'e' || c === 'I') && paramIndex >= params.length) {
this.processChannelModeCommand(nickname, channel, c, null);
continue;
return;
}
if (c === '+') {
adding = true;
@@ -1347,6 +1357,18 @@ class WTVIRC {
}
}
// Allow IRCop to set channel modes, or require channel operator
if (
!this.isIRCOp(nickname) &&
(
!this.channelops.has(channel) ||
this.channelops.get(channel) === true ||
!this.channelops.get(channel).has(nickname)
)
) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
// Now apply each mode change
for (const change of modeChanges) {
let modeFlag = (change.adding ? '+' : '-') + change.mode;
@@ -1360,15 +1382,6 @@ class WTVIRC {
const socket = Array.from(this.nicknames.keys()).find(s => this.nicknames.get(s) === nickname);
const username = this.usernames.get(nickname);
if (mode.startsWith('+m')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
var chan_modes = this.channelmodes.get(channel);
if (!chan_modes || chan_modes === true) {
chan_modes = [];
@@ -1379,15 +1392,7 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} +m\r\n`);
return;
} else if (mode.startsWith('-m')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
var chan_modes = this.channelmodes.get(channel);
if (!chan_modes || chan_modes === true) {
chan_modes = [];
@@ -1396,15 +1401,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} -m\r\n`);
return;
} else if (mode.startsWith("+I")) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
if (params.length < 3) {
socket.write(`:${this.servername} 461 ${nickname} MODE :Not enough parameters\r\n`);
return;
@@ -1422,15 +1418,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} +I ${inviteMask}\r\n`, socket);
return;
} else if (mode.startsWith("-I")) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
if (params.length < 3) {
socket.write(`:${this.servername} 461 ${nickname} MODE :Not enough parameters\r\n`);
return;
@@ -1450,15 +1437,7 @@ class WTVIRC {
return;
}
} else if (mode.startsWith('+l')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
if (params.length < 3) {
socket.write(`:${this.servername} 461 ${nickname} MODE :Not enough parameters\r\n`);
return;
@@ -1478,15 +1457,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} +l ${limit}\r\n`);
return;
} else if (mode.startsWith('-l')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
if (params.length < 2) {
socket.write(`:${this.servername} 461 ${nickname} MODE :Not enough parameters\r\n`);
return;
@@ -1499,15 +1469,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} -l\r\n`);
return;
} else if (mode.startsWith('+k')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
if (params.length < 3) {
socket.write(`:${this.servername} 461 ${nickname} MODE :Not enough parameters\r\n`);
return;
@@ -1521,15 +1482,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} +k ${key}\r\n`);
return;
} else if (mode.startsWith('-k')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
if (params.length < 2) {
socket.write(`:${this.servername} 461 ${nickname} MODE :Not enough parameters\r\n`);
return;
@@ -1542,15 +1494,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} -k\r\n`);
return;
} else if (mode.startsWith('+i')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
var chan_modes = this.channelmodes.get(channel);
if (!chan_modes || chan_modes === true) {
chan_modes = [];
@@ -1559,15 +1502,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} +i\r\n`);
return;
} else if (mode.startsWith('-i')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
var chan_modes = this.channelmodes.get(channel);
if (!chan_modes || chan_modes === true) {
chan_modes = [];
@@ -1580,15 +1514,6 @@ class WTVIRC {
socket.write(`:${this.servername} 461 ${nickname} MODE :Not enough parameters\r\n`);
return;
}
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
const target_nickname = params[2];
this.channelops.set(channel, (this.channelops.get(channel) || new Set()).add(target_nickname));
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} +o ${target_nickname}\r\n`);
@@ -1598,15 +1523,6 @@ class WTVIRC {
socket.write(`:${this.servername} 461 ${nickname} MODE :Not enough parameters\r\n`);
return;
}
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
const target_nickname = params[2];
this.channelops.set(channel, (this.channelops.get(channel) || new Set()).delete(target_nickname));
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} -o ${target_nickname}\r\n`);
@@ -1616,15 +1532,6 @@ class WTVIRC {
socket.write(`:${this.servername} 461 ${nickname} MODE :Not enough parameters\r\n`);
return;
}
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
const target_nickname = params[2];
this.channelvoices.set(channel, (this.channelvoices.get(channel) || new Set()).add(target_nickname));
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} +v ${target_nickname}\r\n`);
@@ -1634,29 +1541,11 @@ class WTVIRC {
socket.write(`:${this.servername} 461 ${nickname} MODE :Not enough parameters\r\n`);
return;
}
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
const target_nickname = params[2];
this.channelvoices.set(channel, (this.channelvoices.get(channel) || new Set()).delete(target_nickname));
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} -v ${target_nickname}\r\n`, socket);
return;
} else if (mode.startsWith('+b')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
const banMask = params[2];
if (!banMask) {
socket.write(`:${this.servername} 461 ${nickname} MODE :Not enough parameters\r\n`);
@@ -1670,15 +1559,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} +b ${banMask}\r\n`, socket);
return
} else if (mode.startsWith('-b')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
const banMask = params[2];
if (!banMask) {
socket.write(`:${this.servername} 461 ${nickname} MODE :Not enough parameters\r\n`);
@@ -1694,15 +1574,6 @@ class WTVIRC {
return
}
} else if (mode.startsWith('+e')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
const exemptMask = params[2];
if (!exemptMask) {
socket.write(`:${this.servername} 461 ${nickname} MODE :Not enough parameters\r\n`);
@@ -1716,15 +1587,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} +e ${exemptMask}\r\n`, socket);
return;
} else if (mode.startsWith('-e')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
const exemptMask = params[2];
if (!exemptMask) {
socket.write(`:${this.servername} 461 ${nickname} MODE :Not enough parameters\r\n`);
@@ -1740,15 +1602,6 @@ class WTVIRC {
return;
}
} else if (mode.startsWith("+n")) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
var chan_modes = this.channelmodes.get(channel);
if (!chan_modes || chan_modes === true) {
chan_modes = [];
@@ -1757,15 +1610,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} +n\r\n`);
return;
} else if (mode.startsWith("-n")) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
var chan_modes = this.channelmodes.get(channel);
if (!chan_modes || chan_modes === true) {
chan_modes = [];
@@ -1774,15 +1618,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} -n\r\n`);
return;
} else if (mode.startsWith('+s')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
var chan_modes = this.channelmodes.get(channel);
if (!chan_modes || chan_modes === true) {
chan_modes = [];
@@ -1791,15 +1626,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} +s\r\n`);
return;
} else if (mode.startsWith('-s')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
var chan_modes = this.channelmodes.get(channel);
if (!chan_modes || chan_modes === true) {
chan_modes = [];
@@ -1808,15 +1634,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} -s\r\n`);
return;
} else if (mode.startsWith('+p')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
var chan_modes = this.channelmodes.get(channel);
if (!chan_modes || chan_modes === true) {
chan_modes = [];
@@ -1825,15 +1642,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} +p\r\n`);
return;
} else if (mode.startsWith('-p')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
var chan_modes = this.channelmodes.get(channel);
if (!chan_modes || chan_modes === true) {
chan_modes = [];
@@ -1842,15 +1650,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} -p\r\n`);
return;
} else if (mode.startsWith('+t')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
var chan_modes = this.channelmodes.get(channel);
if (!chan_modes || chan_modes === true) {
chan_modes = [];
@@ -1859,15 +1658,6 @@ class WTVIRC {
this.broadcastChannel(channel, `:${nickname}!${username}@${socket.host} MODE ${channel} +t\r\n`);
return;
} else if (mode.startsWith('-t')) {
if (!this.channelops.has(channel) || this.channelops.get(channel) === true) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
} else {
if (!this.channelops.get(channel).has(nickname)) {
socket.write(`:${this.servername} 482 ${nickname} ${channel} :You're not channel operator\r\n`);
return;
}
}
var chan_modes = this.channelmodes.get(channel);
if (!chan_modes || chan_modes === true) {
chan_modes = [];