From 27ccfb467cbfc88b1f9c4892d05dbc57b28e98ab Mon Sep 17 00:00:00 2001 From: Junior Date: Wed, 25 Sep 2024 15:24:24 +0000 Subject: [PATCH] Switch from net-ping to system ping through child process so don't need to be root --- includes/class_server.js | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/includes/class_server.js b/includes/class_server.js index 8a14cd9..cd80d43 100644 --- a/includes/class_server.js +++ b/includes/class_server.js @@ -1,4 +1,4 @@ -const Ping = require('net-ping'); +const ChildProcess = require('child_process'); const Discord = require('discord.js'); class Server { @@ -38,19 +38,12 @@ class Server { } async hostIsAlive() { + if ( !this.active || (this.rconAddress == "") ) return false; try { - if ( !this.active || (this.rconAddress == "") ) return false; - let session = Ping.createSession({retries: 1, timeout: 250}); - let result = await session.pingHost(this.rconAddress, function(error, target) { - if ( error ) { - return false; - } else { - return true; - } - }); - return result; + let res = ChildProcess.execSync('ping -c 1 -W 0.25 -q ' + this.rconAddress); + return true; } catch (e) { - console.log(e); + console.log("Host for " + this.name + " at " + this.rconAddress + " not available"); return false; } } @@ -76,4 +69,4 @@ class Server { } } -module.exports = Server; \ No newline at end of file +module.exports = Server;