Skip to content

Instantly share code, notes, and snippets.

@alejzeis
Created June 12, 2015 16:13
Show Gist options
  • Save alejzeis/89284b5eaab0f97e0d5e to your computer and use it in GitHub Desktop.
Save alejzeis/89284b5eaab0f97e0d5e to your computer and use it in GitHub Desktop.
A Demo of using the CustomPacket class to decode/encode MCPE packets.
/*
* Copyright (C) 2015 jython234
*/
CustomPacket cp = new CustomPacket();
cp.decode(rawBuffer); //The rawbuffer is the raw datagram packet's buffer you have recieved.
System.out.println(cp.sequenceNumber); //Access the sequence number to check if you missed any packets from the client
for(CustomPacket.InternalPacket ip : cp.packets){ // Loop thru all the decoded packets
//Access messageIndex, buffer, etc
System.out.println(Arrays.toString(ip.buffer)); //The decoded packet buffer (ClientConnect, Ping, etc)
}
CustomPacket.InternalPacket ip = new CustomPacket.InternalPacket();
ip.reliability = (byte) 2; //Default reliability is 2
ip.messageIndex = nextMessageIndex++;
ip.buffer = new byte[] {0x15} //CLIENT_DISCONNECT
cp = new CustomPacket();
cp.packets.add(ip);
byte[] data = cp.encode();
//Now you can send you very own CustomPacket!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment