///
import { DisconnectReason, GameOverReason } from "@skeldjs/constant";
import { BaseGameDataMessage, BaseMessage, BaseRootMessage, ComponentSpawnData, GameSettings, PacketDecoder, PlayerJoinData } from "@skeldjs/protocol";
import { CustomNetworkTransform, EndGameIntent, Hostable, HostableEvents, Networkable, PlayerData, PlayerDataResolvable } from "@skeldjs/core";
import { BasicEvent, ExtractEventTypes } from "@skeldjs/events";
import { ClientLeaveEvent, ClientBroadcastEvent, RoomBeforeDestroyEvent, RoomCreateEvent, RoomDestroyEvent, RoomGameEndEvent, RoomGameStartEvent, RoomSelectHostEvent, EventTarget as EventTarget } from "../api";
import { SendChatOptions, RoomsConfig } from "../interfaces";
import { RoomPlugin, ChatCommandHandler, WorkerPlugin, LoadedPlugin } from "../handlers";
import { Logger } from "../logger";
import { Connection } from "./Connection";
import { PacketContext, Worker } from "./Worker";
import { Perspective, PresetFilter } from "./Perspective";
export declare enum SpecialClientId {
Nil = 2147483647,
Server = 2147483646,
Temp = 2147483645
}
export declare const logMaps: {
0: string;
1: string;
2: string;
3: string;
4: string;
};
export declare type RoomEvents = HostableEvents & ExtractEventTypes<[
ClientBroadcastEvent,
ClientLeaveEvent,
RoomBeforeDestroyEvent,
RoomCreateEvent,
RoomDestroyEvent,
RoomGameEndEvent,
RoomGameStartEvent,
RoomSelectHostEvent
]>;
export declare class BaseRoom extends Hostable {
/**
* The worker that instantiated this object.
*/
readonly worker: Worker;
/**
* The config for the room, the worker uses the worker's {@link HindenburgConfig.rooms} config to initialise it as.
*/
readonly config: RoomsConfig;
/**
* The unix (milliseconds) timestamp. that the room was created.
*/
createdAt: number;
protected playerJoinedFlag: boolean;
/**
* All connections in the room, mapped by client ID to connection object.
*/
connections: Map;
/**
* The connections/players that are waiting for the host to join back.
*/
waitingForHost: Set;
/**
* Player perspectives for each player, mapped by clientId to perspective object.
*/
playerPerspectives: Map;
/**
* A map of objects to their respective perspective owner.
*/
ownershipGuards: Map;
/**
* An array of every player perspective created in the room.
*/
activePerspectives: Perspective[];
/**
* Whether or not acting hosts are enabled on this room.
*/
actingHostsEnabled: boolean;
/**
* The client IDs of every acting host in the room.
*/
actingHostIds: Set;
/**
* This room's console logger.
*/
logger: Logger;
/**
* All IP addresses banned from this room.
*/
bannedAddresses: Set;
/**
* Player that the server is waiting to finish joining before resetting all
* acting hosts back.
*/
actingHostWaitingFor: PlayerData[];
/**
* All plugins loaded and scoped to the worker when this room was created, mapped by plugin id to worker plugin object.
*/
workerPlugins: Map>;
/**
* All plugins loaded and scoped to the room, mapped by plugin id to room plugin object.
*/
loadedPlugins: Map>;
/**
* The chat command handler in the room.
*/
chatCommandHandler: ChatCommandHandler;
/**
* A packet decoder for the room to decode and handle incoming packets.
*/
decoder: PacketDecoder;
protected finishedActingHostTransactionRoutine: boolean;
protected roomNameOverride: string;
protected eventTargets: EventTarget[];
constructor(
/**
* The worker that instantiated this object.
*/
worker: Worker,
/**
* The config for the room, the worker uses the worker's {@link HindenburgConfig.rooms} config to initialise it as.
*/
config: RoomsConfig,
/**
* The game settings for the room.
*/
settings: GameSettings);
registerPacketHandlers(): void;
protected _reset(): void;
emit(event: Event): Promise;
emit(event: Event): Promise;
emitSerial(event: Event): Promise;
emitSerial(event: Event): Promise;
emitSync(event: Event): Event;
emitSync(event: Event): Event;
formatName(name: string): string;
get host(): PlayerData | undefined;
/**
* An array of all acting hosts in the room.
*/
getActingHosts(): PlayerData[];
get hostIsMe(): boolean;
/**
* The name of the room, or just the code formatted as a string.
*
* @example REDSUS
* @example LOCAL
*/
get roomName(): string;
/**
* Whether or not this room has been destroyed, and is no longer active on the server.
*/
get destroyed(): boolean;
/**
* Destroy this room.
* @param reason Reason for the destroying the room.
*/
destroy(reason?: DisconnectReason): Promise;
FixedUpdate(): Promise;
spawnComponent(component: Networkable): void;
despawnComponent(component: Networkable): void;
/**
* 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 {@link BaseRoom.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 `undefined`s.
* @param players The list of players to get connections for.
* @returns All real connections for the players provided.
*/
getRealConnections(players: PlayerDataResolvable[]): Connection[];
/**
* 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`.
* @param players The players to get connections for.
* @returns A list of connections for the players, in the same order.
*/
getConnections(players: PlayerDataResolvable[]): (Connection | undefined)[];
/**
* Get the client-server connection of a player.
* @returns The connection of the player, or undefined if they only exist on the server.
*/
getConnection(player: PlayerDataResolvable): Connection | undefined;
/**
* Ban player from a room
* @param connection The connection or the player that should be banned.
* @param messages The messages in that the banned player gets displayed.
*/
banPlayer(connection: Connection | PlayerData, message?: string): void;
/**
* Broadcast [GameData messages](https://github.com/codyphobe/among-us-protocol/blob/master/03_gamedata_and_gamedatato_message_types/README.md)
* and root messages to all or some connections.
*
* Sends GameDataTo if a filter is applied with the include parameter.
* @param gamedata The [GameData messages](https://github.com/codyphobe/among-us-protocol/blob/master/03_gamedata_and_gamedatato_message_types/README.md)
* to send.
* @param payloads The [Root messages](https://github.com/codyphobe/among-us-protocol/blob/master/02_root_message_types/README.md)
* to send.
* @param include The connections to include in the broadcast.
* @param exclude The connections to exclude in the broadcast.
* @returns A promise that resolves when all packets have been sent.
* @example
* ```ts
* // Broadcast a scenechange message.
* await room.broadcastMessages([
* new SceneChangeMessage(0, "OnlineGame")
* ]);
* ```
*/
broadcastMessages(gamedata: BaseGameDataMessage[], payloads?: BaseRootMessage[], include?: Connection[], exclude?: Connection[], reliable?: boolean): Promise;
broadcastMovement(component: CustomNetworkTransform, data: Buffer): Promise;
broadcast(gameData: BaseGameDataMessage[], payloads?: BaseRootMessage[], include?: PlayerDataResolvable[], exclude?: PlayerDataResolvable[], reliable?: boolean): Promise;
processMessagesAndGetNotCanceled(messages: BaseMessage[], notCanceled: BaseMessage[], ctx: PacketContext): Promise;
setCode(code: number | string): Promise;
/**
* Update the host for the room or for a specific client.
* @param hostId The host to set.
* @param recipient The specific client recipient if required.
*/
updateHostForClient(hostId: number, recipient?: Connection): Promise;
/**
* Set the actual host for the room, cannot be used in rooms using SaaH.
* @param playerResolvable The player to set as the host.
*/
setHost(playerResolvable: PlayerDataResolvable): Promise;
/**
* Enable SaaH (Server-as-a-Host) on this room.
*
* Does nothing particularly special except tell clients that the server is now the host.
* @param saahEnabled Whether or not SaaH should be enabled.
* @param addActingHost Whether or not to add the current host as an acting host
*/
enableSaaH(addActingHost: boolean): Promise;
/**
* 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.
* @param saahEnabled Whether or not SaaH should be enabled.
* @param addActingHost Whether or not to add the current host as an acting host
*/
disableSaaH(): Promise;
/**
* Set whether SaaH is enabled on this room, calling either {@link BaseRoom.enableSaaH} or
* {@link BaseRoom.disableSaaH}.
* and tell clients the new host (unless they are an acting host.).
* @param saahEnabled Whether or not SaaH should be enabled.
* @param addActingHost Whether or not to add the current host as an acting host
*/
setSaaHEnabled(saahEnabled: boolean, addActingHost: boolean): Promise;
/**
* Add another acting host to a Server-As-A-Host room.
* @param player The player to make host.
*/
addActingHost(player: PlayerData | Connection): Promise;
/**
* Remove an acting host from a Server-As-A-Host room.
* @param player The player to remove as host.
*/
removeActingHost(player: PlayerData | Connection): Promise;
/**
* 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 {@link BaseRoom.enableActingHosts}.
*/
disableActingHosts(): Promise;
/**
* Enable acting hosts on the room.
*/
enableActingHosts(): Promise;
/**
* Set whether or not acting hosts are enabled, calling either {@link BaseRoom.disableActingHosts}
* or {@link BaseRoom.enableActingHosts}.
* @param actingHostsEnabled Whether or not to enable acting hosts
*/
setActingHostsEnabled(actingHostsEnabled: boolean): Promise;
handleJoin(joinInfo: PlayerJoinData): Promise>;
handleRemoteJoin(joiningClient: Connection): Promise;
handleRemoteLeave(leavingConnection: Connection, reason?: DisconnectReason): Promise;
private _joinOtherClients;
handleStart(): Promise;
startGame(): Promise;
handleEnd(reason: GameOverReason, intent?: EndGameIntent): Promise;
endGame(reason: GameOverReason, intent?: EndGameIntent): Promise;
protected spawnUnknownPrefab(spawnType: number, ownerId: number | PlayerData | undefined, flags: number, componentData: (any | ComponentSpawnData)[], doBroadcast?: boolean, doAwake?: boolean): Networkable | undefined;
private getOtherPlayer;
private _sendChatFor;
/**
* 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.
* @param message The message to send.
* @param options Options for the method.
* @example
* ```ts
* // Tell a player off if they use a bad word.
* .@EventListener("player.sentchat")
* onPlayerChat(ev: PlayerChatEvent) {
* 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("You used a bad word there, mister.", { target: ev.player });
* }
* }
* }
* ```
*/
sendChat(message: string, options?: Partial): Promise;
/**
* 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.
* @param roomName The name of the room to use instead.
*/
setRoomNameOverride(roomName: string): void;
/**
* Clear a room name override made with {@link BaseRoom.setRoomNameOverride}.
*/
clearRoomNameOverride(): void;
/**
* Creates a fake dummy player without a connected client.
* @param isNew Whether or not this player should be considered as "joining" the room,
* i.e. whether they should hop off their seat in the lobby.
* @param setCosmetics Whether or not default cosmetics should be set for this player,
* i.e. whether they should be immediately visible as a player.
* @param isRecorded Whether or not the player should appear in {@link GameData}. If not,
* they won't count as an actual player and will live (mostly) off-the-grid.
* @returns The created player.
* @example
* ```ts
* const player = room.createFakePlayer();
*
* ...
*
* room.removeFakePlayer(player);
* ```
*/
createFakePlayer(isNew?: boolean, setCosmetics?: boolean, isRecorded?: boolean): PlayerData;
/**
* Short-hand for removing a fake player created with {@link BaseRoom.createFakePlayer}. This will
* despawn the player immediately.
* @param player The fake player to remove from the game.
* @example
* ```ts
* const player = room.createFakePlayer();
*
* ...
*
* room.removeFakePlayer(player);
* ```
*/
removeFakePlayer(player: PlayerData): void;
registerEventTarget(observer: EventTarget): void;
removeEventTarget(observer: EventTarget): void;
createPerspective(players: PlayerData | PlayerData[], filters: PresetFilter[]): Perspective;
guardObjectAsOwner(networkable: Networkable): void;
disownObject(networkable: Networkable): void;
getOwnerOf(networkable: Networkable): BaseRoom | undefined;
}