more debugging

This commit is contained in:
Soph :3 2024-05-03 20:32:10 +03:00
parent c72b2c494e
commit 59d2db1785
Signed by: sophie
GPG key ID: EDA5D222A0C270F2

View file

@ -47,18 +47,20 @@ export class Server {
socket.data.dataBuffer = data; socket.data.dataBuffer = data;
} }
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.");
const parseBuffer = () => { const parseBuffer = () => {
if(!socket.data.dataBuffer) return; if(!socket.data.dataBuffer) return;
const packetId = socket.data.dataBuffer.readUint8(0); const packetId = socket.data.dataBuffer.readUint8(0);
const packetLength = this.lengthMap.get(packetId); const packetLength = this.lengthMap.get(packetId);
if(!packetLength) { if(!packetLength) {
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) return;
this.handlePacket(socket.data.dataBuffer.copyWithin(0, 1), packetId, socket); this.handlePacket(socket.data.dataBuffer.subarray(1), packetId, socket);
log.debug("Parsed packet", packetId, "with packet length", packetLength)
socket.data.dataBuffer = socket.data.dataBuffer.subarray(packetLength+1); socket.data.dataBuffer = socket.data.dataBuffer.subarray(packetLength+1);
parseBuffer(); parseBuffer();
} }