1
0
mirror of https://github.com/KubaPro010/fm-dx-webserver.git synced 2026-02-27 06:23:53 +01:00

user kick, plugins, bugfixes

This commit is contained in:
NoobishSVK
2024-04-25 20:41:05 +02:00
parent 981c0f25e2
commit 510ed6b8f3
15 changed files with 152 additions and 46 deletions

View File

@@ -1,5 +1,7 @@
const WebSocket = require('ws');
const dataHandler = require('./datahandler');
const storage = require('./storage');
const consoleCmd = require('./console');
function parseMarkdown(parsed) {
parsed = parsed.replace(/<\/?[^>]+(>|$)/g, '');
@@ -79,6 +81,23 @@ function resolveDataBuffer(data, wss) {
}
}
function kickClient(ipAddress) {
// Find the entry in connectedClients associated with the provided IP address
const targetClient = storage.connectedUsers.find(client => client.ip === ipAddress);
if (targetClient && targetClient.instance) {
// Send a termination message to the client
targetClient.instance.send('KICK');
// Close the WebSocket connection after a short delay to allow the client to receive the message
setTimeout(() => {
targetClient.instance.close();
consoleCmd.logInfo(`Web client kicked (${ipAddress})`);
}, 500);
} else {
consoleCmd.logInfo(`Kicking client ${ipAddress} failed. No suitable client found.`);
}
}
module.exports = {
parseMarkdown, removeMarkdown, formatUptime, resolveDataBuffer
parseMarkdown, removeMarkdown, formatUptime, resolveDataBuffer, kickClient
}