From 5873c1a29f1eded951865c617c82831a6c8d8662 Mon Sep 17 00:00:00 2001 From: David Duarte Date: Sat, 5 Dec 2020 16:52:36 +0100 Subject: [PATCH] Only use fullReason for the disconnect packet (#776) And keep endReason for the client end reason, to avoid having big JSON string that are more difficult to read --- src/server.js | 7 +++---- test/serverTest.js | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/server.js b/src/server.js index 7eab660..24db23f 100644 --- a/src/server.js +++ b/src/server.js @@ -24,12 +24,11 @@ class Server extends EventEmitter { self.socketServer.on('connection', socket => { const client = new Client(true, this.version, this.customPackets, this.hideErrors) client._end = client.end - client.end = function end (endReason, fullReason) { - endReason = fullReason !== undefined ? fullReason : '{"text":"' + endReason + '"}' + client.end = function end (endReason, fullReason = JSON.stringify({ text: endReason })) { if (client.state === states.PLAY) { - client.write('kick_disconnect', { reason: endReason }) + client.write('kick_disconnect', { reason: fullReason }) } else if (client.state === states.LOGIN) { - client.write('disconnect', { reason: endReason }) + client.write('disconnect', { reason: fullReason }) } client._end(endReason) } diff --git a/test/serverTest.js b/test/serverTest.js index 1062301..2515189 100644 --- a/test/serverTest.js +++ b/test/serverTest.js @@ -95,7 +95,7 @@ mc.supportedVersions.forEach(function (supportedVersion, i) { let count = 2 server.on('connection', function (client) { client.on('end', function (reason) { - assert.strictEqual(reason, '{"text":"LoginTimeout"}') + assert.strictEqual(reason, 'LoginTimeout') server.close() }) }) @@ -126,7 +126,7 @@ mc.supportedVersions.forEach(function (supportedVersion, i) { let count = 2 server.on('connection', function (client) { client.on('end', function (reason) { - assert.strictEqual(reason, '{"text":"KeepAliveTimeout"}') + assert.strictEqual(reason, 'KeepAliveTimeout') server.close() }) }) @@ -323,7 +323,7 @@ mc.supportedVersions.forEach(function (supportedVersion, i) { let count = 2 server.on('login', function (client) { client.on('end', function (reason) { - assert.strictEqual(reason, '{"text":"ServerShutdown"}') + assert.strictEqual(reason, 'ServerShutdown') resolve() }) const loginPacket = {