more debugging, and fixes

This commit is contained in:
Soph :3 2024-05-03 21:09:22 +03:00
parent 957249ed71
commit 5226d5652a
Signed by: sophie
GPG key ID: EDA5D222A0C270F2

View file

@ -32,7 +32,7 @@ export class Server {
maxUsers = config.maxUsers;
worlds: World[] = [new World({ x: 64, y: 64, z: 64 }, config.main)];
worlds: World[] = [new World({ x: 64, y: 64, z: 64 }, config.main), new World({ x: 256, y: 64, z: 256 }, "large")];
async start(port: number) {
this.server = Bun.listen<{dataBuffer?: Buffer}>({
@ -48,7 +48,7 @@ export class Server {
}
log.debug("Socket", socket.remoteAddress, "has", socket.data.dataBuffer.length, "data for parsing.");
//if(config.debug) await new Promise(r => setTimeout(r, 100));
//if(config.debug) await new Promise(r => setTimeout(r, 300));
const parseBuffer = () => {
if(!socket.data.dataBuffer) return;
@ -59,13 +59,16 @@ export class Server {
log.debug("Incorrect packet ID", packetId, "packet length could not be found.")
return;
};
if(socket.data.dataBuffer.byteLength < packetLength) return;
if(socket.data.dataBuffer.byteLength < packetLength) {
log.debug("not enough bytes for packet", packetId)
return;
};
this.handlePacket(socket.data.dataBuffer.copyWithin(0, 1, packetLength+1), packetId, socket);
this.handlePacket(socket.data.dataBuffer.copyWithin(0, 1, packetLength), packetId, socket);
log.debug("Parsed packet", packetId, "with packet length", packetLength)
socket.data.dataBuffer = socket.data.dataBuffer.subarray(packetLength+1);
//console.log(socket.data.dataBuffer, socket.data.dataBuffer.copyWithin(0, 1, packetLength))
socket.data.dataBuffer = Uint8Array.prototype.slice.call(socket.data.dataBuffer, packetLength+1);
parseBuffer();
}
@ -258,7 +261,7 @@ export class Server {
const player = this.players.find((e) => e.socket == connection);
if (!player) return;
packet.readByte();
packet.readSByte();
player.position.x = packet.readShort();
player.position.y = packet.readShort();
player.position.z = packet.readShort();
@ -301,11 +304,11 @@ export class Server {
const player = this.players.find((e) => e.socket == connection);
if (!player) return;
const position = {
x: packet.readShort(),
y: packet.readShort(),
z: packet.readShort(),
};
let position = {x:0,y:0,z:0}
position.x = packet.readShort();
position.y = packet.readShort();
position.z = packet.readShort();
const mode = packet.readByte();
const block = packet.readByte();
@ -323,7 +326,6 @@ export class Server {
}
if (pluginAnswer.some((e) => e == true)) {
console.log(world.size, position)
PacketDefinitions.setBlock(position, world.getBlock(position), player);
return;
}