Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function handleData(client, isToServer, buffer) {
var source = isToServer ? 'client' : 'server';
var dest = isToServer ? 'toServer' : 'toClient';
while (true) {
parsed = protocol.parsePacket(buffer, client.state, isToServer, {packet: 1 });
if (!parsed)
break;
if (parsed.error) {
console.error('parse error from ' + source + ': ' + parsed.error);
} else {
packet = parsed.results;
var name = packetNames[client.state][dest][packet.id];
if (typeof name == 'undefined')
console.error('unknown packet id ' + packet.id + ' from ' + source);
else {
delete packet.id;
if (['mapChunkBulk', 'mapChunk'].indexOf(name) >= 0)
packet.compressedChunkData = '(hidden)';
var output = (name + ': ').bold + JSON.stringify(packet);
console.log(output[isToServer ? 'green' : 'blue']);