mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-15 03:14:56 -05:00
Properly close chat example when connection fails or errors
This commit is contained in:
parent
d8b1ce68ac
commit
e94876d30a
1 changed files with 14 additions and 3 deletions
|
@ -84,13 +84,24 @@ client.on([states.PLAY, 0x40], function(packet) { // you can listen for packets
|
|||
console.info(color('Kicked for ' + packet.reason, "blink+red"));
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
|
||||
var chats = [];
|
||||
|
||||
|
||||
client.on('connect', function() {
|
||||
console.info(color('Successfully connected to ' + host + ':' + port, "blink+green"));
|
||||
});
|
||||
|
||||
client.on('end', function() {
|
||||
console.log("Connection lost");
|
||||
process.exit();
|
||||
});
|
||||
|
||||
client.on('error', function(err) {
|
||||
console.log("Error occured");
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
client.on('state', function(newState) {
|
||||
if (newState === states.PLAY) {
|
||||
chats.forEach(function(chat) {
|
||||
|
@ -159,4 +170,4 @@ function parseChat(chatObj, parentState) {
|
|||
}
|
||||
return chat;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue