Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 27 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,53 @@
[According to Valve's RCON specification](https://developer.valvesoftware.com/wiki/Source_RCON_Protocol)

## Install
This version of rcon-srcds is an ES Module and requires Node 14+.

```console
npm install rcon-srcds --save
```

## Usage
```typescript
// ES5 import
const server = new Rcon(options);

// ES5+ import
import Rcon from 'rcon-srcds';
```
import { RCON, RCONOptions } from 'rcon-srcds';

### Options
These are the default values.
```typescript
{
// These are the default values.
const options: RCONOptions = {
host: '127.0.0.1', // Host
port: 27015, // Port
maximumPacketSize: 0, // Maximum packet bytes (0 = no limit)
encoding: 'ascii', // Packet encoding (ascii, utf8)
encoding: 'utf8', // Packet encoding (ascii, utf8)
timeout: 1000 // in ms
}
```

*The maximum possible value of packet size is **4096** bytes*: https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Packet_Size

## Minecraft Compatibility
Although the package name implies exclusive compatibility with Source games, Minecraft servers also use Valve's RCON implementation, so there should not be any issues using this package for your Minecraft projects!
const rcon = new RCON(options);

## Examples
Using async/await:
```typescript
import Rcon from 'rcon-srcds';
const server = new Rcon({ host: '127.0.0.1', port: 25010 });
// using async/await
try {
await server.authenticate('your_rcon_password');
await rcon.authenticate('your_rcon_password');
console.log('authenticated');
let status = await server.execute('status'); // You can read `status` reponse
server.execute('mp_autokick 0'); // no need to read the response
let status = await rcon.execute('status'); // You can read `status` reponse
rcon.execute('mp_autokick 0'); // no need to read the response
} catch(e) {
console.error(e);
}
```
Using (native) promises:
```typescript
import Rcon from 'rcon-srcds';
const server = new Rcon({ port: 25010 });

server.authenticate('rcon_password')
// Using promises
rcon.authenticate('your_rcon_password')
.then(() => {
console.log('authenticated');
return server.execute('status');
return rcon.execute('status');
})
.then((response) => {
console.log(response)
})
.then(console.log)
.catch(console.error);
.catch((e) => {
console.log(e);
});
```

*The maximum possible value of packet size is **4096** bytes*:
https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Packet_Size

## Minecraft Compatibility
Although the package name implies exclusive compatibility with Source games, Minecraft servers also use Valve's RCON
implementation, so there should not be any issues using this package for your Minecraft projects!
Loading