(feature) Update UI & Resource Availability
This commit is contained in:
parent
11d8229eb5
commit
929193d272
44 changed files with 4747 additions and 27 deletions
31
lib/server/rcon.js
Normal file
31
lib/server/rcon.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
import k8s from "@kubernetes/client-node";
|
||||
import { Rcon as RconClient } from "rcon-client";
|
||||
import { ERR } from "../util/logging.js";
|
||||
const kc = new k8s.KubeConfig();
|
||||
kc.loadFromDefault();
|
||||
const k8sCore = kc.makeApiClient(k8s.CoreV1Api);
|
||||
const namespace = process.env.MCL_SERVER_NAMESPACE;
|
||||
|
||||
export default async function rconInterface(socket) {
|
||||
if (socket.rconClient)
|
||||
return VERB("RCON", "Socket already connected to RCON");
|
||||
const rconSecret = `mcl-${socket.mcs.serverName}-rcon-secret`;
|
||||
const rconRes = await k8sCore.readNamespacedSecret(rconSecret, namespace);
|
||||
const rconPassword = Buffer.from(
|
||||
rconRes.body.data["rcon-password"],
|
||||
"base64"
|
||||
).toString("utf8");
|
||||
const rconHost = `mcl-${socket.mcs.serverName}-rcon`;
|
||||
const rcon = new RconClient({
|
||||
host: rconHost,
|
||||
port: 25575,
|
||||
password: rconPassword,
|
||||
});
|
||||
rcon.on("error", (error) => socket.emit("push", error));
|
||||
try {
|
||||
await rcon.connect();
|
||||
} catch (error) {
|
||||
ERR("RCON", `Could not connect to 'mcl-${socket.mcs.serverName}-rcon'`);
|
||||
}
|
||||
socket.rconClient = rcon;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue