### Install battleye-node Source: https://github.com/devkirkir/battleye-node/blob/main/README.md Install the battleye-node library using npm. ```sh npm install battleye-node ``` -------------------------------- ### Configuration Clamping Example Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/configuration.md Demonstrates how connectionTimeout and connectionInterval values are clamped to their minimums during RCON client initialization. ```typescript const rcon = new RCON({ address: "127.0.0.1", port: 2302, password: "mypass", connectionTimeout: 20000, // will become 50000 connectionInterval: 2000, // will become 5000 keepAliveInterval: 5000, // will stay 5000 }); ``` -------------------------------- ### UDPSocket Full Lifecycle Example Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/UDPSocket.md Demonstrates the complete lifecycle of a UDPSocket, including creation, setting up a message listener, sending a login buffer, and closing the socket after a delay. Ensure the correct configuration object with address, port, password, and connection type is provided. ```typescript import { UDPSocket } from "battleye-node"; import { bufferLogin } from "battleye-node"; const config = { address: "127.0.0.1", port: 2302, password: "mypass", connectionType: "udp4" as const, }; // Create socket const udp = new UDPSocket(config); // Set up message listener udp.socket.on("message", (msg) => { console.log("Response:", msg); }); // Send login udp.send(bufferLogin("mypass")); // Later: close socket setTimeout(() => { udp.close(); console.log("Socket closed"); }, 5000); ``` -------------------------------- ### RCON Constructor Example Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/RCON.md Instantiates the RCON class with connection configuration. Ensure all required parameters like address, port, and password are provided. ```typescript import RCON from "battleye-node"; const rcon = new RCON({ address: "127.0.0.1", port: 2302, password: "your_rcon_password", connectionType: "udp4", connectionTimeout: 50000, connectionInterval: 5000, keepAliveInterval: 10000, }); ``` -------------------------------- ### Connection Timeout with Default Interval Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/configuration.md Example demonstrating the default connection timeout and interval. The client will attempt to log in for 50 seconds with retries every 5 seconds. ```typescript // 50000 ms timeout / 5000 ms interval = 10 retry attempts const rcon = new RCON({ address: "127.0.0.1", port: 2302, password: "mypass", }); ``` -------------------------------- ### Runtime Configuration Change Example Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/configuration.md Illustrates that RCON configuration cannot be changed after instantiation. A new RCON instance must be created to apply different settings. ```typescript let rcon = new RCON({ address: "127.0.0.1", port: 2302, password: "mypass", }); // To change settings, create a new instance rcon.logout(); rcon = new RCON({ address: "127.0.0.1", port: 2303, // different port password: "newpass", }); rcon.login(); ``` -------------------------------- ### UDPSocket Usage within RCON Class Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/UDPSocket.md Illustrates how UDPSocket is instantiated and managed within the RCON class for login and logout operations. It shows the setup of the message listener and the conditional closing of the socket. ```typescript // In RCON.login() this.udp = new UDPSocket(this.config); this.udp.socket.on("message", (msg: Buffer) => this.onMessage(msg)); this.udp.send(bufferLogin(this.config.password)); // In RCON.logout() if (this.udp?.isSocketOpen) { this.udp.close(); } ``` -------------------------------- ### Handle RCON 'error' Events and Reconnection Logic Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/RCON.md Handle 'error' events to catch authentication failures, connection timeouts, or queue issues. This example logs errors and includes logic to attempt a manual reconnect if the server is not responding. ```typescript rcon.on("error", (msg) => { console.error("RCON Error:", msg); if (msg.includes("not responding")) { // Attempt manual reconnect rcon.logout(); setTimeout(() => rcon.login(), 5000); } }); ``` -------------------------------- ### parsePacket Function Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/types.md Parses a raw UDP message buffer into a typed packet object. Returns null if the buffer is invalid or does not start with the BattlEye magic header. ```APIDOC ### parsePacket Parses a raw UDP message buffer into a typed packet object. #### Signature ```typescript function parsePacket(msg: Buffer): BEPacket | null ``` #### Parameters | Parameter | Type | Description | |-----------|------|-------------| | msg | Buffer | Raw UDP message buffer from the server | #### Return Type `BEPacket | null` — Parsed packet object if the buffer is a valid BattlEye packet, `null` if the buffer is invalid or does not start with the BattlEye magic header ``` -------------------------------- ### RCON Class Initialization and Basic Usage Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/index.md Demonstrates how to instantiate the RCON class with connection details and perform basic operations like login, sending a command, and logging out. ```APIDOC ## RCON Class ### Description The `RCON` class is the main interface for interacting with BattlEye RCon servers. It provides methods for establishing a connection, sending commands, and handling server responses. ### Methods - **`constructor(config: Config)`**: Initializes a new RCON client instance. - **`login(): Promise`**: Attempts to log in to the RCON server. - **`commandSend(command: string): Promise`**: Sends a command to the RCON server and returns the response. - **`logout(): Promise`**: Disconnects from the RCON server. ### Events - **`onConnect(isConnected: boolean)`**: Emitted when the connection status changes. - **`message(msg: string)`**: Emitted when a message is received from the server. - **`error(msg: string)`**: Emitted when an error occurs. ### Example Usage ```typescript import RCON from "battleye-node"; const rcon = new RCON({ address: "127.0.0.1", port: 2302, password: "rcon_password", }); rcon.login(); rcon.commandSend("players"); rcon.logout(); ``` ### Event-Driven Usage Example ```typescript rcon.on("onConnect", (isConnected) => { console.log("Connected:", isConnected); }); rcon.on("message", (msg) => { console.log("Response:", msg); }); rcon.on("error", (msg) => { console.error("Error:", msg); }); ``` ``` -------------------------------- ### Initialize and Use RCON Client Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/index.md Demonstrates how to initialize the RCON client with connection details, log in, send a command, and log out. Ensure you have the correct address, port, and password for your BattlEye server. ```typescript import RCON from "battleye-node"; const rcon = new RCON({ address: "127.0.0.1", port: 2302, password: "rcon_password", }); rcon.login(); rcon.commandSend("players"); rcon.logout(); ``` -------------------------------- ### Initialize and Use RCON Client Source: https://github.com/devkirkir/battleye-node/blob/main/README.md Initialize the RCON client with server details and demonstrate sending commands and handling events. Ensure to replace placeholder values with your actual server information. ```typescript import RCON from "battleye-node"; const rcon = new RCON({ address: "127.0.0.1", port: 2302, password: "your_rcon_password", connectionType: "udp4", // or "udp6" connectionTimeout: 50000, // in ms (default 50000, min 50000) connectionInterval: 5000, // in ms (default 5000, min 5000) keepAliveInterval: number, // in ms (default 10000) }); // Login rcon.login(); // Send a command rcon.commandSend("say -1 'Hello, world!'"); rcon.commandSend("players"); rcon.commandSend("#shutdown"); // Check connection status console.log(rcon.isRconConnected); // Logout rcon.logout(); // Events rcon.on("onConnect", (isConnected) => { console.log(isConnected); }); rcon.on("message", (msg) => { console.log(msg); }); rcon.on("error", (msg) => { console.log(msg); }); ``` -------------------------------- ### login() Source: https://github.com/devkirkir/battleye-node/blob/main/README.md Establishes a connection to the BattlEye RCon server. ```APIDOC ## login() ### Description Connects to the BattlEye RCon server. ### Method None (Method call on RCON instance) ### Endpoint None ### Parameters None ### Request Example ```typescript rcon.login(); ``` ### Response None (This is a method call, not a network response) ### Events Emitted - `onConnect` - `message` - `error` ``` -------------------------------- ### Instantiate UDPSocket Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/UDPSocket.md Demonstrates how to create a new UDPSocket instance with the required configuration. Ensure the configuration object includes address, port, password, and connectionType. ```typescript import { UDPSocket } from "battleye-node"; const config = { address: "127.0.0.1", port: 2302, password: "mypass", connectionType: "udp4" as const, }; const udp = new UDPSocket(config); console.log(udp.isSocketOpen); // true ``` -------------------------------- ### RCON Constructor Usage with Config Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/types.md Demonstrates how to instantiate the RCON class with a configuration object. Ensure all required fields like address, port, and password are provided. ```typescript import RCON from "battleye-node"; const config: Config = { address: "192.168.1.100", port: 2302, password: "secure_rcon_password", connectionType: "udp4", connectionTimeout: 60000, connectionInterval: 5000, keepAliveInterval: 10000, }; const rcon = new RCON(config); ``` -------------------------------- ### login Method Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/RCON.md Initiates connection to the BattlEye RCon server using the configured password. Emits 'onConnect' on success and 'error' on failure. ```APIDOC ## Method: login ### Description Initiates connection to the BattlEye RCon server. Sends an authentication packet with the configured password. If already connected, logs an error message and returns early. ### Signature ```typescript login(): void ``` ### Parameters None ### Return Type `void` ### Behavior - Opens UDP socket if not already open - Sends login buffer with the configured password - Starts connection attempt loop with retry intervals - Emits `"onConnect"` event when authentication succeeds - Emits `"error"` event if authentication fails or connection times out ### Example ```typescript const rcon = new RCON({ address: "127.0.0.1", port: 2302, password: "mypassword", }); rcon.on("onConnect", (isConnected) => { console.log("Connected:", isConnected); }); rcon.login(); ``` ``` -------------------------------- ### Basic RCON Connection and Event Handling Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/index.md Establishes an RCON connection to a game server and sets up event listeners for connection status, messages, and errors. Use this to initiate communication with the server. ```typescript import RCON from "battleye-node"; const rcon = new RCON({ address: "game.example.com", port: 2302, password: "secret", }); rcon.on("onConnect", (connected) => { if (connected) { console.log("Logged in"); rcon.commandSend("players"); } else { console.log("Disconnected"); } }); rcon.on("message", (msg) => { console.log(msg); }); rcon.on("error", (msg) => { console.error(msg); }); rcon.login(); ``` -------------------------------- ### RCON Constructor Source: https://github.com/devkirkir/battleye-node/blob/main/README.md Initializes a new RCON client with the specified configuration options. ```APIDOC ## RCON Constructor ### Description Initializes a new RCON client with the specified configuration options. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Constructor Parameters - **address** (string) - Required - The IP address of the BattlEye RCon server. - **port** (number) - Required - The port of the BattlEye RCon server. - **password** (string) - Required - The password for RCon authentication. - **connectionType** ("udp4" | "udp6") - Optional - The type of UDP connection to use. - **connectionTimeout** (number) - Optional - The connection timeout in milliseconds. - **connectionInterval** (number) - Optional - The interval for connection attempts in milliseconds. - **keepAliveInterval** (number) - Optional - The interval for keep-alive messages in milliseconds. ``` -------------------------------- ### UDPSocket Constructor Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/UDPSocket.md Initializes a new UDPSocket instance with the provided configuration. It creates and opens the UDP socket. ```APIDOC ## Constructor UDPSocket ### Description Initializes a new UDPSocket instance with the provided configuration. It creates and opens the UDP socket. ### Signature ```typescript constructor(config: UDPConfig) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **config** (UDPConfig) - Required - Configuration object with address, port, password, and connectionType ### Request Example ```typescript import { UDPSocket } from "battleye-node"; const config = { address: "127.0.0.1", port: 2302, password: "mypass", connectionType: "udp4" as const, }; const udp = new UDPSocket(config); console.log(udp.isSocketOpen); // true ``` ### Response #### Success Response (200) None #### Response Example None ### Source `src/UDPSocket.ts:11-16` ``` -------------------------------- ### Full RCON Client Configuration Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/configuration.md Initialize the RCON client with all available configuration options, including custom values for connection type, timeouts, and intervals. ```typescript import RCON from "battleye-node"; const rcon = new RCON({ address: "game-server.example.com", port: 2302, password: "secure_rcon_password", connectionType: "udp4", connectionTimeout: 90000, // 90 seconds for slow networks connectionInterval: 10000, // retry every 10 seconds keepAliveInterval: 15000, // keep-alive every 15 seconds }); ``` -------------------------------- ### Usage of LoginPacket Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/Protocol.md Demonstrates how to parse a buffer and check for a LoginPacket, then access its success status. ```typescript import { parsePacket } from "battleye-node"; const packet = parsePacket(buffer); if (packet && packet.type === 0) { if (packet.success) { console.log("Login successful"); } else { console.log("Login failed - invalid password"); } } ``` -------------------------------- ### Usage of CommandPacket Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/Protocol.md Shows how to parse a buffer and identify a CommandPacket, then log its sequence and message. ```typescript import { parsePacket } from "battleye-node"; const packet = parsePacket(buffer); if (packet && packet.type === 1) { console.log(`Command ${packet.sequence} response: ${packet.message}`); } ``` -------------------------------- ### Import BattlEye Node Client (ES Modules) Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/index.md Import the RCON class using import for ES Module environments. ```javascript import RCON from "battleye-node"; const rcon = new RCON({ /* ... */ }); ``` -------------------------------- ### Import BattlEye Node Client (CommonJS) Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/index.md Import the RCON class using require for CommonJS environments. ```javascript const RCON = require("battleye-node"); const rcon = new RCON({ /* ... */ }); ``` -------------------------------- ### Basic BattlEye Packet Parsing Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/Protocol.md Demonstrates how to parse a simulated BattlEye UDP message and handle different packet types (login success, command response, server message). ```typescript import { parsePacket } from "battleye-node"; // Simulated UDP message from server (login success) const buffer = Buffer.from([0x42, 0x45, ...crc..., 0x00, 0x00, 0x01]); const packet = parsePacket(buffer); if (!packet) { console.log("Invalid packet"); return; } switch (packet.type) { case 0: console.log("Login", packet.success ? "OK" : "FAILED"); break; case 1: console.log(`Response [${packet.sequence}]: ${packet.message}`); break; case 2: console.log(`Message: ${packet.message}`); break; } ``` -------------------------------- ### Send Data with UDPSocket Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/UDPSocket.md Shows how to use the `send` method to transmit data buffers to the BattlEye server. This method is asynchronous and does not guarantee delivery. ```typescript import { bufferLogin } from "battleye-node"; const udp = new UDPSocket(config); // Send a login packet const loginBuf = bufferLogin("mypassword"); udp.send(loginBuf); // Send a command packet const cmdBuf = bufferCommand("players", 1); udp.send(cmdBuf); ``` -------------------------------- ### RCON Constructor Options Source: https://github.com/devkirkir/battleye-node/blob/main/README.md Defines the configuration options available when initializing the RCON client. These parameters control connection details and behavior. ```typescript address: string; port: number; password: string; connectionType?: "udp4" | "udp6"; connectionTimeout?: number; connectionInterval?: number; keepAliveInterval?: number; }); ``` -------------------------------- ### Minimal RCON Client Configuration Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/configuration.md Initialize the RCON client with only the required parameters: address, port, and password. All optional parameters will use their default values. ```typescript import RCON from "battleye-node"; const rcon = new RCON({ address: "127.0.0.1", port: 2302, password: "rcon_password", }); // Uses all defaults: // connectionType: "udp4" // connectionTimeout: 50000 // connectionInterval: 5000 // keepAliveInterval: 10000 ``` -------------------------------- ### commandSend(command: string) Source: https://github.com/devkirkir/battleye-node/blob/main/README.md Sends a command to the BattlEye RCon server. ```APIDOC ## commandSend(command: string) ### Description Sends a command to the BattlEye RCon server. ### Method None (Method call on RCON instance) ### Endpoint None ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **command** (string) - Required - The command to send to the server. ### Request Example ```typescript rcon.commandSend("say -1 'Hello, world!'"); rcon.commandSend("players"); ``` ### Response None (This is a method call, and responses are handled via the 'message' event) ### Events Emitted - `message` (for command responses) ``` -------------------------------- ### Access UDPSocket Configuration Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/UDPSocket.md Demonstrates how to access the configuration details stored within a UDPSocket instance. This can be useful for debugging or verifying connection parameters. ```typescript const udp = new UDPSocket(config); console.log(udp.config.address); // "127.0.0.1" console.log(udp.config.port); // 2302 console.log(udp.config.connectionType); // "udp4" ``` -------------------------------- ### Login to BattlEye RCON Server Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/RCON.md Initiates the connection to the BattlEye RCon server and handles connection events. Use this to establish a session. ```typescript const rcon = new RCON({ address: "127.0.0.1", port: 2302, password: "mypassword", }); rcon.on("onConnect", (isConnected) => { console.log("Connected:", isConnected); }); rcon.login(); ``` -------------------------------- ### Import BattlEye Node Client (TypeScript) Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/index.md Import the RCON class and Config type for TypeScript projects. ```typescript import RCON from "battleye-node"; import type { Config } from "battleye-node"; const config: Config = { /* ... */ }; const rcon = new RCON(config); ``` -------------------------------- ### bufferAck Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/Buffers.md Constructs a BattlEye acknowledgment packet for server-initiated messages. ```APIDOC ## Function: bufferAck Constructs an acknowledgment packet for server-initiated messages (type 2). ### Signature ```typescript function bufferAck(sequence: number): Buffer ``` ### Parameters #### Path Parameters - **sequence** (number) - Required - Sequence number of the message being acknowledged ### Return Type `Buffer` — Complete acknowledgment packet ready to send via UDP ### Packet Structure | Bytes | Content | Notes | |-------|---------|-------| | 0-1 | "BE" | Magic header (0x42, 0x45) | | 2-5 | CRC32 | Checksum of payload (little-endian) | | 6 | 0x00 | Reserved byte | | 7-8 | 0xFF, 0x02 | Acknowledgment packet type identifier | | 9 | sequence | Sequence number of message being ACKed | ### Behavior - Creates an acknowledgment for a server-initiated message - Packet size is fixed at 10 bytes - Used to confirm receipt of type 2 packets from the server ### Example ```typescript import { bufferAck } from "battleye-node"; // Server sent a message with sequence 42 const ack = bufferAck(42); console.log(ack.length); // Always 10 bytes // Send ACK back to server // udpSocket.send(ack, 0, ack.length, port, address); ``` ### Source `src/buffers/bufferAck.ts` ``` -------------------------------- ### bufferCommand Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/types.md Constructs a command packet with the given command and sequence number. This function is typically used internally by the library. ```APIDOC ## bufferCommand ### Description Constructs a command packet with the given command and sequence number. This function is typically used internally by the library. ### Method `bufferCommand(command: string, sequence: number): Buffer` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **command** (string) - Required - The command to send (ASCII) - **sequence** (number) - Required - Sequence number (0-255) to match responses ### Returns - `Buffer`: Buffer containing the complete command packet with BattlEye header and CRC32 checksum. ### Request Example ```typescript // Example usage (typically internal) import { bufferCommand } from "battleye-node"; const commandPacket = bufferCommand("status", 1); ``` ``` -------------------------------- ### commandSend Method Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/RCON.md Sends a command to the BattlEye server. The command is only sent if the client is connected and the request queue is not saturated. ```APIDOC ## Method: commandSend ### Description Sends a command to the BattlEye server. The command is sent only if connected and the request queue is not saturated (max 5 pending requests). ### Signature ```typescript commandSend(command: string): void ``` ### Parameters #### Path Parameters - **command** (string) - Required - The RCon command to send (e.g., "players", "say -1 Hello") ### Return Type `void` ### Behavior - Validates connection status; emits `"error"` if not connected - Validates queue size; emits `"error"` if 5+ pending requests (indicates server not responding) - Increments sequence number (wraps at 255) - Adds sequence to tracking queue - Sends command buffer to server ### Queue Saturation If the internal sequence queue reaches 5 pending requests without acknowledgment, the method emits an error: `"The server is not responding"`. This indicates the server is likely offline or not responding to commands. ### Example ```typescript rcon.on("message", (msg) => { console.log("Server response:", msg); }); rcon.on("error", (msg) => { console.error("Error:", msg); }); rcon.login(); // Wait for connection... setTimeout(() => { rcon.commandSend("players"); rcon.commandSend("say -1 'Hello from RCon'"); rcon.commandSend("#shutdown 60"); }, 2000); ``` ``` -------------------------------- ### bufferLogin Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/types.md Constructs a login packet with the provided password. This function is typically used internally by the library. ```APIDOC ## bufferLogin ### Description Constructs a login packet with the provided password. This function is typically used internally by the library. ### Method `bufferLogin(pass: string): Buffer` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **pass** (string) - Required - The RCon password (ASCII) ### Returns - `Buffer`: Buffer containing the complete login packet with BattlEye header and CRC32 checksum. ### Request Example ```typescript // Example usage (typically internal) import { bufferLogin } from "battleye-node"; const loginPacket = bufferLogin("your_password"); ``` ``` -------------------------------- ### bufferHeader Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/Buffers.md Constructs the BattlEye packet header, including magic bytes and CRC32 checksum. ```APIDOC ## Internal: bufferHeader Constructs the BattlEye packet header (magic + CRC32). ### Signature ```typescript function bufferHeader(subsequent: Buffer): Buffer ``` ### Parameters #### Path Parameters - **subsequent** (Buffer) - Required - Payload buffer to checksum ### Return Type `Buffer` — 7-byte header (magic + CRC + reserved) ### Packet Structure | Bytes | Content | |-------|---------| | 0 | 0x42 ("B") | | 1 | 0x45 ("E") | | 2-5 | CRC32 (little-endian) | | 6 | 0x00 (reserved) | ### Behavior - Computes CRC32 checksum of the payload buffer - Stores checksum in little-endian format (LSB first) - Prepends BattlEye magic bytes ### Example ```typescript // Manual example (normally done internally) // const payload = Buffer.from([0xFF, 0x01, 0x00]); // const crc = CRC32.buf(payload); // const crcBuffer = Buffer.alloc(4); // crcBuffer.writeInt32LE(crc, 0); // const header = Buffer.concat([Buffer.from([0x42, 0x45]), crcBuffer, Buffer.from([0x00])]); // console.log(header.length); // 7 ``` ### Source `src/buffers/bufferHeader.ts` ``` -------------------------------- ### Config Interface Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/types.md Configuration object passed to the RCON constructor. Defines the necessary and optional parameters for establishing an RCON connection. ```APIDOC ## Config Configuration object passed to the RCON constructor. All required fields must be provided; optional fields have defaults applied if omitted. ### Definition ```typescript interface Config { address: string; port: number; password: string; connectionType?: "udp4" | "udp6"; connectionTimeout?: number; connectionInterval?: number; keepAliveInterval?: number; } ``` ### Fields | Field | Type | Required | Default | Description | |-------|------|----------|---------|-------------| | address | string | Yes | — | IPv4 or IPv6 address of the BattlEye RCon server | | port | number | Yes | — | UDP port number the RCon server listens on (typically 2302 for DayZ) | | password | string | Yes | — | RCon password configured on the server | | connectionType | `"udp4"` | `"udp6"` | No | `"udp4"` | UDP protocol version: `"udp4"` for IPv4, `"udp6"` for IPv6 | | connectionTimeout | number | No | 50000 | Maximum time in milliseconds to wait for successful authentication (clamped to min 50000) | | connectionInterval | number | No | 5000 | Time in milliseconds between login retry attempts (clamped to min 5000) | | keepAliveInterval | number | No | 10000 | Time in milliseconds between keep-alive packets after successful login | ### Validation The RCON constructor validates that `address`, `port`, and `password` are provided. If any are missing, an `Error` is thrown with the message: `"Address, port, and password are required"`. Timeout and interval values are clamped to their minimums: - `connectionTimeout` is set to `Math.max(provided, 50000)` - `connectionInterval` is set to `Math.max(provided, 5000)` - `keepAliveInterval` uses the provided value or defaults to 10000 ### Usage ```typescript import RCON from "battleye-node"; const config: Config = { address: "192.168.1.100", port: 2302, password: "secure_rcon_password", connectionType: "udp4", connectionTimeout: 60000, connectionInterval: 5000, keepAliveInterval: 10000, }; const rcon = new RCON(config); ``` ``` -------------------------------- ### Construct BattlEye Login Packet Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/Buffers.md Use bufferLogin to create a login packet with your RCon password. The packet is a Buffer ready for UDP transmission. The length will be 18 bytes plus the password length. ```typescript import { bufferLogin } from "battleye-node"; const loginPacket = bufferLogin("my_rcon_password"); console.log(loginPacket.length); // 18 + password length console.log(loginPacket[0]); // 0x42 ("B") console.log(loginPacket[1]); // 0x45 ("E") // Send via UDP udpSocket.send(loginPacket, 0, loginPacket.length, port, address); ``` ```typescript // In RCON.login() this.udp?.send(bufferLogin(this.config.password)); ``` -------------------------------- ### bufferCommand Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/Buffers.md Constructs a command packet containing a command string and sequence number. This packet is used to send commands to the BattlEye RCon server. ```APIDOC ## Function: bufferCommand Constructs a command packet containing a command string and sequence number. ### Signature ```typescript function bufferCommand(command: string, sequence: number): Buffer ``` ### Parameters - **command** (string) - Required - Command to send (e.g., "players", "say -1 Hello") - **sequence** (number) - Required - Sequence number 0-255 for matching responses ### Return Type `Buffer` — Complete command packet ready to send via UDP ### Packet Structure | Bytes | Content | Notes | |-------|---------|-------| | 0-1 | "BE" | Magic header (0x42, 0x45) | | 2-5 | CRC32 | Checksum of payload (little-endian) | | 6 | 0x00 | Reserved byte | | 7-8 | 0xFF, 0x01 | Command packet type identifier | | 9 | sequence | Sequence number (0-255) | | 10+ | command | Command string in ASCII encoding | ### Behavior - Encodes the command as ASCII bytes - Combines command with sequence and type marker (0xFF, 0x01, sequence) - Computes CRC32 checksum of the payload - Adds BattlEye header with magic and checksum ### Sequence Number The sequence number (0-255) must match the client's current sequence counter. The RCON class increments this automatically: ```typescript // RCON internally increments sequence this.sequence = this.sequence >= 255 ? 0 : this.sequence + 1; this.udp?.send(bufferCommand(command, this.sequence)); ``` ### Example ```typescript import { bufferCommand } from "battleye-node"; // Create command packets const playersCmd = bufferCommand("players", 1); const sayCmd = bufferCommand("say -1 'Hello world'", 2); const kickCmd = bufferCommand("#kick 12345", 3); // Send via UDP udpSocket.send(playersCmd, 0, playersCmd.length, port, address); udpSocket.send(sayCmd, 0, sayCmd.length, port, address); udpSocket.send(kickCmd, 0, kickCmd.length, port, address); ``` ``` -------------------------------- ### Type-Safe Packet Handling with BEPacket Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/Protocol.md Demonstrates using a switch statement on the packet type to handle different BEPacket variants safely. ```typescript import type { BEPacket } from "battleye-node"; import { parsePacket } from "battleye-node"; function handlePacket(packet: BEPacket) { switch (packet.type) { case 0: console.log("Login:", packet.success); break; case 1: console.log("Command response:", packet.message); break; case 2: console.log("Server message:", packet.message); break; } } const parsed = parsePacket(buffer); if (parsed) { handlePacket(parsed); } ``` -------------------------------- ### Manually Construct BattlEye Header Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/Buffers.md Demonstrates the manual creation of a BattlEye packet header, including magic bytes, CRC32 checksum, and a reserved byte. This is typically handled internally by other buffer functions. ```typescript import CRC32 from "crc-32"; // Manual example (normally done internally) const payload = Buffer.from([0xFF, 0x01, 0x00]); const crc = CRC32.buf(payload); const crcBuffer = Buffer.alloc(4); crcBuffer.writeInt32LE(crc, 0); const header = Buffer.concat([Buffer.from([0x42, 0x45]), crcBuffer, Buffer.from([0x00])]); console.log(header.length); // 7 ``` -------------------------------- ### Usage of ServerMessagePacket Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/Protocol.md Illustrates parsing a buffer to detect a ServerMessagePacket and display its content. ```typescript import { parsePacket } from "battleye-node"; const packet = parsePacket(buffer); if (packet && packet.type === 2) { console.log(`Server: ${packet.message}`); } ``` -------------------------------- ### Default RCON Configuration Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/index.md Shows the default configuration for the RCON client, suitable for most servers. It highlights the parameters that use default values if not explicitly provided. ```typescript const rcon = new RCON({ address: "server.example.com", port: 2302, password: "rcon_password", // Uses defaults: // connectionType: "udp4" // connectionTimeout: 50000 (50 sec) // connectionInterval: 5000 (5 sec) // keepAliveInterval: 10000 (10 sec) }); ``` -------------------------------- ### Construct BattlEye Login Packet Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/types.md Constructs a BattlEye login packet. Requires the RCon password as an ASCII string. Returns a Buffer containing the complete packet with header and checksum. ```typescript function bufferLogin(pass: string): Buffer ``` -------------------------------- ### Handle UDP Socket Events Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/UDPSocket.md Shows how to attach event listeners to the underlying dgram.Socket for handling incoming messages and errors. This is crucial for receiving data from the BattlEye server. ```typescript const udp = new UDPSocket(config); // Listen for incoming messages udp.socket.on("message", (msg: Buffer, rinfo) => { console.log("Received:", msg); console.log("From:", rinfo.address, rinfo.port); }); // Handle errors udp.socket.on("error", (err) => { console.error("Socket error:", err); }); ``` -------------------------------- ### Construct BattlEye Command Packet Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/types.md Constructs a BattlEye command packet. Requires the command string (ASCII) and a sequence number. Returns a Buffer containing the complete packet with header and checksum. ```typescript function bufferCommand(command: string, sequence: number): Buffer ``` -------------------------------- ### Local Network (LAN) Configuration Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/configuration.md Configure the RCON client for local testing or LAN servers where low latency is expected. Default values are often suitable. ```typescript import RCON from "battleye-node"; // For local testing or LAN servers with reliable low latency const rcon = new RCON({ address: "192.168.1.100", port: 2302, password: "rcon_password", connectionTimeout: 50000, // default is fine connectionInterval: 5000, // default is fine keepAliveInterval: 10000, // default is fine }); ``` -------------------------------- ### bufferLogin Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/Buffers.md Constructs a login authentication packet containing the RCon password. This packet is used to authenticate with the BattlEye RCon server. ```APIDOC ## Function: bufferLogin Constructs a login authentication packet containing the RCon password. ### Signature ```typescript function bufferLogin(pass: string): Buffer ``` ### Parameters - **pass** (string) - Required - RCon password (ASCII characters) ### Return Type `Buffer` — Complete login packet ready to send via UDP ### Packet Structure | Bytes | Content | Notes | |-------|---------|-------| | 0-1 | "BE" | Magic header (0x42, 0x45) | | 2-5 | CRC32 | Checksum of payload (little-endian) | | 6 | 0x00 | Reserved byte | | 7-8 | 0xFF, 0x00 | Login packet type identifier | | 9+ | password | Password string in ASCII encoding | ### Behavior - Encodes the password as ASCII bytes - Prepends login marker bytes (0xFF, 0x00) - Computes CRC32 checksum - Adds BattlEye header with magic and checksum ### Example ```typescript import { bufferLogin } from "battleye-node"; const loginPacket = bufferLogin("my_rcon_password"); console.log(loginPacket.length); // 18 + password length console.log(loginPacket[0]); // 0x42 ("B") console.log(loginPacket[1]); // 0x45 ("E") // Send via UDP udpSocket.send(loginPacket, 0, loginPacket.length, port, address); ``` ``` -------------------------------- ### Connection Interval Clamped to Minimum Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/configuration.md Attempt to set a connection interval shorter than the minimum allowed. The client will automatically use the minimum interval of 5000ms. ```typescript // Fast reconnection (retry every 3 seconds, but clamped to 5000) const rcon = new RCON({ address: "127.0.0.1", port: 2302, password: "mypass", connectionInterval: 3000, // will use 5000 }); ``` -------------------------------- ### IPv6 Server Configuration Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/configuration.md Configure the RCON client for an IPv6 BattlEye server using the 'udp6' connection type. ```typescript const rcon = new RCON({ address: "::1", port: 2302, password: "mypass", connectionType: "udp6", }); ``` -------------------------------- ### Type Definitions Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/index.md Provides the type definitions for the configuration object used to initialize the RCON client and the various packet types returned by the protocol parser. ```APIDOC ### Type Definitions #### Configuration (`Config`) ```typescript interface Config { address: string; port: number; password: string; connectionType?: "udp4" | "udp6"; connectionTimeout?: number; // default 50000 connectionInterval?: number; // default 5000 keepAliveInterval?: number; // default 10000 } ``` #### Packet Types (`BEPacket`) ```typescript type LoginPacket = { type: 0; success: boolean }; type CommandPacket = { type: 1; sequence: number; message: string }; type ServerMessagePacket = { type: 2; sequence: number; message: string }; type BEPacket = LoginPacket | CommandPacket | ServerMessagePacket; ``` ``` -------------------------------- ### Handle RCON Events Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/index.md Shows how to subscribe to RCON events such as connection status, server messages, and errors. Use these event handlers to manage the state and receive real-time updates from the server. ```typescript rcon.on("onConnect", (isConnected) => { console.log("Connected:", isConnected); }); rcon.on("message", (msg) => { console.log("Response:", msg); }); rcon.on("error", (msg) => { console.error("Error:", msg); }); ``` -------------------------------- ### BattlEye Packet Parsing in Message Handler Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/Protocol.md Shows how to integrate `parsePacket` within a typical UDP message handler to process incoming BattlEye packets. ```typescript import { parsePacket } from "battleye-node"; // Typical UDP message handler socket.on("message", (msg: Buffer, rinfo) => { const packet = parsePacket(msg); if (!packet) { console.log("Received invalid packet from", rinfo.address); return; } console.log("Valid packet type:", packet.type); if (packet.type === 1 || packet.type === 2) { console.log("Message:", packet.message); } }); ``` -------------------------------- ### IPv4 Server Configuration Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/configuration.md Configure the RCON client for an IPv4 BattlEye server. The 'udp4' connection type is used, which is also the default. ```typescript const rcon = new RCON({ address: "127.0.0.1", port: 2302, password: "mypass", connectionType: "udp4", // or omit for default }); ``` -------------------------------- ### RCON Configuration Interface Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/index.md Defines the structure for RCON client configuration, including essential network details and optional parameters for connection timeouts and keep-alive intervals. Default values are provided for tuning. ```typescript // Configuration interface Config { address: string; port: number; password: string; connectionType?: "udp4" | "udp6"; connectionTimeout?: number; // default 50000 connectionInterval?: number; // default 5000 keepAliveInterval?: number; // default 10000 } ``` -------------------------------- ### bufferKeepAlive Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/Buffers.md Constructs a BattlEye keep-alive packet. These packets are used as heartbeats and contain only a sequence number. ```APIDOC ## Function: bufferKeepAlive Constructs a BattlEye keep-alive packet. ### Behavior - Creates a minimal packet with just type and sequence - Computes CRC32 checksum - Adds BattlEye header - Packet size is fixed at 10 bytes (header + 3-byte payload) ### Example ```typescript import { bufferKeepAlive } from "battleye-node"; // Create keep-alive packets const keepAlive1 = bufferKeepAlive(1); const keepAlive2 = bufferKeepAlive(2); console.log(keepAlive1.length); // Always 10 bytes // Send via UDP // udpSocket.send(keepAlive1, 0, keepAlive1.length, port, address); ``` ### Source `src/buffers/bufferKeepAlive.ts` ``` -------------------------------- ### bufferAck Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/types.md Constructs an acknowledgment packet for server-initiated messages. This function is typically used internally by the library. ```APIDOC ## bufferAck ### Description Constructs an acknowledgment packet for server-initiated messages. This function is typically used internally by the library. ### Method `bufferAck(sequence: number): Buffer` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **sequence** (number) - Required - Sequence number of the message being acknowledged ### Returns - `Buffer`: Buffer containing the complete acknowledgment packet with BattlEye header and CRC32 checksum. ### Request Example ```typescript // Example usage (typically internal) import { bufferAck } from "battleye-node"; const ackPacket = bufferAck(10); ``` ``` -------------------------------- ### LoginPacket Type Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/types.md Represents the response from the server to a login attempt, indicating success or failure. ```APIDOC ### LoginPacket Response from the server to a login attempt. ```typescript type LoginPacket = { type: 0; success: boolean; }; ``` | Field | Type | Description | |-------|------|-------------| | type | `0` | Literal type indicating this is a login response | | success | boolean | `true` if authentication succeeded, `false` if password was incorrect | ``` -------------------------------- ### Check Socket Status Before Sending Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/UDPSocket.md Illustrates how to check the `isSocketOpen` flag before attempting to send data. This prevents errors that may occur if trying to send data on a closed socket. ```typescript if (udp.isSocketOpen) { udp.send(buffer); } else { console.log("Socket is closed"); } ``` -------------------------------- ### Handling Command Responses Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/index.md Demonstrates how to process responses received from RCON commands. The 'message' event handler is used to capture and parse command results, such as player lists. ```typescript rcon.on("message", (msg) => { // All command responses come as "message" events // Parse as needed for your commands if (msg.includes("Players on server")) { console.log("Player list:", msg); } }); // Send command rcon.commandSend("players"); ``` -------------------------------- ### Config Interface Definition Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/types.md Defines the configuration object structure for the RCON constructor. All required fields must be provided, while optional fields utilize default values if omitted. ```typescript interface Config { address: string; port: number; password: string; connectionType?: "udp4" | "udp6"; connectionTimeout?: number; connectionInterval?: number; keepAliveInterval?: number; } ``` -------------------------------- ### BattlEye Packet Type Guard Source: https://github.com/devkirkir/battleye-node/blob/main/_autodocs/api-reference/Protocol.md Illustrates how to use a type guard function to narrow down the type of a parsed BattlEye packet, specifically checking for `CommandPacket`. ```typescript import type { BEPacket, CommandPacket } from "battleye-node"; import { parsePacket } from "battleye-node"; function isCommandResponse(packet: BEPacket): packet is CommandPacket { return packet.type === 1; } const packet = parsePacket(buffer); if (packet && isCommandResponse(packet)) { console.log(`Command ${packet.sequence}: ${packet.message}`); } ```