diff --git a/server/chat-commands/admin.ts b/server/chat-commands/admin.ts index ad3ede2b9d..92264ca9e0 100644 --- a/server/chat-commands/admin.ts +++ b/server/chat-commands/admin.ts @@ -71,7 +71,7 @@ export const commands: ChatCommands = { html += Utils.html`
[${user.name}]
`; } - this.room.sendRankedUsers(`|html|
${html}
`, rank as GroupSymbol); + room.sendRankedUsers(`|html|
${html}
`, rank as GroupSymbol); }, addrankhtmlboxhelp: [ `/addrankhtmlbox [rank], [message] - Shows everyone with the specified rank or higher a message, parsing HTML code contained. Requires: * # &`, @@ -121,7 +121,7 @@ export const commands: ChatCommands = { } html = `|uhtml${(cmd === 'changerankuhtml' ? 'change' : '')}|${name}|${html}`; - this.room.sendRankedUsers(html, rank as GroupSymbol); + room.sendRankedUsers(html, rank as GroupSymbol); }, addrankuhtmlhelp: [ `/addrankuhtml [rank], [name], [message] - Shows everyone with the specified rank or higher a message that can change, parsing HTML code contained. Requires: * # &`, @@ -324,7 +324,7 @@ export const commands: ChatCommands = { // respawn simulator processes void Rooms.PM.respawn(); // broadcast the new formats list to clients - Rooms.global.send(Rooms.global.formatListText); + Rooms.global.sendAll(Rooms.global.formatListText); this.sendReply("Formats have been hot-patched."); } else if (target === 'loginserver') { @@ -787,7 +787,7 @@ export const commands: ChatCommands = { refreshpage(target, room, user) { if (!this.can('lockdown')) return false; - Rooms.global.send('|refresh|'); + Rooms.global.sendAll('|refresh|'); const logRoom = Rooms.get('staff') || room; logRoom.roomlog(`${user.name} used /refreshpage`); }, diff --git a/server/chat-commands/core.ts b/server/chat-commands/core.ts index 43effde143..5ed6e790cc 100644 --- a/server/chat-commands/core.ts +++ b/server/chat-commands/core.ts @@ -507,8 +507,8 @@ export const commands: ChatCommands = { target = this.splitTarget(target); const targetUser = this.targetUser; if (this.targetUsername === '~') { - this.room = Rooms.global; this.pmTarget = null; + this.room = null; } else if (!targetUser) { let error = `User ${this.targetUsername} not found. Did you misspell their name?`; error = `|pm|${this.user.getIdentity()}| ${this.targetUsername}|/error ${error}`; @@ -516,7 +516,7 @@ export const commands: ChatCommands = { return; } else { this.pmTarget = targetUser; - this.room = null!; + this.room = null; } if (targetUser && !targetUser.connected) { @@ -547,7 +547,7 @@ export const commands: ChatCommands = { const targetUser = this.pmTarget!; // not room means it's a PM - if (!targetRoom || targetRoom === Rooms.global) { + if (!targetRoom) { return this.errorReply(`The room "${target}" was not found.`); } if (!targetRoom.checkModjoin(targetUser)) { @@ -1393,7 +1393,7 @@ export const commands: ChatCommands = { } const targetRoom = Rooms.get(target); - if (!targetRoom || targetRoom === Rooms.global || ( + if (!targetRoom || ( targetRoom.settings.isPrivate && !user.inRooms.has(targetRoom.roomid) && !user.games.has(targetRoom.roomid) )) { const roominfo = {id: target, error: 'not found or access denied'}; diff --git a/server/chat-commands/info.ts b/server/chat-commands/info.ts index ddffdbb6fb..3236854ac9 100644 --- a/server/chat-commands/info.ts +++ b/server/chat-commands/info.ts @@ -19,10 +19,8 @@ export const commands: ChatCommands = { alt: 'whois', alts: 'whois', whoare: 'whois', - whois(target, room, user, connection, cmd) { - let usedRoom: ChatRoom | GameRoom | GlobalRoom = room; - if (usedRoom?.roomid === 'staff' && !this.runBroadcast()) return; - if (!usedRoom) usedRoom = Rooms.global; + whois(target, room: Room | null, user, connection, cmd) { + if (room?.roomid === 'staff' && !this.runBroadcast()) return; const targetUser = this.targetUserOrSelf(target, user.group === ' '); const showAll = (cmd === 'ip' || cmd === 'whoare' || cmd === 'alt' || cmd === 'alts'); if (!targetUser) { @@ -43,8 +41,8 @@ export const commands: ChatCommands = { buf += ` (trusted${targetUser.id === trusted ? `` : `: ${trusted}`})`; } if (!targetUser.connected) buf += ` (offline)`; - const roomauth = usedRoom.auth.getDirect(targetUser.id); - if (Config.groups[roomauth]?.name) { + const roomauth = room?.auth.getDirect(targetUser.id); + if (roomauth && Config.groups[roomauth]?.name) { buf += Utils.html`
${Config.groups[roomauth].name} (${roomauth})`; } if (Config.groups[targetUser.group]?.name) { @@ -85,7 +83,7 @@ export const commands: ChatCommands = { } const canViewAlts = (user === targetUser || user.can('alts', targetUser)); const canViewPunishments = canViewAlts || - (usedRoom.settings.isPrivate !== true && user.can('mute', targetUser, usedRoom) && targetUser.id in usedRoom.users); + (room && room.settings.isPrivate !== true && user.can('mute', targetUser, room) && targetUser.id in room.users); const canViewSecretRooms = user === targetUser || (canViewAlts && targetUser.locked) || user.can('makeroom'); buf += `
`; @@ -2631,13 +2629,15 @@ export const commands: ChatCommands = { export const pages: PageTable = { punishments(query, user) { this.title = 'Punishments'; + const room = this.extractRoom(); + if (!room) return; + let buf = ""; - this.extractRoom(); if (!user.named) return Rooms.RETRY_AFTER_LOGIN; - if (!this.room.persist) return; - if (!this.can('mute', null, this.room)) return; + if (!room.persist) return; + if (!this.can('mute', null, room)) return; // Ascending order - const sortedPunishments = Array.from(Punishments.getPunishments(this.room.roomid)) + const sortedPunishments = Array.from(Punishments.getPunishments(room.roomid)) .sort((a, b) => a[1].expireTime - b[1].expireTime); const sP = new Map(); for (const punishment of sortedPunishments) { diff --git a/server/chat-commands/moderation.ts b/server/chat-commands/moderation.ts index 5470dc23d7..1e7e86a7ca 100644 --- a/server/chat-commands/moderation.ts +++ b/server/chat-commands/moderation.ts @@ -227,7 +227,7 @@ export const commands: ChatCommands = { let userLookup = ''; if (cmd === 'roomauth1') userLookup = `\n\nTo look up auth for a user, use /userauth ${target}`; let targetRoom = room; - if (target) targetRoom = Rooms.search(target) as ChatRoom | GameRoom; + if (target) targetRoom = Rooms.search(target)!; if (!targetRoom || targetRoom.roomid === 'global' || !targetRoom.checkModjoin(user)) { return this.errorReply(`The room "${target}" does not exist.`); } @@ -262,7 +262,7 @@ export const commands: ChatCommands = { const also = buffer.length === 0 ? `` : ` also`; buffer.push(`${curRoom.title} is a ${roomType}subroom of ${curRoom.parent.title}, so ${curRoom.parent.title} users${inheritedUserType}${also} have authority in this room.`); } - curRoom = curRoom.parent as ChatRoom | GameRoom; + curRoom = curRoom.parent; } if (!buffer.length) { connection.popup(`The room '${targetRoom.title}' has no auth. ${userLookup}`); @@ -375,7 +375,7 @@ export const commands: ChatCommands = { leave: 'part', part(target, room, user, connection) { const targetRoom = target ? Rooms.search(target) : room; - if (!targetRoom || targetRoom === Rooms.global) { + if (!targetRoom) { if (target.startsWith('view-')) return; return this.errorReply(`The room '${target}' does not exist.`); } @@ -1829,7 +1829,7 @@ export const commands: ChatCommands = { blacklists: 'showblacklist', showbl: 'showblacklist', showblacklist(target, room, user, connection, cmd) { - if (target) room = Rooms.search(target) as ChatRoom | GameRoom; + if (target) room = Rooms.search(target)!; if (!room) return this.errorReply(`The room "${target}" was not found.`); if (!this.can('mute', null, room)) return false; const SOON_EXPIRING_TIME = 3 * 30 * 24 * 60 * 60 * 1000; // 3 months diff --git a/server/chat-plugins/announcements.ts b/server/chat-plugins/announcements.ts index e7e4ac639d..35197b4662 100644 --- a/server/chat-plugins/announcements.ts +++ b/server/chat-plugins/announcements.ts @@ -7,11 +7,11 @@ import {Utils} from '../../lib/utils'; export class Announcement { readonly activityId: 'announcement'; announcementNumber: number; - room: ChatRoom | GameRoom; + room: Room; source: string; timeout: NodeJS.Timer | null; timeoutMins: number; - constructor(room: ChatRoom | GameRoom, source: string) { + constructor(room: Room, source: string) { this.activityId = 'announcement'; this.announcementNumber = room.nextGameNumber(); this.room = room; diff --git a/server/chat-plugins/blackjack.ts b/server/chat-plugins/blackjack.ts index bc5d2cde3b..589faa26fc 100644 --- a/server/chat-plugins/blackjack.ts +++ b/server/chat-plugins/blackjack.ts @@ -18,7 +18,7 @@ type Symbols = '♥' | '♦' | '♣' | '♠'; type SymbolName = 'Hearts' | 'Diamonds' | 'Clubs' | 'Spades'; export class Blackjack extends Rooms.RoomGame { - room: ChatRoom | GameRoom; + room: Room; blackjack: boolean; @@ -56,7 +56,7 @@ export class Blackjack extends Rooms.RoomGame { playerTable: {[k: string]: BlackjackPlayer}; gameNumber: number; - constructor(room: ChatRoom | GameRoom, user: User, autostartMinutes = 0) { + constructor(room: Room, user: User, autostartMinutes = 0) { super(room); this.gameNumber = room.nextGameNumber(); this.room = room; diff --git a/server/chat-plugins/chat-monitor.ts b/server/chat-plugins/chat-monitor.ts index 1744ed85ae..e353ca3305 100644 --- a/server/chat-plugins/chat-monitor.ts +++ b/server/chat-plugins/chat-monitor.ts @@ -6,7 +6,7 @@ type FilterWord = [RegExp, string, string, string | null, number]; type MonitorHandler = ( this: CommandContext, line: FilterWord, - room: ChatRoom | GameRoom | null, + room: Room | null, user: User, message: string, lcMessage: string, diff --git a/server/chat-plugins/daily-spotlight.ts b/server/chat-plugins/daily-spotlight.ts index 2b56a8e1cb..813e3b47c5 100644 --- a/server/chat-plugins/daily-spotlight.ts +++ b/server/chat-plugins/daily-spotlight.ts @@ -52,18 +52,20 @@ export const destroy = () => { export const pages: PageTable = { async spotlights(query, user, connection) { this.title = 'Daily Spotlights'; - this.extractRoom(); + const room = this.extractRoom(); + if (!room) return; + let buf = `

Daily Spotlights

`; - if (!spotlights[this.room.roomid]) { + if (!spotlights[room.roomid]) { buf += `

This room has no daily spotlights.

`; } else { - for (const key in spotlights[this.room.roomid]) { + for (const key in spotlights[room.roomid]) { buf += ``; - for (const [i, spotlight] of spotlights[this.room.roomid][key].entries()) { + for (const [i, spotlight] of spotlights[room.roomid][key].entries()) { const html = await renderSpotlight(spotlight.description, spotlight.image); buf += ``; // @ts-ignore room is definitely a proper room here. - if (!user.can('announce', null, this.room)) break; + if (!user.can('announce', null, room)) break; } buf += '

${key}:

${i ? i : 'Current'}${html}
'; } diff --git a/server/chat-plugins/hangman.ts b/server/chat-plugins/hangman.ts index 614e6d0026..9c120871b1 100644 --- a/server/chat-plugins/hangman.ts +++ b/server/chat-plugins/hangman.ts @@ -18,7 +18,7 @@ export class Hangman extends Rooms.RoomGame { lastGuesser: string; wordSoFar: string[]; - constructor(room: ChatRoom | GameRoom, user: User, word: string, hint = '') { + constructor(room: Room, user: User, word: string, hint = '') { super(room); this.gameNumber = room.nextGameNumber(); diff --git a/server/chat-plugins/jeopardy.ts b/server/chat-plugins/jeopardy.ts index 48b64ddab2..8bfae7e72a 100644 --- a/server/chat-plugins/jeopardy.ts +++ b/server/chat-plugins/jeopardy.ts @@ -40,7 +40,7 @@ export class Jeopardy extends Rooms.RoomGame { finals: boolean; gameNumber: number; - constructor(room: ChatRoom | GameRoom, user: User, categoryCount: number, questionCount: number) { + constructor(room: Room, user: User, categoryCount: number, questionCount: number) { super(room); this.gameNumber = room.nextGameNumber(); this.playerTable = Object.create(null); diff --git a/server/chat-plugins/lottery.ts b/server/chat-plugins/lottery.ts index 9981724989..ce98b2c256 100644 --- a/server/chat-plugins/lottery.ts +++ b/server/chat-plugins/lottery.ts @@ -264,19 +264,21 @@ export const commands: ChatCommands = { export const pages: PageTable = { lottery(query, user) { - this.extractRoom(); this.title = 'Lottery'; + const room = this.extractRoom(); + if (!room) return; + let buf = '
'; - const lottery = lotteries[this.room.roomid]; + const lottery = lotteries[room.roomid]; if (!lottery) { - buf += `

There is no lottery running in ${this.room.title}

`; + buf += `

There is no lottery running in ${room.title}

`; return buf; } buf += `

${lottery.name}

${lottery.markup}
`; if (lottery.running) { const userSignedUp = lottery.participants[user.latestIp] || Object.values(lottery.participants).map(toID).includes(user.id); - buf += ``; + buf += ``; } else { buf += '

This lottery has already ended. The winners are:

'; buf += '