fix some bugs
This commit is contained in:
parent
59d2db1785
commit
888782c2a9
1 changed files with 10 additions and 4 deletions
|
@ -39,18 +39,20 @@ export class Server {
|
|||
hostname: process.env.HOST || "127.0.0.1",
|
||||
port: +process.env.PORT!,
|
||||
socket: {
|
||||
data: (socket, data) => {
|
||||
data: async (socket, data) => {
|
||||
if(socket.data.dataBuffer) {
|
||||
const newBuffer = Buffer.concat([socket.data.dataBuffer, data]);
|
||||
const newBuffer = Buffer.concat([socket.data.dataBuffer, data]);
|
||||
socket.data.dataBuffer = newBuffer;
|
||||
} else {
|
||||
socket.data.dataBuffer = data;
|
||||
}
|
||||
log.debug("Socket", socket.remoteAddress, "has", socket.data.dataBuffer.length, "data for parsing.");
|
||||
|
||||
if(config.debug) await new Promise(r => setTimeout(r, 100));
|
||||
|
||||
const parseBuffer = () => {
|
||||
if(!socket.data.dataBuffer) return;
|
||||
|
||||
if(socket.data.dataBuffer.length == 0) return;
|
||||
const packetId = socket.data.dataBuffer.readUint8(0);
|
||||
const packetLength = this.lengthMap.get(packetId);
|
||||
if(!packetLength) {
|
||||
|
@ -59,12 +61,15 @@ export class Server {
|
|||
};
|
||||
if(socket.data.dataBuffer.byteLength < packetLength) return;
|
||||
|
||||
this.handlePacket(socket.data.dataBuffer.subarray(1), packetId, socket);
|
||||
this.handlePacket(socket.data.dataBuffer.copyWithin(0, 1, packetLength+1), packetId, socket);
|
||||
|
||||
log.debug("Parsed packet", packetId, "with packet length", packetLength)
|
||||
|
||||
socket.data.dataBuffer = socket.data.dataBuffer.subarray(packetLength+1);
|
||||
parseBuffer();
|
||||
}
|
||||
|
||||
|
||||
parseBuffer();
|
||||
},
|
||||
open: (socket) => {
|
||||
|
@ -318,6 +323,7 @@ export class Server {
|
|||
}
|
||||
|
||||
if (pluginAnswer.some((e) => e == true)) {
|
||||
console.log(world.size, position)
|
||||
PacketDefinitions.setBlock(position, world.getBlock(position), player);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue