How to use the minecraft-protocol.protocol.parsePacket function in minecraft-protocol

To help you get started, we’ve selected a few minecraft-protocol examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Yogu / minecraft-sniffer / index.js View on Github external
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']);