mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-12-04 13:01:14 -05:00
Update examples to log when connection is lost
Normally, the client will send a kick packet if the client is disconnected from the server, but if the connection is lost due to network or lower-level protocol issues, the 'end' event will be emitted. Log this event in the examples so it is clear why the scripts exit.
This commit is contained in:
parent
46a134c5e9
commit
1349fdfc73
2 changed files with 6 additions and 0 deletions
|
@ -18,6 +18,9 @@ client.on('connect', function() {
|
||||||
client.on('disconnect', function(packet) {
|
client.on('disconnect', function(packet) {
|
||||||
console.log('disconnected: '+ packet.reason);
|
console.log('disconnected: '+ packet.reason);
|
||||||
});
|
});
|
||||||
|
client.on('end', function(err) {
|
||||||
|
console.log('Connection lost');
|
||||||
|
});
|
||||||
client.on('chat', function(packet) {
|
client.on('chat', function(packet) {
|
||||||
var jsonMsg = JSON.parse(packet.message);
|
var jsonMsg = JSON.parse(packet.message);
|
||||||
if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
|
if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
|
||||||
|
|
|
@ -20,6 +20,9 @@ client.on('connect', function() {
|
||||||
client.on('disconnect', function(packet) {
|
client.on('disconnect', function(packet) {
|
||||||
console.log('disconnected: '+ packet.reason);
|
console.log('disconnected: '+ packet.reason);
|
||||||
});
|
});
|
||||||
|
client.on('end', function(err) {
|
||||||
|
console.log('Connection lost');
|
||||||
|
});
|
||||||
client.on('chat', function(packet) {
|
client.on('chat', function(packet) {
|
||||||
var jsonMsg = JSON.parse(packet.message);
|
var jsonMsg = JSON.parse(packet.message);
|
||||||
if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
|
if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
|
||||||
|
|
Loading…
Reference in a new issue