From 654a268aa693ad77a1e3c6129135dd0cd8d9f38e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Buscht=C3=B6ns?= <buschtoens@gmail.com> Date: Mon, 28 Jan 2013 00:56:59 +0100 Subject: [PATCH 1/5] Add latency measurement to lib/ping.js --- lib/ping.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ping.js b/lib/ping.js index 8a495ef..17d6247 100644 --- a/lib/ping.js +++ b/lib/ping.js @@ -19,6 +19,7 @@ function ping(options, cb) { motd: parts[3], playerCount: parseInt(parts[4], 10), maxPlayers: parseInt(parts[5], 10), + latency: Date.now() - start }; } catch (err) { client.end(); @@ -34,5 +35,7 @@ function ping(options, cb) { client.on('connect', function() { client.write(0xfe, { magic: 1 }); }); + + var start = Date.now(); client.connect(port, host); } From efe2e7f775305edbcbf8b908e85fc9ad6f78a916 Mon Sep 17 00:00:00 2001 From: Robin Lambertz <robinpub@googlemail.com> Date: Sun, 27 Jan 2013 11:47:35 +0000 Subject: [PATCH 2/5] Fixes #20 for real this time... --- lib/server.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/server.js b/lib/server.js index fd40db2..62d1c40 100644 --- a/lib/server.js +++ b/lib/server.js @@ -24,6 +24,11 @@ Server.prototype.listen = function(port, host) { self.socketServer = net.createServer(); self.socketServer.on('connection', function(socket) { var client = new Client(true); + client._end = client.end; + client.end = function end(endReason) { + client.write(0xff, {reason: endReason}); + client._end(endReason); + } client.id = nextId++; self.clients[client.id] = client; client.on('error', function(err) { From e59ac0f76daa2e7a07216b753fea974ed6d9e2dc Mon Sep 17 00:00:00 2001 From: Andrew Kelley <superjoe30@gmail.com> Date: Sun, 27 Jan 2013 19:36:22 -0500 Subject: [PATCH 3/5] fix ping module to pass tests --- lib/ping.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ping.js b/lib/ping.js index 17d6247..859a368 100644 --- a/lib/ping.js +++ b/lib/ping.js @@ -8,7 +8,7 @@ function ping(options, cb) { var port = options.port || 25565; var client = new Client(); - client.on(0xff, function(packet) { + client.once(0xff, function(packet) { var parts = packet.reason.split('\u0000'); var results; try { From ba29fa59d75a8b73acbe3e927c40e8213276d25c Mon Sep 17 00:00:00 2001 From: Andrew Kelley <superjoe30@gmail.com> Date: Sun, 27 Jan 2013 19:40:56 -0500 Subject: [PATCH 4/5] Release 0.6.6 --- README.md | 7 ++++++- package.json | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d9a1eb9..14ef4d9 100644 --- a/README.md +++ b/README.md @@ -230,11 +230,16 @@ correct data type. ## History +### 0.6.6 + + * ping: fix calling callback twice when server sends kick + * server: send a kick packet when kicking clients. (thanks roblabla) + * ping: include latency property (thanks Jan Buschtöns) + ### 0.6.5 * createServer: allow empty options * server: support online mode and encryption (thanks roblabla) - * server: send a kick packet when kicking clients. (thanks roblabla) ### 0.6.4 diff --git a/package.json b/package.json index 005b55d..73e9aca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minecraft-protocol", - "version": "0.6.5", + "version": "0.6.6", "description": "Parse and serialize minecraft packets, plus authentication and encryption.", "main": "index.js", "repository": { From 484a2bd34fb656438544945550690a92ecc62723 Mon Sep 17 00:00:00 2001 From: Andrew Kelley <superjoe30@gmail.com> Date: Mon, 28 Jan 2013 19:24:03 -0500 Subject: [PATCH 5/5] fix ping tests. closes #28 --- test/test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/test.js b/test/test.js index 9a13e5a..63727fc 100644 --- a/test/test.js +++ b/test/test.js @@ -245,6 +245,9 @@ describe("client", function() { }, function() { mc.ping({}, function(err, results) { if (err) return done(err); + assert.ok(results.latency >= 0); + assert.ok(results.latency <= 1000); + delete results.latency; assert.deepEqual(results, { prefix: "§1", protocol: protocol.version, @@ -446,6 +449,9 @@ describe("mc-server", function() { server.on('listening', function() { mc.ping({}, function(err, results) { if (err) return done(err); + assert.ok(results.latency >= 0); + assert.ok(results.latency <= 1000); + delete results.latency; assert.deepEqual(results, { prefix: "§1", protocol: protocol.version,