build chat system

This commit is contained in:
2023-05-06 13:09:46 +02:00
parent 5aa8dce299
commit 8d358e694e
9 changed files with 165 additions and 4 deletions

41
web/server/utils/rcon.js Normal file
View File

@@ -0,0 +1,41 @@
import { RCON } from 'minecraft-server-util';
const client = new RCON()
const config = useRuntimeConfig()
let connected = false;
export const sendRconCommand = async (command) => {
await connectRcon()
const message = await client.execute(command);
closeClient()
return message;
}
const connectRcon = async () => {
if (connected) return;
await client.connect(config.rconHost);
await client.login(config.rconPassword);
connected = true;
}
const debounce = (callback, wait) => {
let timeout = null;
return (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => {
callback.apply(null, args);
}, wait);
};
}
const closeClient = debounce(() => {
client.close();
connected = false;
}, 5000)