@0x0c/rcon

中文文档
1.0.0发布于 2024/07/30ISCTypeScriptCommonJS零依赖近 30 天下载 2936

Simple queued RCON client with support for multi-packeted responses.

原始使用文档
文档目录8 节
  1. Quick Start
  2. API
  3. new RconClient(options): RconClient
  4. RconClient.connect(): Promise<void>
  5. RconClient.connected: boolean
  6. RconClient.send(command, options?): Promise<string>
  7. RconClient.disconnect(): void
  8. Notes

NodeJS RCON Client

$ npm install @0x0c/rcon

A zero-dependency, fully-typed Node.js library providing an client for interacting with servers that support RCON protocol.

Supports multi-packeted responses, timeouts and queuing out of the box.

Quick Start

import {RconClient} from '@0x0c/rcon';

const rcon = new RconClient({
    host: '127.0.0.1',
    port: 27015,
    password: '<my-rcon-password>',
});

async function queryStatus() {
    const [status, stats] = await Promise.all([rcon.send('status'), rcon.send('stats')]);
    myCustomParserForStatusCommandResponse(status);
    parseAndStoreServerStats(stats);
    // close connection when it is not required anymore
    rcon.disconnect();
}

queryStatus();

API

new RconClient(options): RconClient

ArgumentTypeDescription
optionsobjectOptions
options.hoststringIP address or hostname of the server
options.portnumberRCON port
options.passwordstringRCON Password
[options.timeout=5000]numberOptional. The timeout for the response in milliseconds. Default: 5000

RconClient.connect(): Promise<void>

Connect to the server. This method is called automatically when you send the first command, but you can call it manually if you want to check the connection status after that.

RconClient.connected: boolean

Property that indicates whether the client is connected to the server.

RconClient.send(command, options?): Promise<string>

Send command to the server an return the response as a string.

ArgumentTypeDescription
commandstringCommand to send
[options]objectOptional. Options
[options.timeout]numberOptional. Set timeout for this command separately from connection timeout. Default: equals to connection timeout
[options.multipacket=true]booleanOptional. Send at least two commands using a "boundary packet" that helps to read multi-packeted responses. Default: true

RconClient.disconnect(): void

Close the connection to the server. Connection is kept alive between commands, so you should call this method when you are done to free up resources.

Notes

By default, all commands are sent with the expectation of multi-packet response.

However, this means that even smallest replies may take twice as long (roughly) to resolve due to two packets being queued: a packet for the command itself, and a "boundary" packet (a junk packet that helps the connection client to understand when a server has finished replying to the previously sequenced packet).

You can disable this feature when sending:

const stats = await rcon.send('stats', {multipacket: false});

版本与发布记录

@0x0c/rcon 共发布 1 个版本,首次发布于 2024/07/30;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0latest2024/07/302 年前

关于 @0x0c/rcon 的常见问题

@0x0c/rcon 是什么?

Simple queued RCON client with support for multi-packeted responses.

如何安装 @0x0c/rcon?

在项目目录运行 npm install @0x0c/rcon,或使用 pnpm add / yarn add / bun add。

@0x0c/rcon 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@0x0c/rcon 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@0x0c/rcon 可以商用吗?

@0x0c/rcon 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@0x0c/rcon 的下载量有多少?

根据 npm 官方下载统计,@0x0c/rcon 在 2026/10/04 – 2026/11/02 这 30 天内被下载 2,936 次,日均约 98 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@0x0c/rcon 还在维护吗?

最新版本 1.0.0 发布于 2024/07/30(2 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/07/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。