more debugging, and fixes
This commit is contained in:
parent
957249ed71
commit
5226d5652a
|
@ -32,7 +32,7 @@ export class Server {
|
||||||
|
|
||||||
maxUsers = config.maxUsers;
|
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) {
|
async start(port: number) {
|
||||||
this.server = Bun.listen<{dataBuffer?: Buffer}>({
|
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.");
|
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 = () => {
|
const parseBuffer = () => {
|
||||||
if(!socket.data.dataBuffer) return;
|
if(!socket.data.dataBuffer) return;
|
||||||
|
@ -59,13 +59,16 @@ export class Server {
|
||||||
log.debug("Incorrect packet ID", packetId, "packet length could not be found.")
|
log.debug("Incorrect packet ID", packetId, "packet length could not be found.")
|
||||||
return;
|
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)
|
log.debug("Parsed packet", packetId, "with packet length", packetLength)
|
||||||
|
//console.log(socket.data.dataBuffer, socket.data.dataBuffer.copyWithin(0, 1, packetLength))
|
||||||
socket.data.dataBuffer = socket.data.dataBuffer.subarray(packetLength+1);
|
socket.data.dataBuffer = Uint8Array.prototype.slice.call(socket.data.dataBuffer, packetLength+1);
|
||||||
parseBuffer();
|
parseBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +261,7 @@ export class Server {
|
||||||
const player = this.players.find((e) => e.socket == connection);
|
const player = this.players.find((e) => e.socket == connection);
|
||||||
if (!player) return;
|
if (!player) return;
|
||||||
|
|
||||||
packet.readByte();
|
packet.readSByte();
|
||||||
player.position.x = packet.readShort();
|
player.position.x = packet.readShort();
|
||||||
player.position.y = packet.readShort();
|
player.position.y = packet.readShort();
|
||||||
player.position.z = packet.readShort();
|
player.position.z = packet.readShort();
|
||||||
|
@ -301,11 +304,11 @@ export class Server {
|
||||||
const player = this.players.find((e) => e.socket == connection);
|
const player = this.players.find((e) => e.socket == connection);
|
||||||
if (!player) return;
|
if (!player) return;
|
||||||
|
|
||||||
const position = {
|
let position = {x:0,y:0,z:0}
|
||||||
x: packet.readShort(),
|
position.x = packet.readShort();
|
||||||
y: packet.readShort(),
|
position.y = packet.readShort();
|
||||||
z: packet.readShort(),
|
position.z = packet.readShort();
|
||||||
};
|
|
||||||
const mode = packet.readByte();
|
const mode = packet.readByte();
|
||||||
const block = packet.readByte();
|
const block = packet.readByte();
|
||||||
|
|
||||||
|
@ -323,7 +326,6 @@ export class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pluginAnswer.some((e) => e == true)) {
|
if (pluginAnswer.some((e) => e == true)) {
|
||||||
console.log(world.size, position)
|
|
||||||
PacketDefinitions.setBlock(position, world.getBlock(position), player);
|
PacketDefinitions.setBlock(position, world.getBlock(position), player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue