Created
June 12, 2015 16:13
-
-
Save alejzeis/89284b5eaab0f97e0d5e to your computer and use it in GitHub Desktop.
A Demo of using the CustomPacket class to decode/encode MCPE packets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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