Switch from net-ping to system ping through child process so don't need to be root
This commit is contained in:
		
							parent
							
								
									44f563533e
								
							
						
					
					
						commit
						27ccfb467c
					
				| 
						 | 
				
			
			@ -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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user