Represents an object capable of hosting games.

See HostableEvents for events to listen to.

Hierarchy

Properties

Methods

Constructors

Accessors

Properties

FixedUpdateInterval: number

How often a FixedUpdate should be called.

actingHostIds: Set<number>

The client IDs of every acting host in the room.

actingHostWaitingFor: PlayerData<BaseRoom>[]

Player that the server is waiting to finish joining before resetting all acting hosts back.

actingHostsEnabled: boolean

Whether or not acting hosts are enabled on this room.

activePerspectives: Perspective[]

An array of every player perspective created in the room.

bannedAddresses: Set<string>

All IP addresses banned from this room.

chatCommandHandler: ChatCommandHandler

The chat command handler in the room.

code: number

The code of the room.

config: RoomsConfig

The config for the room, the worker uses the worker's rooms config to initialise it as.

connections: Map<number, Connection>

All connections in the room, mapped by client ID to connection object.

counter: number

The current start counter for the room.

createdAt: number

The unix (milliseconds) timestamp. that the room was created.

createdBy: undefined | Connection

A packet decoder for the room to decode and handle incoming packets.

endGameIntents: EndGameIntent<any>[]

Every end game intent that should happen in a queue to be or not to be canceled.

The first item of each element being the name of the end game intent and the second being metadata passed with it.

See RoomEndGameIntentEvent to cancel an end game intent, or see registerEndGameIntent to register your own.

See RoomGameEndEvent to listen for a game actually ending.

gameData: undefined | GameData<BaseRoom>

An instance of the game data in the room. Contains information about players such as their name, colour, hat etc.

It is possible for more than one game data to be spawned, however this property is set and cleared for simplicity.

See objectList if you're looking to find all game data objects that have been spawned.

gameState: GameState

The state that the game is currently in.

hostId: number

The ID of the host of the room.

loadedPlugins: Map<string, LoadedPlugin<typeof RoomPlugin>>

All plugins loaded and scoped to the room, mapped by plugin id to room plugin object.

lobbyBehaviour: undefined | LobbyBehaviour<BaseRoom>

An instance of the lobby behaviour in the room. Spawned when the room is currently in the lobby waiting for a game to start.

It is possible for more than one lobby behaviour to be spawned, however this property is set and cleared for simplicity.

See objectList if you're looking to find all lobby behaviour objects that have been spawned.

logger: Logger

This room's console logger.

meetingHud: undefined | MeetingHud<BaseRoom>

An instance of the meeting hud in the room. Spawned when a meeting is started.

It is possible for more than one meeting hud to be spawned, however this property is set and cleared for simplicity.

See objectList if you're looking to find all meeting hud objects that have been spawned.

messageStream: BaseGameDataMessage[]

The current message stream to be sent to the server on fixed update.

netobjects: Map<number, Networkable<any, NetworkableEvents<Hostable<any>>, BaseRoom>>

The networkable components in the room.

objectList: Networkable<any, NetworkableEvents<Hostable<any>>, Hostable<any>>[]

A list of all objects in the room.

ownershipGuards: Map<number, BaseRoom>

A map of objects to their respective perspective owner.

playerPerspectives: Map<number, Perspective>

Player perspectives for each player, mapped by clientId to perspective object.

players: Map<number, PlayerData<BaseRoom>>

The players in the room.

privacy: PrivacyType

The privacy state of the room.

registeredPrefabs: Map<number, NetworkableConstructor<any>[]>

A map of spawn type -> objects used in the protocol. Useful to register custom INO (inner net objects) such as replicating behaviour from a client mod, see registerPrefab.

registeredRoles: Map<number, typeof BaseRole>

All roles that can be assigned to players. See registerRole.

settings: GameSettings

The settings of the room.

shipStatus: undefined | InnerShipStatus<BaseRoom>

An instance of the ship status in the room. Spawned when a game is started and represents the current map.

It is possible for more than one ship status to be spawned, however this property is set and cleared for simplicity.

See objectList if you're looking to find all ship status objects that have been spawned.

voteBanSystem: undefined | VoteBanSystem<BaseRoom>

