From 618e19192cb7085d8eed5b5acdb5b17e11e95bff Mon Sep 17 00:00:00 2001 From: Kristjan Kirpu Date: Mon, 3 Aug 2015 17:05:30 +0300 Subject: [PATCH] Added gameserver latency to returning data --- package.json | 3 ++- protocols/core.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e472ceb..34938e7 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "request": "~2.51.0", "minimist": "~1.1.0", "varint": "~4.0.0", - "moment": "~2.9.0" + "moment": "~2.9.0", + "jjg-ping": "~1.0.1" }, "bin": { "gamedig": "bin/gamedig.js" diff --git a/protocols/core.js b/protocols/core.js index 1ed7d4d..5d064ac 100644 --- a/protocols/core.js +++ b/protocols/core.js @@ -3,7 +3,8 @@ var EventEmitter = require('events').EventEmitter, net = require('net'), async = require('async'), Class = require('../lib/Class'), - Reader = require('../lib/reader'); + Reader = require('../lib/reader'), + ping = require('jjg-ping'); module.exports = Class.extend(EventEmitter,{ init: function() { @@ -18,6 +19,7 @@ module.exports = Class.extend(EventEmitter,{ this.encoding = 'utf8'; this.byteorder = 'le'; this.delimiter = '\0'; + this.ping = 0; var self = this; this.globalTimeoutTimer = setTimeout(function() { @@ -68,6 +70,7 @@ module.exports = Class.extend(EventEmitter,{ if('port_query' in this.options) state.query.port_query = this.options.port_query; state.query.type = this.type; if('pretty' in this) state.query.pretty = this.pretty; + state.query.server_ping = this.ping; this.reset(); this.finished = true; @@ -107,6 +110,13 @@ module.exports = Class.extend(EventEmitter,{ self.parseDns(options.host,c); } }, + function(c) { + // not sure if this is the best way to ping a host + ping.system.ping(options.host, function(latency, status) { + if(status) self.ping = latency; + }); + c(); + }, function(c) { // calculate query port if needed if(!('port_query' in options) && 'port' in options) {