mc-beta-server/server/Packets/Packet.js

30 lines
557 B
JavaScript
Raw Permalink Normal View History

2021-08-24 15:29:46 +01:00
/*
==============- Packet.js -=============
Created by Holly (tgpethan) (c) 2021
Licenced under MIT
========================================
*/
2021-08-12 04:58:56 +01:00
const bufferStuff = require("../bufferStuff.js");
2021-08-11 15:05:14 +01:00
module.exports = class {
2021-08-12 04:58:56 +01:00
constructor(packetID = 0x00) {
this.id = packetID;
2021-08-24 15:08:48 +01:00
this.packetSize = 0;
2021-08-12 04:58:56 +01:00
this.writer = null;
2021-08-11 15:05:14 +01:00
}
2021-08-12 04:58:56 +01:00
writePacket() {
2021-08-24 15:08:48 +01:00
this.writer = new bufferStuff.Writer(this.packetSize);
2021-08-11 15:05:14 +01:00
2021-08-12 04:58:56 +01:00
this.writer.writeByte(this.id);
return this.writer;
2021-08-11 15:05:14 +01:00
}
2021-08-12 04:58:56 +01:00
toBuffer() {
return this.writer == null ? Buffer.alloc(0) : this.writer.buffer;
2021-08-11 15:05:14 +01:00
}
}