An instance of the voting ban system in the room. Used as a utility object for handling kick and ban votes.

It is possible for more than one vote ban system to be spawned, however this property is set and cleared for simplicity.

See objectList if you're looking to find all vote ban system objects that have been spawned.

waitingForHost: Set<Connection>

The connections/players that are waiting for the host to join back.

worker: Worker

The worker that instantiated this object.

workerPlugins: Map<string, LoadedPlugin<typeof WorkerPlugin>>

All plugins loaded and scoped to the worker when this room was created, mapped by plugin id to worker plugin object.

Methods

  • Returns void

  • Creates a fake dummy player without a connected client.

    Returns

    The created player.

    Example

    const player = room.createFakePlayer();

    ...

    room.removeFakePlayer(player);

    Parameters

    • isNew: boolean = false

      Whether or not this player should be considered as "joining" the room, i.e. whether they should hop off their seat in the lobby.

    • setCosmetics: boolean = true

      Whether or not default cosmetics should be set for this player, i.e. whether they should be immediately visible as a player.

    • isRecorded: boolean = false

      Whether or not the player should appear in GameData. If not, they won't count as an actual player and will live (mostly) off-the-grid.

    Returns PlayerData<BaseRoom>

  • Disable acting hosts on the room, leaving either no hosts if the server is in SaaH mode, or leaving 1 host otherwise. It doesn't clear the list of acting hosts, just disables them from being in use.

    This function will prevent any acting hosts from being assigned at any point until enabled again with enableActingHosts.

    Returns Promise<void>

  • Disable SaaH (Server-as-a-Host) on this room, assigning a new host (the first acting host if available), and tell clients the new host (unless they are an acting host.).

    Does nothing particularly special except tell clients that the server is now the host.

    Returns Promise<void>

  • Enable SaaH (Server-as-a-Host) on this room.

    Does nothing particularly special except tell clients that the server is now the host.

    Parameters

    • addActingHost: boolean

      Whether or not to add the current host as an acting host

    Returns Promise<void>

  • Get an available player ID.

    Returns

    The player ID that was found.

    Example

    // Get an available player ID and add it to the gamedata.
    const playerId = room.getAvailablePlayerID();
    room.gamedata.add(playerId);

    Returns number

  • Get all client-server connections for a list of players. If a player only exists ont he server, i.e. they are being controlled by a remote client/real player, their place in the list will be undefined.

    Returns

    A list of connections for the players, in the same order.

    Parameters

    Returns (undefined | Connection)[]

  • Type Parameters

    • Event extends BasicEvent<Event> = BasicEvent

    Parameters

    • event: string

    Returns Listener<Event>[]

  • Returns number

  • Get a player by one of their components' netIds.

    Returns

    The player that was found, or null if they do not exist.

    Example

    const player = room.getPlayerByNetId(34);
    

    Parameters

    • netId: number

      The net ID of the component of the player to search.

    Returns undefined | PlayerData<BaseRoom>

  • Get a player by their player ID.

    Returns

    The player that was found, or null if they do not exist.

    Example

    const player = room.getPlayerByPlayerId(1);
    

    Parameters

    • playerId: number

      The player ID of the player.

    Returns undefined | PlayerData<BaseRoom>

  • Get all real client-server connections for a list of players. That is, connections for all players that are being controlled by a remote client/real player.

    See getConnections to get connections for a list of players and returned in the same order & place as the players provided, although some connections may not exist, resulting in undefineds.

    Returns

    All real connections for the players provided.

    Parameters

    Returns Connection[]

  • Type Parameters

    • EventName extends "component.spawn" | "component.despawn" | "player.checkcolor" | "player.checkmurder" | "player.checkname" | "player.checkprotect" | "player.completetask" | "player.die" | "player.usemovingplatform" | "player.murder" | "player.protect" | "player.removeprotection" | "player.reportbody" | "player.revertshapeshift" | "player.chat" | "player.quickchat" | "player.setcolor" | "player.sethat" | "player.setname" | "player.setnameplate" | "player.setpet" | "player.setrole" | "player.setskin" | "player.setstartcounter" | "player.setvisor" | "player.shapeshift" | "player.startmeeting" | "player.syncsettings" | "player.entervent" | "player.exitvent" | "player.climbladder" | "player.move" | "player.snapto" | "player.ready" | "player.join" | "player.leave" | "player.sethost" | "player.scenechange" | "player.spawn" | "gamedata.addplayer" | "gamedata.removeplayer" | "gamedata.settasks" | "meeting.castvote" | "meeting.clearvote" | "meeting.votingcomplete" | "meeting.close" | "doors.open" | "doors.close" | "system.sabotage" | "system.repair" | "decon.doors.close" | "decon.doors.open" | "decon.enter" | "decon.exit" | "hqhud.consoles.reset" | "hqhud.consoles.open" | "hqhud.consoles.close" | "hqhud.consoles.complete" | "heli.consoles.open" | "heli.consoles.reset" | "heli.consoles.close" | "heli.consoles.complete" | "o2.consoles.clear" | "o2.consoles.complete" | "medscan.joinqueue" | "medscan.leavequeue" | "movingplatform.updateplayer" | "reactor.consoles.add" | "reactor.consoles.remove" | "reactor.consoles.reset" | "security.cameras.join" | "security.cameras.leave" | "electrical.switchflip" | "room.assignroles" | "room.endgameintent" | "room.fixedupdate" | "room.gameend" | "room.gamestart" | "room.setprivacy" | "client.broadcast" | "client.leave" | "room.beforedestroy" | "room.create" | "room.destroy" | "room.selecthost"

    Parameters

    • event: EventName
    • listener: Listener<RoomEvents[EventName]>

    Returns void

  • Type Parameters

    • K extends BasicEvent<K>

    Parameters

    • event: string
    • listener: Listener<K>

    Returns void

  • Type Parameters

    • EventName extends "component.spawn" | "component.despawn" | "player.checkcolor" | "player.checkmurder" | "player.checkname" | "player.checkprotect" | "player.completetask" | "player.die" | "player.usemovingplatform" | "player.murder" | "player.protect" | "player.removeprotection" | "player.reportbody" | "player.revertshapeshift" | "player.chat" | "player.quickchat" | "player.setcolor" | "player.sethat" | "player.setname" | "player.setnameplate" | "player.setpet" | "player.setrole" | "player.setskin" | "player.setstartcounter" | "player.setvisor" | "player.shapeshift" | "player.startmeeting" | "player.syncsettings" | "player.entervent" | "player.exitvent" | "player.climbladder" | "player.move" | "player.snapto" | "player.ready" | "player.join" | "player.leave" | "player.sethost" | "player.scenechange" | "player.spawn" | "gamedata.addplayer" | "gamedata.removeplayer" | "gamedata.settasks" | "meeting.castvote" | "meeting.clearvote" | "meeting.votingcomplete" | "meeting.close" | "doors.open" | "doors.close" | "system.sabotage" | "system.repair" | "decon.doors.close" | "decon.doors.open" | "decon.enter" | "decon.exit" | "hqhud.consoles.reset" | "hqhud.consoles.open" | "hqhud.consoles.close" | "hqhud.consoles.complete" | "heli.consoles.open" | "heli.consoles.reset" | "heli.consoles.close" | "heli.consoles.complete" | "o2.consoles.clear" | "o2.consoles.complete" | "medscan.joinqueue" | "medscan.leavequeue" | "movingplatform.updateplayer" | "reactor.consoles.add" | "reactor.consoles.remove" | "reactor.consoles.reset" | "security.cameras.join" | "security.cameras.leave" | "electrical.switchflip" | "room.assignroles" | "room.endgameintent" | "room.fixedupdate" | "room.gameend" | "room.gamestart" | "room.setprivacy" | "client.broadcast" | "client.leave" | "room.beforedestroy" | "room.create" | "room.destroy" | "room.selecthost"

    Parameters

    • event: EventName
    • listener: Listener<RoomEvents[EventName]>

    Returns (() => void)

      • (): void
      • Returns void

  • Type Parameters

    • K extends BasicEvent<K>

    Parameters

    • event: string
    • listener: Listener<K>

    Returns (() => void)

      • (): void
      • Returns void

  • Type Parameters

    • EventName extends "component.spawn" | "component.despawn" | "player.checkcolor" | "player.checkmurder" | "player.checkname" | "player.checkprotect" | "player.completetask" | "player.die" | "player.usemovingplatform" | "player.murder" | "player.protect" | "player.removeprotection" | "player.reportbody" | "player.revertshapeshift" | "player.chat" | "player.quickchat" | "player.setcolor" | "player.sethat" | "player.setname" | "player.setnameplate" | "player.setpet" | "player.setrole" | "player.setskin" | "player.setstartcounter" | "player.setvisor" | "player.shapeshift" | "player.startmeeting" | "player.syncsettings" | "player.entervent" | "player.exitvent" | "player.climbladder" | "player.move" | "player.snapto" | "player.ready" | "player.join" | "player.leave" | "player.sethost" | "player.scenechange" | "player.spawn" | "gamedata.addplayer" | "gamedata.removeplayer" | "gamedata.settasks" | "meeting.castvote" | "meeting.clearvote" | "meeting.votingcomplete" | "meeting.close" | "doors.open" | "doors.close" | "system.sabotage" | "system.repair" | "decon.doors.close" | "decon.doors.open" | "decon.enter" | "decon.exit" | "hqhud.consoles.reset" | "hqhud.consoles.open" | "hqhud.consoles.close" | "hqhud.consoles.complete" | "heli.consoles.open" | "heli.consoles.reset" | "heli.consoles.close" | "heli.consoles.complete" | "o2.consoles.clear" | "o2.consoles.complete" | "medscan.joinqueue" | "medscan.leavequeue" | "movingplatform.updateplayer" | "reactor.consoles.add" | "reactor.consoles.remove" | "reactor.consoles.reset" | "security.cameras.join" | "security.cameras.leave" | "electrical.switchflip" | "room.assignroles" | "room.endgameintent" | "room.fixedupdate" | "room.gameend" | "room.gamestart" | "room.setprivacy" | "client.broadcast" | "client.leave" | "room.beforedestroy" | "room.create" | "room.destroy" | "room.selecthost"

    Parameters

    • event: EventName
    • listener: Listener<RoomEvents[EventName]>

    Returns (() => void)

      • (): void
      • Returns void

  • Type Parameters

    • K extends BasicEvent<K>

    Parameters

    • event: string
    • listener: Listener<K>

    Returns (() => void)

      • (): void
      • Returns void

  • Register an intent to end the game.

    Parameters

    • endGameIntent: EndGameIntent<any>

      The intention to end the game.

    Returns void

  • Register a role that can be assigned to a player.

    Parameters

    • roleCtr: typeof BaseRole

      The role to register to the room.

    Returns void

  • Returns void

  • Parameters

    • event: string

    Returns void

  • Resolve a client id by some identifier.

    Returns

    The resolved client ID.

    Parameters

    Returns undefined | number

  • Resolve a player ID by some identifier.

    Returns

    The resolved player ID.

    Parameters

    Returns undefined | number

  • Send a message into the chat as the server. Requries game data to be spawned, can only send messages on the left side of the chat room if there is at least 2 players in the room.

    Summary

    If on the right side, for each player the room sets their name and colour, sends the message then immediately sets them back.

    If on the left side, for each player the room finds a different player, sets their name and colour and immediately sets them back after sending the message. If there is no other player, it shows it on the right side instead.

    Example

    // Tell a player off if they use a bad word.
    .@EventListener("player.sentchat")
    onPlayerChat(ev: PlayerChatEvent<Room>) {
    const badWords = [ "sprout", "barney" ];

    for (const word of badWords) {
    if (ev.chatMessage.includes(word)) {
    ev.message.cancel(); // Don't broadcast the message to other players
    ev.room.sendChat("<color=red>You used a bad word there, mister.</color>", { target: ev.player });
    }
    }
    }

    Parameters

    • message: string

      The message to send.

    • options: Partial<SendChatOptions> = {}

      Options for the method.

    Returns Promise<boolean>

  • Set the code of the room.

    Example

    room.setCode("ABCDEF");
    

    Parameters

    • code: string | number

    Returns Promise<void>

  • Change the the privacy of the room.

    Example

    room.setAlterGameTag(AlterGameTag.ChangePrivacy, 1); // 0 for private, 1 for public.
    

    Parameters

    Returns Promise<void>

  • Add an override for the name of the room. Can be used anywhere, but only used in Among Us in the "find public games" list.

    Parameters

    • roomName: string

      The name of the room to use instead.

    Returns void

  • Set whether SaaH is enabled on this room, calling either enableSaaH or disableSaaH. and tell clients the new host (unless they are an acting host.).

    Parameters

    • saahEnabled: false

      Whether or not SaaH should be enabled.

    Returns Promise<void>

  • Set whether SaaH is enabled on this room, calling either enableSaaH or disableSaaH. and tell clients the new host (unless they are an acting host.).

    Parameters

    • saahEnabled: true

      Whether or not SaaH should be enabled.

    • addActingHost: boolean

      Whether or not to add the current host as an acting host

    Returns Promise<void>

  • Set whether SaaH is enabled on this room, calling either enableSaaH or disableSaaH. and tell clients the new host (unless they are an acting host.).

    Parameters

    • saahEnabled: boolean

      Whether or not SaaH should be enabled.

    • addActingHost: boolean

      Whether or not to add the current host as an acting host, if SaaH is being enabled.

    Returns Promise<void>

  • Change the settings of the room. If the host, it will broadcast these changes.

    Example

    room.syncSettings({
    crewmateVision: 0.5,
    votingTime: 120
    });

    Parameters

    • settings: Partial<AllGameSettings>

      The settings to set to (Can be partial).

    Returns void

  • Returns void

  • Spawn a prefab of an object.

    Returns

    The object that was spawned.

    Example

    room.spawnPrefab(SpawnType.Player, client.myPlayer);
    

    Parameters

    • spawnType: number

      The type of object to spawn.

    • ownerId: undefined | number | PlayerData<Hostable<any>>
    • Optional flags: number
    • Optional componentData: any[]
    • Optional doBroadcast: boolean
    • Optional doAwake: boolean

    Returns undefined | Networkable<any, any, BaseRoom>

  • Update the host for the room or for a specific client.

    Parameters

    • hostId: number

      The host to set.

    • Optional recipient: Connection

      The specific client recipient if required.

    Returns Promise<void>

  • Type Parameters

    • EventName extends "component.spawn" | "component.despawn" | "player.checkcolor" | "player.checkmurder" | "player.checkname" | "player.checkprotect" | "player.completetask" | "player.die" | "player.usemovingplatform" | "player.murder" | "player.protect" | "player.removeprotection" | "player.reportbody" | "player.revertshapeshift" | "player.chat" | "player.quickchat" | "player.setcolor" | "player.sethat" | "player.setname" | "player.setnameplate" | "player.setpet" | "player.setrole" | "player.setskin" | "player.setstartcounter" | "player.setvisor" | "player.shapeshift" | "player.startmeeting" | "player.syncsettings" | "player.entervent" | "player.exitvent" | "player.climbladder" | "player.move" | "player.snapto" | "player.ready" | "player.join" | "player.leave" | "player.sethost" | "player.scenechange" | "player.spawn" | "gamedata.addplayer" | "gamedata.removeplayer" | "gamedata.settasks" | "meeting.castvote" | "meeting.clearvote" | "meeting.votingcomplete" | "meeting.close" | "doors.open" | "doors.close" | "system.sabotage" | "system.repair" | "decon.doors.close" | "decon.doors.open" | "decon.enter" | "decon.exit" | "hqhud.consoles.reset" | "hqhud.consoles.open" | "hqhud.consoles.close" | "hqhud.consoles.complete" | "heli.consoles.open" | "heli.consoles.reset" | "heli.consoles.close" | "heli.consoles.complete" | "o2.consoles.clear" | "o2.consoles.complete" | "medscan.joinqueue" | "medscan.leavequeue" | "movingplatform.updateplayer" | "reactor.consoles.add" | "reactor.consoles.remove" | "reactor.consoles.reset" | "security.cameras.join" | "security.cameras.leave" | "electrical.switchflip" | "room.assignroles" | "room.endgameintent" | "room.fixedupdate" | "room.gameend" | "room.gamestart" | "room.setprivacy" | "client.broadcast" | "client.leave" | "room.beforedestroy" | "room.create" | "room.destroy" | "room.selecthost"

    Parameters

    • event: EventName

    Returns Promise<RoomEvents[EventName]>

  • Parameters

    • event: string

    Returns Promise<BasicEvent>

  • Type Parameters

    • EventName extends "component.spawn" | "component.despawn" | "player.checkcolor" | "player.checkmurder" | "player.checkname" | "player.checkprotect" | "player.completetask" | "player.die" | "player.usemovingplatform" | "player.murder" | "player.protect" | "player.removeprotection" | "player.reportbody" | "player.revertshapeshift" | "player.chat" | "player.quickchat" | "player.setcolor" | "player.sethat" | "player.setname" | "player.setnameplate" | "player.setpet" | "player.setrole" | "player.setskin" | "player.setstartcounter" | "player.setvisor" | "player.shapeshift" | "player.startmeeting" | "player.syncsettings" | "player.entervent" | "player.exitvent" | "player.climbladder" | "player.move" | "player.snapto" | "player.ready" | "player.join" | "player.leave" | "player.sethost" | "player.scenechange" | "player.spawn" | "gamedata.addplayer" | "gamedata.removeplayer" | "gamedata.settasks" | "meeting.castvote" | "meeting.clearvote" | "meeting.votingcomplete" | "meeting.close" | "doors.open" | "doors.close" | "system.sabotage" | "system.repair" | "decon.doors.close" | "decon.doors.open" | "decon.enter" | "decon.exit" | "hqhud.consoles.reset" | "hqhud.consoles.open" | "hqhud.consoles.close" | "hqhud.consoles.complete" | "heli.consoles.open" | "heli.consoles.reset" | "heli.consoles.close" | "heli.consoles.complete" | "o2.consoles.clear" | "o2.consoles.complete" | "medscan.joinqueue" | "medscan.leavequeue" | "movingplatform.updateplayer" | "reactor.consoles.add" | "reactor.consoles.remove" | "reactor.consoles.reset" | "security.cameras.join" | "security.cameras.leave" | "electrical.switchflip" | "room.assignroles" | "room.endgameintent" | "room.fixedupdate" | "room.gameend" | "room.gamestart" | "room.setprivacy" | "client.broadcast" | "client.leave" | "room.beforedestroy" | "room.create" | "room.destroy" | "room.selecthost"

    Parameters

    • event: EventName
    • filter: ((ev: RoomEvents[EventName]) => boolean | Promise<boolean>)
        • (ev: RoomEvents[EventName]): boolean | Promise<boolean>
        • Parameters

          Returns boolean | Promise<boolean>

    Returns Promise<RoomEvents[EventName]>

  • Type Parameters

    • K extends BasicEvent<K>

    Parameters

    • event: string
    • filter: ((ev: K) => boolean | Promise<boolean>)
        • (ev: K): boolean | Promise<boolean>
        • Parameters

          • ev: K

          Returns boolean | Promise<boolean>

    Returns Promise<BasicEvent>

Constructors

Accessors

  • get destroyed(): boolean
  • Whether or not this room has been destroyed, and is no longer active on the server.

    Returns boolean

  • get hostIsMe(): boolean
  • Whether or not the current client is the host of the room.

    Returns boolean

  • get myPlayer(): undefined | PlayerData<this>
  • The current client in the room.

    Returns undefined | PlayerData<this>

  • get roomName(): string
  • The name of the room, or just the code formatted as a string.

    Example

    REDSUS
    

    Example

    LOCAL
    

    Returns string

Generated using TypeDoc