[TS] Renamed file extensions to typescript
This commit is contained in:
parent
4d5b347767
commit
4a6f20fa7b
31 changed files with 12 additions and 0 deletions
46
lib/server/sockets.ts
Normal file
46
lib/server/sockets.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import { Server as Skio } from "socket.io";
|
||||
import { VERB, WARN, ERR } from "../util/logging.js";
|
||||
import {
|
||||
webConsoleLogs,
|
||||
webConsoleRcon,
|
||||
} from "../controllers/sub-controllers/console-controller.js";
|
||||
|
||||
async function rconSend(socket, m) {
|
||||
if (!socket.rconClient)
|
||||
return WARN("RCON", "Message sent before RCON connected!");
|
||||
try {
|
||||
const r = await socket.rconClient.send(m);
|
||||
socket.emit("push", `[RCON]: ${r}`);
|
||||
} catch (error) {
|
||||
WARN("RCON", error);
|
||||
}
|
||||
}
|
||||
|
||||
const socketConnect = async (io, socket) => {
|
||||
VERB("WS", "Websocket connecting");
|
||||
socket.mcs = { serverId: socket.handshake.query.serverId };
|
||||
try {
|
||||
await webConsoleLogs(socket);
|
||||
await webConsoleRcon(socket);
|
||||
socket.on("msg", (m) => rconSend(socket, m));
|
||||
} catch (err) {
|
||||
ERR("SOCKETS", err);
|
||||
socket.send("push", err);
|
||||
socket.disconnect();
|
||||
}
|
||||
};
|
||||
|
||||
const socketAuth = (socket, next) => {
|
||||
const { token } = socket.handshake.auth;
|
||||
// next(new Error("Bad Token"));
|
||||
next();
|
||||
};
|
||||
|
||||
const applySockets = (server) => {
|
||||
const io = new Skio(server);
|
||||
io.on("connection", (socket) => socketConnect(io, socket));
|
||||
VERB("WS", "Configured Websockets");
|
||||
return io;
|
||||
};
|
||||
|
||||
export default applySockets;
|
Loading…
Add table
Add a link
Reference in a new issue