Hierarchy

  • Connection

Accessors

  • get address(): string
  • A formatted address for this connection.

    Example

    console.log(connection.address); // => 127.0.0.1:22023
    

    Returns string

Properties

chatMode: QuickChatMode

The chat mode setting that the client has enabled.

clientId: number

The server-unique client ID for this client, see getNextClientId.

clientVersion: VersionInfo

The version of the client's game. Sent with the identify packet.

hasIdentified: boolean

Whether the client has successfully identified with the server.

Requires the client sending a ModdedHelloPacket (optional extension of 0x08 Hello)

language: Language

The language that the client identified with.

listenSocket: Socket

The socket that this client connected to.

nextExpectedNonce: number

The last nonce that was received by this client.

Used to prevent duplicate packets with the same nonce.

The specific platform that this client is playing on.

playerLevel: number

This client's level/rank.

receivedPackets: number[]

An array of the 8 latest packet nonces that were received from this client. Used to re-send acknowledgements that the client did not receive.

remoteInfo: RemoteInfo

Remote information about this client.

room?: BaseRoom

The room that this client is in.

roundTripPing: number

The round-trip ping for this connection. Calculated very roughly by calculating the time it takes for each reliable packet to be acknowledged.

sentDisconnect: boolean

Whether a disconnect packet has been sent to this client.

Used to avoid an infinite loop of sending disconnect confirmations back and forth.

sentPackets: SentPacket[]

An array of the 8 latest packets that were sent to this client. Used to re-send packets that have not been acknowledged.

unorderedMessageMap: Map<number, BaseRootPacket>

A map of messages that were sent out-of-order to allow the server to execute them when needed.

username: string

The username that this client identified with. Sent with the identify packet.

worker: Worker

The server that this client is connected to.

Constructors

  • Parameters

    • worker: Worker

      The server that this client is connected to.

    • listenSocket: Socket

      The socket that this client connected to.

    • remoteInfo: RemoteInfo

      Remote information about this client.

    • clientId: number

      The server-unique client ID for this client, see getNextClientId.

    Returns Connection

Methods

  • Gracefully disconnect the client for this connection.

    Note that this does not remove this connection from the server, see removeConnection.

    Example

    // Disconnect a player for hacking.
    await player.connection.disconnect(DisconnectReason.Hacking);
    // Disconnect a player for a custom reason.
    await player.connection.disconnect("You have been very naughty.");

    Parameters

    • Optional reason: string | DisconnectReason | Record<string, string>

      The reason for why the client is being disconnected. Set to a string to use a custom message.

    • Rest ...message: string[]

      If the reason is custom, the message for why the client is being disconnected.

    Returns Promise<void>

  • Parameters

    • i18n: Record<string, string>
    • Rest ...fmt: string[]

    Returns undefined | string

  • Parameters

    • i18n: Record<string, string>

    Returns undefined | string

  • Get the next nonce to use for a reliable packet for this connection.

    Returns

    An incrementing nonce.

    Example

    console.log(connection.getNextNonce()); // => 1
    console.log(connection.getNextNonce()); // => 2
    console.log(connection.getNextNonce()); // => 3
    console.log(connection.getNextNonce()); // => 4
    console.log(connection.getNextNonce()); // => 5

    Returns number

  • Force this client to leave their current game. Primarily for destroy although exposed as a function for any other possible uses.

    Sends a RemoveGame packet and does not immediately disconnect, although the client should do this shortly after receiving the message.

    Parameters

    • reason: DisconnectReason = DisconnectReason.ServerRequest

      The reason to close the game.

    Returns Promise<void>

  • Serialize and reliable or unreliably send a packet to this client.

    For reliable packets, packets sent will be reliably recorded and marked for re-sending if the client does not send an acknowledgement for the packet.

    Example

    connection.sendPacket(
    new ReliablePacket(
    connection.getNextNonce(),
    [
    new HostGameMessage("ALBERT")
    ]
    )
    );

    Parameters

    Returns Promise<void>

Generated using TypeDoc