import { PlayerData, SystemStatus, SystemType, PlayerDataResolvable, Networkable } from "@skeldjs/core"; import { BaseGameDataMessage, BaseRootMessage, BaseMessage, MessageDirection } from "@skeldjs/protocol"; import { MasketDecoder } from "../util/MasketDecoder"; import { Worker } from "./Worker"; import { BaseRoom } from "./BaseRoom"; import { Connection } from "./Connection"; export declare type AllSystems = Map>; /** * Preset perspective filters to use with {@link Room.createPerspective}. */ export declare enum PresetFilter { /** * Block all gamedata updates: * * {@link SetNameMessage} * * {@link SetColorMessage} * * {@link SetHatMessage} * * {@link SetPetMessage} * * {@link SetSkinMessage} */ GameDataUpdates = 0, /** * Block all movement packets from players: * * {@link DataMessage} (only those coming from {@link CustomNetworkTransform} objects) */ PositionUpdates = 1, /** * Block all room settings updates: * * {@link SyncSettingsMessage} */ SettingsUpdates = 2, /** * Block all chat messages: * * {@link SendChatMessage} */ ChatMessages = 3, /** * Block all updates for any objects: * * {@link SpawnMessage} * * {@link DespawnMessage} */ ObjectUpdates = 4 } /** * Syntactic sugar for a {@link MasketDecoder}, used in perspectives as a way * to filter incoming and outgoing packets, see {@link Perspective.incomingFilter}. */ export declare class PerspectiveFilter extends MasketDecoder { constructor(worker: Worker); } /** * Represents the entire room from the perspective of a set of players. * Different from the {@link Room}, it allows you to create an entire space * completely separate, affecting only specified players. Think of it like a * sandbox which acts as a mirror, and as a space which allows plugins and * players to do anything without affecting the original room. * * As a mirror, it is initially a perfect clone of the original room. It has filters, * which allow you to control which incoming packets get sent to the perspective, * and which outgoing packets get sent to the room. See {@link Room.createPerspective} * and {@link PresetFilter} for preset filters to use. * * Overtime, the perspective will get more and more out of sync with the original * room. When destroyed, all players will be brought back up-to-date with the * current state of the room. * * This class shouldn't be instantiated directly, instead, see {@link Room.createPerspective}. * * @example * ```ts * // Make every other player appear black and without a name for somePlayer. * * const perspective = room.createPerspective(somePlayer, [ * PerspectiveFilter.gameDataUpdates * ]); // Create a perspective for somePlayer, filtering out gamedata updates (names, colours, hats, etc.) * * for (const [ , player ] of perspective.players) { * player.control?.setColor(Color.Black); * player.control?.setName("?????"); * player.control?.setHat(Hat.None); * player.control?.setPet(Pet.None); * player.control?.setSkin(Skin.None); * } * * await sleep(10000); * * perspective.destroyPerspective(); // destroy and restore state for players in this perspective * ``` */ export declare class Perspective extends BaseRoom { /** * The original room that this perspective is mirroring. */ readonly parentRoom: BaseRoom; /** * The players that this perspective is from the perspective of. Every * player object is from the original {@link Room} object, rather than * this perspective object. */ readonly playersPov: PlayerData[]; /** * Filter for packets making their way into the perspective. See {@link Perspective.outgoingFilter} * for handling outgoing packets. * * @example * ```ts * perspective.incomingFilter.on([ SetColorMessage, SetNameMessage, SetSkinMessage, SetPetMessage, SetHatMessage ], message => { * message.cancel(); * }); * ``` */ incomingFilter: PerspectiveFilter; /** * Filter for packets making their way out of the perspective into the room. * See {@link Perspective.incomingFilter} to handle incoming packets. * * By default, this is different from the incoming filter. You can manually * re-assign it to {@link incomingFilter} to have the same filters for * both incoming and outgoing packets. * * @example * ```ts * perspective.outgoingFilter = perspective.incomingFilter; * * perspective.outgoingFilter.on([ SetColorMessage, SetNameMessage, SetSkinMessage, SetPetMessage, SetHatMessage ], message => { * message.cancel(); * }); * ``` */ outgoingFilter: PerspectiveFilter; messageNonce: Set; /** * @internal */ constructor( /** * The original room that this perspective is mirroring. */ parentRoom: BaseRoom, /** * The players that this perspective is from the perspective of. Every * player object is from the original {@link Room} object, rather than * this perspective object. */ playersPov: PlayerData[], /** * Filter for packets making their way into the perspective. See {@link Perspective.outgoingFilter} * for handling outgoing packets. * * @example * ```ts * perspective.incomingFilter.on([ SetColorMessage, SetNameMessage, SetSkinMessage, SetPetMessage, SetHatMessage ], message => { * message.cancel(); * }); * ``` */ incomingFilter: PerspectiveFilter, /** * Filter for packets making their way out of the perspective into the room. * See {@link Perspective.incomingFilter} to handle incoming packets. * * By default, this is different from the incoming filter. You can manually * re-assign it to {@link incomingFilter} to have the same filters for * both incoming and outgoing packets. * * @example * ```ts * perspective.outgoingFilter = perspective.incomingFilter; * * perspective.outgoingFilter.on([ SetColorMessage, SetNameMessage, SetSkinMessage, SetPetMessage, SetHatMessage ], message => { * message.cancel(); * }); * ``` */ outgoingFilter: PerspectiveFilter); private cloneSystems; getNextNetId(): number; static applyPerspectiveFilter(perspective: Perspective, decoder: PerspectiveFilter, filters: PresetFilter[], direction: "incoming" | "outgoing"): void; broadcast(gameData: BaseGameDataMessage[], payloads?: BaseRootMessage[], include?: PlayerDataResolvable[], exclude?: PlayerDataResolvable[], reliable?: boolean): Promise; getNotCanceledIncoming(messages: BaseMessage[], direction: MessageDirection, sender?: Connection): Promise; getNotCanceledOutgoing(messages: BaseMessage[], direction: MessageDirection, sender?: Connection): Promise; isCanceledIncoming(message: BaseMessage, direction: MessageDirection, sender?: Connection): Promise; isCanceledOutgoing(message: BaseMessage, direction: MessageDirection, sender?: Connection): Promise; /** * Destroy this perspective, optionally restoring state for any players that * have been affected by it. * * @param restoreState Whether to restore state for players in this perspective. */ destroyPerspective(restoreState?: boolean): Promise; createPerspective(): Perspective; /** * Resolve a player by some identifier, taking into account the player in the perspective. * @param player The identifier to resolve to a player. * @returns The resolved player * @example * ```ts * const playerPov = perspective.resolvePlayer(originalPlayer); * ``` */ resolvePlayer(player: PlayerDataResolvable): PlayerData | undefined; /** * Guard an object so that no other room (or perspective) can make changes to it. * * This is useful when perspectives create conflicts and state becomes unmanageable; * just assign its logic to one room. * * Note that this is only a nominal change; plugins can still make changes freely - the only * change is that packets won't be managed by rooms that the object does not belong to. * @param netObject The object to own */ guardObjectAsOwner(netObject: Networkable): void; /** * Unknown an object so that all rooms can make changes to it. * @param netObject The object to disown */ disownObject(netObject: Networkable): void; /** * Get the owner of an object. * @param netObject The object to disown */ getOwnerOf(netObject: Networkable): BaseRoom | undefined; canManageObject(object: Networkable): boolean; }