|
2 | 2 | [According to Valve's RCON specification](https://developer.valvesoftware.com/wiki/Source_RCON_Protocol) |
3 | 3 |
|
4 | 4 | ## Install |
| 5 | +This version of rcon-srcds is an ES Module and requires Node 14+. |
| 6 | + |
5 | 7 | ```console |
6 | 8 | npm install rcon-srcds --save |
7 | 9 | ``` |
8 | 10 |
|
9 | 11 | ## Usage |
10 | 12 | ```typescript |
11 | | -// ES5 import |
12 | | -const server = new Rcon(options); |
13 | | - |
14 | | -// ES5+ import |
15 | | -import Rcon from 'rcon-srcds'; |
16 | | -``` |
| 13 | +import { RCON, RCONOptions } from 'rcon-srcds'; |
17 | 14 |
|
18 | | -### Options |
19 | | -These are the default values. |
20 | | -```typescript |
21 | | -{ |
| 15 | +// These are the default values. |
| 16 | +const options: RCONOptions = { |
22 | 17 | host: '127.0.0.1', // Host |
23 | 18 | port: 27015, // Port |
24 | 19 | maximumPacketSize: 0, // Maximum packet bytes (0 = no limit) |
25 | | - encoding: 'ascii', // Packet encoding (ascii, utf8) |
| 20 | + encoding: 'utf8', // Packet encoding (ascii, utf8) |
26 | 21 | timeout: 1000 // in ms |
27 | 22 | } |
28 | | -``` |
29 | | - |
30 | | -*The maximum possible value of packet size is **4096** bytes*: https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Packet_Size |
31 | | - |
32 | | -## Minecraft Compatibility |
33 | | -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! |
| 23 | +const rcon = new RCON(options); |
34 | 24 |
|
35 | | -## Examples |
36 | | -Using async/await: |
37 | | -```typescript |
38 | | -import Rcon from 'rcon-srcds'; |
39 | | -const server = new Rcon({ host: '127.0.0.1', port: 25010 }); |
| 25 | +// using async/await |
40 | 26 | try { |
41 | | - await server.authenticate('your_rcon_password'); |
| 27 | + await rcon.authenticate('your_rcon_password'); |
42 | 28 | console.log('authenticated'); |
43 | | - let status = await server.execute('status'); // You can read `status` reponse |
44 | | - server.execute('mp_autokick 0'); // no need to read the response |
| 29 | + let status = await rcon.execute('status'); // You can read `status` reponse |
| 30 | + rcon.execute('mp_autokick 0'); // no need to read the response |
45 | 31 | } catch(e) { |
46 | 32 | console.error(e); |
47 | 33 | } |
48 | | -``` |
49 | | -Using (native) promises: |
50 | | -```typescript |
51 | | -import Rcon from 'rcon-srcds'; |
52 | | -const server = new Rcon({ port: 25010 }); |
53 | 34 |
|
54 | | -server.authenticate('rcon_password') |
| 35 | +// Using promises |
| 36 | +rcon.authenticate('your_rcon_password') |
55 | 37 | .then(() => { |
56 | 38 | console.log('authenticated'); |
57 | | - return server.execute('status'); |
| 39 | + return rcon.execute('status'); |
| 40 | + }) |
| 41 | + .then((response) => { |
| 42 | + console.log(response) |
58 | 43 | }) |
59 | | - .then(console.log) |
60 | | - .catch(console.error); |
| 44 | + .catch((e) => { |
| 45 | + console.log(e); |
| 46 | + }); |
61 | 47 | ``` |
| 48 | + |
| 49 | +*The maximum possible value of packet size is **4096** bytes*: |
| 50 | +https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Packet_Size |
| 51 | + |
| 52 | +## Minecraft Compatibility |
| 53 | +Although the package name implies exclusive compatibility with Source games, Minecraft servers also use Valve's RCON |
| 54 | +implementation, so there should not be any issues using this package for your Minecraft projects! |
0 commit comments