node-insim
Version:
An InSim library for NodeJS with TypeScript support
101 lines (100 loc) • 3.66 kB
TypeScript
import { TypedEmitter } from 'tiny-typed-emitter';
import type { InSimEvents } from './InSimEvents';
import type { IS_ISI_Data, SendablePacket } from './packets';
import { MessageSound, packetTypeToClass } from './packets';
import type { InSimPacketClassInstance } from './packets/types';
type InSimConnectionOptions = {
Host: string;
Port: number;
Protocol?: 'TCP' | 'UDP';
};
export type InSimOptions = Omit<IS_ISI_Data, 'InSimVer'> & InSimConnectionOptions;
export declare class InSim extends TypedEmitter<InSimEvents> {
/** Currently supported InSim version */
static INSIM_VERSION: number;
private static COMMAND_PREFIX;
/** A unique identifier of the InSim connection to a specific host */
id: string;
private _options;
/** The main connection to InSim (TCP or UDP) */
private connection;
private sizeMultiplier;
constructor(id?: string);
/**
* Connect to a server via InSim.
*/
connect: (options: Omit<Partial<IS_ISI_Data>, "InSimVer"> & InSimConnectionOptions) => void;
/**
* Connect to InSim Relay.
*
* After you are connected you can request a host list, so you can see
* which hosts you can connect to.
* Then you can send a packet to the Relay to select a host. After that
* the Relay will send you all insim data from that host.
*
* Some hosts require a spectator password in order to be selectable.
*
* You do not need to specify a spectator password if you use a valid administrator password.
*
* If you connect with an administrator password, you can send just about every
* regular InSim packet there is available in LFS, just like as if you were connected
* to the host directly.
*
* Regular insim packets that a relay client can send to host:
*
* For anyone
* TINY_VER
* TINY_PING
* TINY_SCP
* TINY_SST
* TINY_GTH
* TINY_ISM
* TINY_NCN
* TINY_NPL
* TINY_RES
* TINY_REO
* TINY_RST
* TINY_AXI
*
* Admin only
* TINY_VTC
* ISP_MST
* ISP_MSX
* ISP_MSL
* ISP_MTC
* ISP_SCH
* ISP_BFN
* ISP_BTN
*
* The relay will also accept, but not forward
* TINY_NONE // for relay-connection maintenance
*/
connectRelay: () => void;
private _connect;
disconnect: () => void;
send: (packet: SendablePacket) => void;
get options(): InSimOptions;
/**
* Send a message or command to LFS
*
* If the message starts with a slash (`/`), it will be treated as a command.
* Otherwise, it will be treated as a message.
*
* The maximum length of the message is {@link MSX_MSG_MAX_LENGTH} characters.
*/
sendMessage: (message: string) => void;
/**
* Send a message which will appear on the local computer only.
*
* The maximum length of the message is {@link MSL_MSG_MAX_LENGTH} characters.
*/
sendLocalMessage: (message: string, sound?: MessageSound) => void;
/** Send a message to a specific connection */
sendMessageToConnection: (ucid: number, message: string, sound?: MessageSound) => void;
/** Send a message to a specific player */
sendMessageToPlayer: (plid: number, message: string, sound?: MessageSound) => void;
sendAwait: <TPacketTypeToAwait extends keyof typeof packetTypeToClass>(packet: SendablePacket, packetTypeToAwait: TPacketTypeToAwait, filterPacketData?: (packet: InSimPacketClassInstance<TPacketTypeToAwait>) => boolean) => Promise<InSimPacketClassInstance<TPacketTypeToAwait>>;
private handlePacket;
private handleKeepAlive;
}
export {};