quit.js 563 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const Command = require('./command.js');
  3. const CommandCode = require('../constants/commands.js');
  4. const Packet = require('../packets/packet.js');
  5. class Quit extends Command {
  6. constructor(callback) {
  7. super();
  8. this.done = callback;
  9. }
  10. start(packet, connection) {
  11. connection._closing = true;
  12. const quit = new Packet(
  13. 0,
  14. Buffer.from([1, 0, 0, 0, CommandCode.QUIT]),
  15. 0,
  16. 5
  17. );
  18. if (this.done) {
  19. this.done();
  20. }
  21. connection.writePacket(quit);
  22. return null;
  23. }
  24. }
  25. module.exports = Quit;