From bb81de62dbf74513512130b9d6a90a8ad3045d2b Mon Sep 17 00:00:00 2001 From: Noah Zalev Date: Tue, 7 Dec 2021 23:47:31 -0500 Subject: [PATCH] Factorize urlargs, intersession --- meshuser.js | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/meshuser.js b/meshuser.js index b45d72b9..57b46050 100644 --- a/meshuser.js +++ b/meshuser.js @@ -631,26 +631,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use // pass through to switch statement until refactoring complete switch (command.action) { - case 'urlargs': - { - console.log(req.query); - console.log(command.args); - break; - } - case 'intersession': - { - // Sends data between sessions of the same user - var sessions = parent.wssessions[obj.user._id]; - if (sessions == null) break; - - // Create the notification message and send on all sessions except our own (no echo back). - var notification = JSON.stringify(command); - for (var i in sessions) { if (sessions[i] != obj.ws) { try { sessions[i].send(notification); } catch (ex) { } } } - - // TODO: Send the message of user sessions connected to other servers. - - break; - } case 'interuser': { // Sends data between users only if allowed. Only a user in the "interUserMessaging": [] list, in the settings section of the config.json can receive and send inter-user messages from and to all users. @@ -5477,6 +5457,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use 'files': serverCommandFiles, 'getnetworkinfo': serverCommandGetNetworkInfo, 'getsysinfo': serverCommandGetSysInfo, + 'intersession': serverCommandInterSession, 'lastconnect': serverCommandLastConnect, 'lastconnects': serverCommandLastConnects, 'meshes': serverCommandMeshes, @@ -5491,6 +5472,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use 'serverstats': serverCommandServerStats, 'serverupdate': serverCommandServerUpdate, 'serverversion': serverCommandServerVersion, + 'urlargs': serverCommandUrlArgs, 'users': serverCommandUsers }; @@ -5901,6 +5883,17 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use }); } + function serverCommandInterSession(command) { + // Sends data between sessions of the same user + var sessions = parent.wssessions[obj.user._id]; + if (sessions == null) return; + + // Create the notification message and send on all sessions except our own (no echo back). + var notification = JSON.stringify(command); + for (var i in sessions) { if (sessions[i] != obj.ws) { try { sessions[i].send(notification); } catch (ex) { } } } + // TODO: Send the message of user sessions connected to other servers. + } + function serverCommandLastConnect(command) { if (!validNodeIdAndDomain(command)) return; @@ -6114,6 +6107,11 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use parent.parent.getServerTags(function (tags, err) { try { ws.send(JSON.stringify({ action: 'serverversion', tags: tags })); } catch (ex) { } }); } + function serverCommandUrlArgs(command) { + console.log(req.query); + console.log(command.args); + } + function serverCommandUsers(command) { // Request a list of all users if ((user.siteadmin & 2) == 0) { if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'users', responseid: command.responseid, result: 'Access denied' })); } catch (ex) { } } return; }