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
This commit is contained in:
David Duarte 2020-12-05 16:52:36 +01:00 committed by GitHub
parent 0009c9ab4c
commit 5873c1a29f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View file

@ -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)
}

View file

@ -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 = {