mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-28 02:05:40 -05:00
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:
parent
0009c9ab4c
commit
5873c1a29f
2 changed files with 6 additions and 7 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in a new issue