-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrustyconsole.js
More file actions
49 lines (43 loc) · 1.14 KB
/
rustyconsole.js
File metadata and controls
49 lines (43 loc) · 1.14 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
'use strict';
const program = require('commander');
const consoleAPI = require('./consoleapi');
const defaults = {
server: '127.0.0.1:28016',
password: '',
id: 1,
json: false,
quiet: false,
};
let rcon = {
...defaults,
command: null,
};
program
.version('0.3.0')
.usage('[options] "RCON command sent to Rust server"')
.arguments('<cmd>')
.option(`-s, --server <host:port>`, `server IP address:port, default ${defaults.server}`)
.option('-p, --password <password>', 'server password')
.option('-i, --id <number>', 'message id', defaults.id)
.option('-j, --json', 'output return data as JSON', defaults.json)
.option('-q, --quiet', 'suppress output', defaults.quiet)
.action((cmd) => {
rcon.command = cmd;
})
.parse(process.argv);
if (!rcon.command) {
console.error('No command entered for remote server.');
program.outputHelp();
process.exit(1);
}
(async () => {
try {
const retval = await consoleAPI.sendCommand(rcon);
if (retval.result && !rcon.quiet) {
console.log(retval.result);
}
} catch (error) {
console.error('Error sending RCON command:', error.message);
}
})();