You've already forked fm-dx-webserver
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:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user