diff --git a/server/rooms.ts b/server/rooms.ts index a21170f63f..d1b627f6a9 100644 --- a/server/rooms.ts +++ b/server/rooms.ts @@ -78,7 +78,6 @@ export interface RoomSettings { auth: {[userid: string]: GroupSymbol}; creationTime: number; - readonly staffAutojoin?: string | boolean; readonly autojoin?: boolean; aliases?: string[]; banwords?: string[]; @@ -924,9 +923,9 @@ export class GlobalRoomState { */ readonly autojoinList: RoomID[]; /** - * Rooms that staff autojoin upon connecting + * Rooms that users autojoin upon logging in */ - readonly staffAutojoinList: RoomID[]; + readonly modjoinedAutojoinList: RoomID[]; readonly ladderIpLog: WriteStream; readonly reportUserStatsInterval: NodeJS.Timeout; lockdown: boolean | 'pre' | 'ddos'; @@ -956,28 +955,35 @@ export class GlobalRoomState { title: 'Staff', auth: {}, creationTime: Date.now(), - isPrivate: true, - staffRoom: true, - staffAutojoin: true, + isPrivate: 'hidden', + modjoin: '%', + autojoin: true, }]; } this.chatRooms = []; this.autojoinList = []; - this.staffAutojoinList = []; + this.modjoinedAutojoinList = []; for (const [i, settings] of this.settingsList.entries()) { if (!settings || !settings.title) { Monitor.warn(`ERROR: Room number ${i} has no data and could not be loaded.`); continue; } + if ((settings as any).staffAutojoin) { + // convert old staffAutojoin format + delete (settings as any).staffAutojoin; + (settings as any).autojoin = true; + if (!settings.modjoin) settings.modjoin = '%'; + if (settings.isPrivate === true) settings.isPrivate = 'hidden'; + } // We're okay with assinging type `ID` to `RoomID` here // because the hyphens in chatrooms don't have any special // meaning, unlike in helptickets, groupchats, battles etc // where they are used for shared modlogs and the like const id = toID(settings.title) as RoomID; - Monitor.notice("NEW CHATROOM: " + id); + Monitor.notice("RESTORE CHATROOM: " + id); const room = Rooms.createChatRoom(id, settings.title, settings); if (room.settings.aliases) { for (const alias of room.settings.aliases) { @@ -986,8 +992,13 @@ export class GlobalRoomState { } this.chatRooms.push(room); - if (room.settings.autojoin) this.autojoinList.push(id); - if (room.settings.staffAutojoin) this.staffAutojoinList.push(id); + if (room.settings.autojoin) { + if (room.settings.modjoin) { + this.modjoinedAutojoinList.push(id); + } else { + this.autojoinList.push(id); + } + } } Rooms.lobby = Rooms.rooms.get('lobby') as ChatRoom; @@ -1295,7 +1306,7 @@ export class GlobalRoomState { } autojoinRooms(user: User, connection: Connection) { // we only autojoin regular rooms if the client requests it with /autojoin - // note that this restriction doesn't apply to staffAutojoin + // note that this restriction doesn't apply to modjoined autojoin rooms let includesLobby = false; for (const roomName of this.autojoinList) { user.joinRoom(roomName, connection); @@ -1305,19 +1316,14 @@ export class GlobalRoomState { } checkAutojoin(user: User, connection?: Connection) { if (!user.named) return; - for (let [i, staffAutojoin] of this.staffAutojoinList.entries()) { - const room = Rooms.get(staffAutojoin); + for (let [i, roomid] of this.modjoinedAutojoinList.entries()) { + const room = Rooms.get(roomid); if (!room) { - this.staffAutojoinList.splice(i, 1); + this.modjoinedAutojoinList.splice(i, 1); i--; continue; } - if (room.settings.staffAutojoin === true && user.isStaff || - typeof room.settings.staffAutojoin === 'string' && room.settings.staffAutojoin.includes(user.tempGroup) || - room.auth.has(user.id)) { - // if staffAutojoin is true: autojoin if isStaff - // if staffAutojoin is String: autojoin if user.group in staffAutojoin - // if staffAutojoin is anything truthy: autojoin if user has any roomauth + if (room.checkModjoin(user)) { user.joinRoom(room.roomid, connection); } }