This commit is contained in:
2026-04-05 17:11:21 +02:00
parent 72bac6e6f1
commit 11328a9fc5
4 changed files with 17 additions and 17 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
/* Libraries / Imports */
const { send_xrd_online } = require('./xrd_server');
const { send_xdr_online } = require('./xdr_server');
const RDSDecoder = require("./rds.js");
const { serverConfig } = require('./server_config');
@@ -274,7 +274,7 @@ checkSerialPortStatus();
function showOnlineUsers(currentUsers) {
dataToSend.users = currentUsers;
initialData.users = currentUsers;
send_xrd_online(currentUsers);
send_xdr_online(currentUsers);
}
let prevFreq = initialData.freq || '87.500';
+2 -2
View File
@@ -7,7 +7,7 @@ const dataHandler = require('./datahandler');
const storage = require('./storage');
const consoleCmd = require('./console');
const { serverConfig, configSave } = require('./server_config');
const { send_to_xrd } = require("./xrd_server")
const { send_to_xdr } = require("./xdr_server")
let geoip = null;
try {
@@ -276,7 +276,7 @@ function resolveDataBuffer(data, wss, rdsWss) {
if (receivedData.length) {
dataHandler.handleData(wss, receivedData, rdsWss);
send_to_xrd(receivedData);
send_to_xdr(receivedData);
}
}
+2 -2
View File
@@ -117,7 +117,7 @@ function connectToSerial() {
pluginsApi.setOutput(serialport);
setTimeout(() => {
serialport.write('x\n');
}, 2500);
}, 1000);
setTimeout(() => {
serialport.write('Q0\n');
@@ -456,7 +456,7 @@ wss.on('connection', (ws, request) => {
}, 10000);
}
if (currentUsers === 0 && serverConfig.autoShutdown === true && serverConfig.xdrd.wirelessConnection === true) client.write('X\n');
if (currentUsers === 0 && serverConfig.autoShutdown === true && serverConfig.xdrd.wirelessConnection) client.write('X\n');
if (code !== 1008) logInfo(`Web client \x1b[31mdisconnected\x1b[0m (${clientIp}) \x1b[90m[${currentUsers}]`);
});
+11 -11
View File
@@ -1,20 +1,20 @@
const storage = require('./storage');
const WebSocket = require('ws');
const crypto = require('crypto');
const xrd = new WebSocket.Server({ noServer: true });
const xdr = new WebSocket.Server({ noServer: true });
const { serverConfig } = require('./server_config');
let currentUsers = 0;
let clients = []
function send_to_xrd(data) {
function send_to_xdr(data) {
clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN) client.send(data);
});
}
function send_xrd_online(fmusers) {
send_to_xrd(`o${currentUsers},${fmusers}\n`);
function send_xdr_online(fmusers) {
send_to_xdr(`o${currentUsers},${fmusers}\n`);
}
function randomString(length) {
@@ -26,7 +26,7 @@ function randomString(length) {
return result;
}
function xrd_auth(ws, salt) {
function xdr_auth(ws, salt) {
return new Promise((resolve, reject) => {
const expected = crypto.createHash('sha1')
.update(salt + serverConfig.password.adminPass).digest('hex');
@@ -44,14 +44,14 @@ function xrd_auth(ws, salt) {
});
}
xrd.on('connection', async (ws, request) => {
xdr.on('connection', async (ws, request) => {
const { initialData } = require('./datahandler');
const salt = randomString(16);
ws.send(`${salt}\n`);
try {
await xrd_auth(ws, salt);
await xdr_auth(ws, salt);
} catch (err) {
ws.send("a0\n");
ws.close(1008, err.message);
@@ -59,7 +59,7 @@ xrd.on('connection', async (ws, request) => {
}
currentUsers++;
send_xrd_online(initialData.users);
send_xdr_online(initialData.users);
ws.send(`T${initialData.freq * 1000}\n`);
ws.send(`G${initialData.eq}${initialData.ims}\n`);
ws.send(`Z${initialData.ant}\n`);
@@ -80,12 +80,12 @@ xrd.on('connection', async (ws, request) => {
ws.on('close', () => {
currentUsers--;
send_xrd_online(initialData.users);
send_xdr_online(initialData.users);
clients = clients.filter(client => client !== ws);
});
});
storage.websocket_delegation.set("/xrd", xrd);
storage.websocket_delegation.set("/xdr", xdr);
module.exports = { send_to_xrd, send_xrd_online };
module.exports = { send_to_xdr, send_xdr_online };