diff --git a/chat-commands.js b/chat-commands.js index 457da5aad5..62f54ce670 100644 --- a/chat-commands.js +++ b/chat-commands.js @@ -1743,15 +1743,18 @@ exports.commands = { banip: function (target, room, user) { target = this.splitTargetText(target); let targetIp = this.targetUsername.trim(); - if (!targetIp || !/^[0-9.*]+$/.test(targetIp)) return this.parse('/help banip'); + if (!targetIp || !/^[0-9.]+(?:\.\*)?$/.test(targetIp)) return this.parse('/help banip'); if (!target) return this.errorReply("/banip requires a ban reason"); if (!this.can('rangeban')) return false; - Punishments.ipSearch(targetIp); - if (Punishments.ips.has(targetIp)) return this.errorReply("The IP " + (targetIp.charAt(targetIp.length - 1) === '*' ? "range " : "") + targetIp + " has already been temporarily locked/banned."); + const targetDesc = "IP " + (targetIp.endsWith('*') ? "range " : "") + targetIp; + const curPunishment = Punishments.ipSearch(targetIp); + if (curPunishment && curPunishment[0] === 'BAN') { + return this.errorReply(`The ${targetDesc} is already temporarily banned.`); + } Punishments.banRange(targetIp, target); - this.addModCommand("" + user.name + " hour-banned the " + (target.charAt(target.length - 1) === '*' ? "IP range" : "IP") + " " + targetIp + ": " + target); + this.addModCommand(`${user.name} hour-banned the ${targetDesc}: ${target}`); }, baniphelp: ["/banip [ip] - Globally bans this IP or IP range for an hour. Accepts wildcards to ban ranges. Existing users on the IP will not be banned. Requires: & ~"], @@ -1774,15 +1777,20 @@ exports.commands = { lockip: function (target, room, user) { target = this.splitTargetText(target); let targetIp = this.targetUsername.trim(); - if (!targetIp || !/^[0-9.*]+$/.test(targetIp)) return this.parse('/help lockip'); + if (!targetIp || !/^[0-9.]+(?:\.\*)?$/.test(targetIp)) return this.parse('/help lockip'); if (!target) return this.errorReply("/lockip requires a lock reason"); if (!this.can('rangeban')) return false; - Punishments.ipSearch(targetIp); - if (Punishments.ips.has(targetIp)) return this.sendReply("The IP " + (targetIp.charAt(targetIp.length - 1) === '*' ? "range " : "") + targetIp + " has already been temporarily locked/banned."); + const targetDesc = "IP " + (targetIp.endsWith('*') ? "range " : "") + targetIp; + + const curPunishment = Punishments.ipSearch(targetIp); + if (curPunishment && (curPunishment[0] === 'BAN' || curPunishment[0] === 'LOCK')) { + const punishDesc = curPunishment[0] === 'BAN' ? `temporarily banned` : `temporarily locked`; + return this.errorReply(`The ${targetDesc} is already ${punishDesc}.`); + } Punishments.lockRange(targetIp, target); - this.addModCommand("" + user.name + " hour-locked the " + (target.charAt(target.length - 1) === '*' ? "IP range" : "IP") + " " + targetIp + ": " + target); + this.addModCommand(`${user.name} hour-locked the ${targetDesc}: ${target}`); }, lockiphelp: ["/lockip [ip] - Globally locks this IP or IP range for an hour. Accepts wildcards to ban ranges. Existing users on the IP will not be banned. Requires: & ~"], @@ -2081,7 +2089,7 @@ exports.commands = { let hidetype = ''; if (!user.can('lock', targetUser) && !this.can('ban', targetUser, room)) return false; - if (targetUser.locked || Punishments.isRoomBanned(user, room.id) || user.can('rangeban')) { + if (targetUser.locked || Punishments.isRoomBanned(targetUser, room.id) || user.can('rangeban')) { hidetype = 'hide|'; } else { return this.errorReply("User '" + name + "' is not banned from this room or locked."); diff --git a/punishments.js b/punishments.js index c1ec5dcaca..48cc7caa64 100644 --- a/punishments.js +++ b/punishments.js @@ -697,6 +697,11 @@ Punishments.roomBlacklist = function (room, user, expireTime, userId, ...reason) if (!expireTime) expireTime = Date.now() + BLACKLIST_DURATION; let punishment = ['BLACKLIST', userId, expireTime].concat(reason); + + if (!user || userId && userId !== user.userid) { + Punishments.roomPunishName(room, userId, punishment); + } + if (user) { Punishments.roomPunish(room, user, punishment); @@ -707,8 +712,6 @@ Punishments.roomBlacklist = function (room, user, expireTime, userId, ...reason) } curUser.leaveRoom(room.id); } - } else { - Punishments.roomPunishName(room, userId, punishment); } }; @@ -985,6 +988,7 @@ Punishments.checkNewNameInRoom = function (user, userid, roomid) { /** * @param {string} userid + * @return {string} Descriptive text for the remaining time until the punishment expires, if any. */ Punishments.checkLockExpiration = function (userid) { const punishment = Punishments.userids.get(userid); diff --git a/tournaments/index.js b/tournaments/index.js index e78fec6607..6a8173df73 100644 --- a/tournaments/index.js +++ b/tournaments/index.js @@ -1200,7 +1200,8 @@ let commands = { if (params.length < 1) { return this.sendReply("Usage: " + cmd + " , "); } - let targetUser = Users.get(params[0]) || params[0]; + let targetUser = Users.get(params[0]); + if (!targetUser) return this.errorReply(`User "${params[0]}" not found.`); let targetUserid = toId(targetUser); let reason = ''; if (params[1]) {