-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathstdio.js
More file actions
31 lines (23 loc) · 812 Bytes
/
stdio.js
File metadata and controls
31 lines (23 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// This example reads commands from stdin and sends them on enter key press.
const RCON = require('../');
const rcon = new RCON('localhost', 1234, 'password');
rcon.on('authenticated', () => {
console.log('Authenticated');
process.stdin.on('data', inputBuffer => {
// Convert buffer to string and take out last 2 characters- return character.
const inputString = inputBuffer.toString().slice(0, -2);
if (inputString === 'disconnect') {
console.log('Disconnecting from the server');
return rcon.disconnect();
}
rcon.send(inputString);
});
}).on('response', response => {
console.log('Response: ' + response);
}).on('error', error => {
console.error('Error:', error);
}).on('end', () => {
console.log('Connection closed');
process.exit(0);
});
rcon.connect();