Switch from net-ping to system ping through child process so don't need to be root

This commit is contained in:
Junior 2024-09-25 15:24:24 +00:00
parent 44f563533e
commit 27ccfb467c

View File

@ -1,4 +1,4 @@
const Ping = require('net-ping'); const ChildProcess = require('child_process');
const Discord = require('discord.js'); const Discord = require('discord.js');
class Server { class Server {
@ -38,19 +38,12 @@ class Server {
} }
async hostIsAlive() { async hostIsAlive() {
if ( !this.active || (this.rconAddress == "") ) return false;
try { try {
if ( !this.active || (this.rconAddress == "") ) return false; let res = ChildProcess.execSync('ping -c 1 -W 0.25 -q ' + this.rconAddress);
let session = Ping.createSession({retries: 1, timeout: 250}); return true;
let result = await session.pingHost(this.rconAddress, function(error, target) {
if ( error ) {
return false;
} else {
return true;
}
});
return result;
} catch (e) { } catch (e) {
console.log(e); console.log("Host for " + this.name + " at " + this.rconAddress + " not available");
return false; return false;
} }
} }