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');
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;
module.exports = Server;