///
///
import dgram from "dgram";
import { DisconnectReason, Language, QuickChatMode } from "@skeldjs/constant";
import { VersionInfo } from "@skeldjs/util";
import { BaseRootPacket, PlatformSpecificData } from "@skeldjs/protocol";
import { Worker } from "./Worker";
import { BaseRoom } from "./BaseRoom";
export declare class SentPacket {
readonly nonce: number;
readonly buffer: Buffer;
sentAt: number;
acked: boolean;
constructor(nonce: number, buffer: Buffer, sentAt: number, acked: boolean);
}
export declare const logLanguages: {
0: string;
1: string;
2: string;
3: string;
4: string;
5: string;
6: string;
7: string;
8: string;
9: string;
10: string;
11: string;
12: string;
14: string;
13: string;
15: string;
};
export declare const logPlatforms: {
0: string;
1: string;
2: string;
3: string;
4: string;
5: string;
6: string;
7: string;
8: string;
9: string;
10: string;
};
export declare const locales: {
0: string;
1: string;
2: string;
3: string;
4: string;
5: string;
6: string;
7: string;
8: string;
9: string;
10: string;
11: string;
12: string;
14: string;
13: string;
15: string;
};
export declare class Connection {
/**
* The server that this client is connected to.
*/
readonly worker: Worker;
/**
* The socket that this client connected to.
*/
readonly listenSocket: dgram.Socket;
/**
* Remote information about this client.
*/
readonly remoteInfo: dgram.RemoteInfo;
/**
* The server-unique client ID for this client, see {@link Worker.getNextClientId}.
*/
readonly clientId: number;
/**
* Whether the client has successfully identified with the server.
*
* Requires the client sending a {@link ModdedHelloPacket} (optional extension
* of [0x08 Hello](https://github.com/codyphobe/among-us-protocol/blob/master/01_packet_structure/05_packet_types.md#0x08-hello))
*/
hasIdentified: boolean;
/**
* Whether a disconnect packet has been sent to this client.
*
* Used to avoid an infinite loop of sending disconnect confirmations
* back and forth.
*/
sentDisconnect: boolean;
/**
* The username that this client identified with. Sent with the {@link Connection.hasIdentified identify}
* packet.
*/
username: string;
/**
* The chat mode setting that the client has enabled.
*/
chatMode: QuickChatMode;
/**
* The language that the client identified with.
*/
language: Language;
/**
* The version of the client's game. Sent with the {@link Connection.hasIdentified identify}
* packet.
*/
clientVersion: VersionInfo;
/**
* The specific platform that this client is playing on.
*/
platform: PlatformSpecificData;
/**
* This client's level/rank.
*/
playerLevel: number;
/**
* The last nonce that was received by this client.
*
* Used to prevent duplicate packets with the same nonce.
*/
nextExpectedNonce: number;
private _incrNonce;
/**
* An array of the 8 latest packets that were sent to this client. Used to
* re-send packets that have not been acknowledged.
*/
sentPackets: SentPacket[];
/**
* 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.
*/
receivedPackets: number[];
/**
* The round-trip ping for this connection. Calculated very roughly by calculating
* the time it takes for each reliable packet to be acknowledged.
*/
roundTripPing: number;
/**
* A map of messages that were sent out-of-order to allow the server to execute
* them when needed.
*/
unorderedMessageMap: Map;
/**
* The room that this client is in.
*/
room?: BaseRoom;
constructor(
/**
* The server that this client is connected to.
*/
worker: Worker,
/**
* The socket that this client connected to.
*/
listenSocket: dgram.Socket,
/**
* Remote information about this client.
*/
remoteInfo: dgram.RemoteInfo,
/**
* The server-unique client ID for this client, see {@link Worker.getNextClientId}.
*/
clientId: number);
/**
* A formatted address for this connection.
* @example
* ```ts
* console.log(connection.address); // => 127.0.0.1:22023
* ```
*/
get address(): string;
/**
* Get this client's player in the room that they're connected to.
* @example
* ```ts
* connection.player.setName("obama");
* ```
*/
getPlayer(): import("@skeldjs/core").PlayerData | undefined;
/**
* Get the next nonce to use for a reliable packet for this connection.
* @returns An incrementing nonce.
* @example
* ```ts
* 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
* ```
*/
getNextNonce(): number;
/**
* 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.
* @param packet The root packet to send.
* @example
* ```ts
* connection.sendPacket(
* new ReliablePacket(
* connection.getNextNonce(),
* [
* new HostGameMessage("ALBERT")
* ]
* )
* );
* ```
*/
sendPacket(packet: BaseRootPacket): Promise;
getLocale(i18n: Record): string | undefined;
fgetLocale(i18n: Record, ...fmt: string[]): string | undefined;
/**
* Gracefully disconnect the client for this connection.
*
* Note that this does not remove this connection from the server, see {@link Worker.removeConnection}.
* @param reason The reason for why the client is being disconnected. Set to
* a string to use a custom message.
* @param message If the reason is custom, the message for why the client
* is being disconnected.
* @example
* ```ts
* // Disconnect a player for hacking.
* await player.connection.disconnect(DisconnectReason.Hacking);
* ```
*
* ```ts
* // Disconnect a player for a custom reason.
* await player.connection.disconnect("You have been very naughty.");
* ```
*/
disconnect(reason?: string | DisconnectReason | Record, ...message: string[]): Promise;
/**
* Force this client to leave their current game. Primarily for {@link Room.destroy}
* although exposed as a function for any other possible uses.
*
* Sends a [RemoveGame](https://github.com/codyphobe/among-us-protocol/blob/master/02_root_message_types/03_removegame.md)
* packet and does not immediately disconnect, although the client should do
* this shortly after receiving the message.
* @param reason The reason to close the game.
*/
leaveRoom(reason?: DisconnectReason): Promise;
}