Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Peer

A class that represents a connected peer

Hierarchy

  • Peer

Index

Constructors

constructor

  • Creates a new instance of the peer

    Parameters

    • server: Server

      The instance of the server

    • Optional data: PeerData

      The user data of the peer

    Returns Peer

Properties

Optional data

data: PeerData

The user data of the peer

Private server

server: Server

The instance of the server

Methods

add_item_to_inventory

  • add_item_to_inventory(id: number, amount?: number): Promise<void>
  • Adds an item from the inventory

    Parameters

    • id: number

      The id of the item

    • Optional amount: number

      The amount to add

    Returns Promise<void>

alreadyInCache

  • alreadyInCache(userID?: number): Promise<PeerData | null>
  • Whether or not a player is already in cache

    Parameters

    • Optional userID: number

      The user id to use for filter, if not specified, will use the connectID.

    Returns Promise<PeerData | null>

audio

  • audio(file: string, delay?: number): void
  • Plays an audio file.

    Parameters

    • file: string

      The name of the file

    • Optional delay: number

      The delay, in ms on when to play.

    Returns void

cloth_packet

  • cloth_packet(silenced?: boolean): Variant
  • Returns the packet for clothing

    Parameters

    • Optional silenced: boolean

      Whether or not to play the sfx when wearing clothes. Defaults to false

    Returns Variant

create

  • create(data: PeerData, saveToCache?: boolean): Promise<void>
  • Creates a new player to be saved to the database. This will also set the data property of a peer

    Parameters

    • data: PeerData

      The data of the peer to create

    • Optional saveToCache: boolean

      Whether or not to save the data to cache as well. Defaults to false

    Returns Promise<void>

disconnect

  • disconnect(type?: "later" | "now"): Promise<void>
  • Disconnects a peer

    Parameters

    • Optional type: "later" | "now"

      The type of disconnection.

    Returns Promise<void>

fetch

  • fetch(type: "cache" | "db", filter?: PeerData): Promise<void>
  • Fetches the peer data from the cache or database

    Parameters

    • type: "cache" | "db"

      Where to fetch the data

    • Optional filter: PeerData

    Returns Promise<void>

hasPlayerData

  • hasPlayerData(): boolean
  • Check if proper player data is present.

    Returns boolean

inventory

  • inventory(): void

isConnected

  • isConnected(): boolean
  • Whether or not a peer is connected

    Returns boolean

join

  • join(name: string, isSuperMod?: boolean): Promise<void>
  • Joins a world

    Parameters

    • name: string

      The name of the world

    • Optional isSuperMod: boolean

      Whether or not the player joining is a super mod. Defaults to false

    Returns Promise<void>

leave

  • leave(sendToMenu?: boolean): Promise<void>
  • Makes the current peer leave the current world he is in.

    Parameters

    • Optional sendToMenu: boolean

      Whether or not to send the peer to the world menu. Defaults to false.

    Returns Promise<void>

remove_item_from_inventory

  • remove_item_from_inventory(id: number, amount?: number): Promise<void>
  • Removes an item from the inventory

    Parameters

    • id: number

      The id of the item

    • Optional amount: number

      The amount to remove

    Returns Promise<void>

requestLoginInformation

  • requestLoginInformation(): void
  • Request the login information from the peer. This will emit the "receive" event.

    Returns void

saveToCache

  • saveToCache(): Promise<void>
  • Saves player data to the cache.

    Returns Promise<void>

saveToDb

  • saveToDb(): Promise<void>
  • Saves the player to the database.

    Returns Promise<void>

send

send_multiple

  • Sends multiple packets to a peer.

    Parameters

    • Rest ...data: SendableData[]

      The data to send. Not an array but argument parameters.

    Returns void

setOnline

  • setOnline(cache: boolean, online?: boolean): Promise<void>
  • Sets the status of a player

    Parameters

    • cache: boolean

      Whether or not to save to cache

    • Optional online: boolean

      Whether or not to set it as offline or online. Defaults to false

    Returns Promise<void>

world

  • world(name: string, fetchDataAfter?: boolean): World
  • world(fetchDataAfter?: boolean): World
  • Creates a new world class then returns it.

    Parameters

    • name: string

      The name of the world

    • Optional fetchDataAfter: boolean

      Whether or not to auto-fetch the world data from either the cache or the database. Defaults to false.

    Returns World

  • Creates a new world class then returns it

    Parameters

    • Optional fetchDataAfter: boolean

      Whehter or not to auto-fetch the world data from either the cache or the database. Defaults to false

    Returns World

Generated using TypeDoc