From 577098db8392341de5fa44b0dec061620a676184 Mon Sep 17 00:00:00 2001
From: Guangcong Luo
Date: Wed, 13 Dec 2017 23:40:16 -0600
Subject: [PATCH] Disallow empty subRooms map
---
chat-commands.js | 20 +++++++++++---------
rooms.js | 2 +-
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/chat-commands.js b/chat-commands.js
index 1c6afebe99..223c0aa158 100644
--- a/chat-commands.js
+++ b/chat-commands.js
@@ -751,8 +751,10 @@ exports.commands = {
if (targetRoom.subRooms) {
for (const subRoom of targetRoom.subRooms) subRoom.parent = null;
}
- if (targetRoom.parent && targetRoom.parent.subRooms) {
- targetRoom.parent.subRooms.delete(targetRoom.id);
+ const parent = targetRoom.parent;
+ if (parent && parent.subRooms) {
+ parent.subRooms.delete(targetRoom.id);
+ if (!parent.subRooms.size) parent.subRooms = null;
}
targetRoom.add("|raw|
This room has been deleted.
");
@@ -823,7 +825,7 @@ exports.commands = {
}
} else {
const settingName = (setting === true ? 'secret' : setting);
- if (room.subRooms && room.subRooms.size) return this.errorReply("Private rooms cannot have subrooms.");
+ if (room.subRooms) return this.errorReply("Private rooms cannot have subrooms.");
if (room.isPrivate === setting) {
if (room.privacySetter && !room.privacySetter.has(user.userid)) {
room.privacySetter.add(user.userid);
@@ -926,10 +928,10 @@ exports.commands = {
if (!this.can('makeroom')) return;
if (!room.parent || !room.chatRoomData) return this.errorReply(`This room is not currently a subroom of a public room.`);
- const main = Rooms(this.parent);
-
- if (main && main.subRooms) {
- main.subRooms.delete(room.id);
+ const parent = room.parent;
+ if (parent && parent.subRooms) {
+ parent.subRooms.delete(room.id);
+ if (!parent.subRooms.size) parent.subRooms = null;
}
room.parent = null;
@@ -1420,7 +1422,7 @@ exports.commands = {
if (targetUser in room.users || user.can('lock')) {
targetUser.popup(
- "|modal||html|
" + Chat.escapeHTML(user.name) + " has banned you from the room " + room.id + (room.subRooms && room.subRooms.size ? " and its subrooms" : "") + ".
" + (target ? "
Reason: " + Chat.escapeHTML(target) + "
" : "") +
+ "|modal||html|
" + Chat.escapeHTML(user.name) + " has banned you from the room " + room.id + (room.subRooms ? " and its subrooms" : "") + ".
" + (target ? "
Reason: " + Chat.escapeHTML(target) + "
" : "") +
"
To appeal the ban, PM the staff member that banned you" + (!room.battle && room.auth ? " or a room owner.
" : ".
")
);
}
@@ -2364,7 +2366,7 @@ exports.commands = {
if (targetUser in room.users || user.can('lock')) {
targetUser.popup(
- "|modal||html|
" + Chat.escapeHTML(user.name) + " has blacklisted you from the room " + room.id + (room.subRooms && room.subRooms.size ? " and its subrooms" : "") + ".
" + (target ? "
Reason: " + Chat.escapeHTML(target) + "
" : "") +
+ "|modal||html|
" + Chat.escapeHTML(user.name) + " has blacklisted you from the room " + room.id + (room.subRooms ? " and its subrooms" : "") + ".
" + (target ? "
Reason: " + Chat.escapeHTML(target) + "
" : "") +
"
To appeal the ban, PM the staff member that blacklisted you" + (!room.battle && room.auth ? " or a room owner.