-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.ts
35 lines (29 loc) · 860 Bytes
/
cli.ts
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
import { parseArgs } from "@std/cli";
import { Rcon } from "./src/rcon.ts";
const args = parseArgs(Deno.args, {
string: ["password", "ip", "port", "command"],
boolean: ["console", "file"],
});
if (!args.password || !args.ip || !args.command) {
console.error("Must specify a password, ip and command");
} else {
const port = parseInt(args.port ?? "27015", 10);
using rcon = new Rcon({
host: args.ip,
port,
timeout: 5_000,
});
const didAuthenticate = await rcon.authenticate(args.password!);
if (didAuthenticate) {
const result = await rcon.execute(args.command!);
if (args.file) {
Deno.writeTextFile(`${Deno.cwd()}/rcon-result.txt`, result.toString(), {
append: true,
});
} else if (args.console) {
console.log(result);
}
} else {
console.error("RCON password incorrect");
}
}