[FEATURE] Adjust more server controllers
This commit is contained in:
parent
62c966a6bd
commit
37e3dc2ae9
16 changed files with 281 additions and 173 deletions
|
@ -1,33 +0,0 @@
|
|||
import k8s from "@kubernetes/client-node";
|
||||
import { Rcon as RconClient } from "rcon-client";
|
||||
import { ERR, WARN } 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 { serverName } = socket.mcs;
|
||||
const rconHost = `mcl-${serverName}-rcon.${namespace}.svc.cluster.local`;
|
||||
const rcon = new RconClient({
|
||||
host: rconHost,
|
||||
port: 25575,
|
||||
password: rconPassword,
|
||||
});
|
||||
rcon.on("error", (error) => socket.emit("push", error));
|
||||
try {
|
||||
await rcon.connect();
|
||||
} catch (error) {
|
||||
socket.emit("push", "Could not connect RCON Input to server!");
|
||||
WARN("RCON", `Could not connect to '${rconHost}'`);
|
||||
}
|
||||
socket.rconClient = rcon;
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
import { Server as Skio } from "socket.io";
|
||||
import { VERB, WARN, ERR } from "../util/logging.js";
|
||||
import liveLogging from "../k8s/live-logging.js";
|
||||
import rconInterface from "./rcon.js";
|
||||
|
||||
const namespace = process.env.MCL_SERVER_NAMESPACE;
|
||||
import {
|
||||
webConsoleLogs,
|
||||
webConsoleRcon,
|
||||
} from "../controllers/sub-controllers/console-controller.js";
|
||||
|
||||
async function rconSend(socket, m) {
|
||||
if (!socket.rconClient)
|
||||
|
@ -20,8 +20,8 @@ const socketConnect = async (io, socket) => {
|
|||
VERB("WS", "Websocket connecting");
|
||||
socket.mcs = { serverName: socket.handshake.query.serverName };
|
||||
try {
|
||||
await liveLogging(socket, namespace);
|
||||
await rconInterface(socket);
|
||||
await webConsoleLogs(socket);
|
||||
await webConsoleRcon(socket);
|
||||
socket.on("msg", (m) => rconSend(socket, m));
|
||||
} catch (err) {
|
||||
ERR("SOCKETS", err);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue