- Joined
- Sep 3, 2008
- Messages
- 977
- Reaction score
- 31
Packets and FlyFF - Introduction to packets with FlyFF
In this thread I will tell you all you need to know about FlyFF packets and how they work - including some tips that will make it easier for you to create a server.
First of all, you must know that FlyFF packets are NOT encrypted, which makes it really easy to read the data.
Now, lets start with the basics.
]The following objects are used in FlyFF packets:
Integer - 4 bytes. Little endian, meaning a normal 0x11223344 integer would be parsed as 44 33 22 11 instead of 11 22 33 44.
String - 4+X bytes. The first 4 bytes indicate an integer which tells the client/server how long the string is, and right after those 4 bytes, comes the string itself, every character represented with it's ASCII code.
Short - 2 bytes. Also little endian, so a normal 0x1122 short would be parsed as 22 11 instead of 11 22.
Byte - A simple byte, which can mean a lot. Known to be used with gender.
Long - 8 bytes. Once again, little endian, so a normal 0x1122334455667788 (no wonder they called that "long") would be parsed as 88 77 66 55 44 33 22 11 instead of 11 22 33 44 55 66 77 88.
Floats - 4 bytes. I have no idea how these work, and if you know how, feel free to tell me.
[/SIZE]
Please note that every FlyFF packet starts with byte 0x5E (ASCII: ^).
]Basic client packet structure]
There are 2 forms of client packets: Form #1 which is used for login server only and form #2 which is used for cluster and world servers.
Form #1
Form #2
The only difference is the addition of -1 after data hash and before command. Remember, form #2 goes to cluster and world client2server packets while form #1 is ONLY login server.
Basic server packet structure
There is only one form of the server2client packet.
Form #3
The length of the packet should be the length of the whole thing - 5 bytes. So if the whole packet is, for example:
5E 08 00 00 00 04 00 00 00 12 34 56 78
As you can see, the whole packet has 13 bytes, but we only calculate the bytes that come AFTER the length integer, so, as you can see, there are two integers after the length integer, so we then calculate the total amount of bytes in the packet (after the length integer) and set the length integer to that.
Note that everytime a client connects to your server, your server should first send a packet containing the session ID.
This is the form of the session ID packet, which is valid for all 3 servers:
Some tips about reversing
As you already saw, we need to reverse numbers before we add them to the packet.
This is how I reverse numbers. The following is for integers only:
I take a number to reverse (for example: 560). I convert it to an hexadecimal string (would result in 230) then I left-pad the string with 0's to total size of 8: 00000230. Then, I split it into 4 substrings, each one containing 2 characters which together represent a byte, so this would split it into 4 bytes (as strings, of course), so set #1=00, set #2=00, set #3=02 and set #4=30.
I then convert the 4 substrings into real byte values, and add them to the packet in this order:
set #4 then set #3 then set #2 then set #1
This will successfully add an integer to the packet.
You can do the same for int16 (short) and int64 (long) variables.
This is all for now.
I might have spelling errors or whatever, I am writing this guide at 6:50am after staying up the whole night.
In this thread I will tell you all you need to know about FlyFF packets and how they work - including some tips that will make it easier for you to create a server.
First of all, you must know that FlyFF packets are NOT encrypted, which makes it really easy to read the data.
Now, lets start with the basics.
]The following objects are used in FlyFF packets:
Integer - 4 bytes. Little endian, meaning a normal 0x11223344 integer would be parsed as 44 33 22 11 instead of 11 22 33 44.
String - 4+X bytes. The first 4 bytes indicate an integer which tells the client/server how long the string is, and right after those 4 bytes, comes the string itself, every character represented with it's ASCII code.
Short - 2 bytes. Also little endian, so a normal 0x1122 short would be parsed as 22 11 instead of 11 22.
Byte - A simple byte, which can mean a lot. Known to be used with gender.
Long - 8 bytes. Once again, little endian, so a normal 0x1122334455667788 (no wonder they called that "long") would be parsed as 88 77 66 55 44 33 22 11 instead of 11 22 33 44 55 66 77 88.
Floats - 4 bytes. I have no idea how these work, and if you know how, feel free to tell me.
[/SIZE]
Please note that every FlyFF packet starts with byte 0x5E (ASCII: ^).
]Basic client packet structure]
There are 2 forms of client packets: Form #1 which is used for login server only and form #2 which is used for cluster and world servers.
Form #1
Code:
5E
[int] Length hash
[int] Packet length
[int] Data hash
[int] Command
Rest of the packet data
Form #2
Code:
5E
[int] Length hash
[int] Packet length
[int] Data hash
[int] -1 (0xFFFFFFFF)(FF FF FF FF)
[int] Command
Rest of the packet data
The only difference is the addition of -1 after data hash and before command. Remember, form #2 goes to cluster and world client2server packets while form #1 is ONLY login server.
Basic server packet structure
There is only one form of the server2client packet.
Form #3
Code:
5E
[int] Length
Rest of the packet data
The length of the packet should be the length of the whole thing - 5 bytes. So if the whole packet is, for example:
5E 08 00 00 00 04 00 00 00 12 34 56 78
As you can see, the whole packet has 13 bytes, but we only calculate the bytes that come AFTER the length integer, so, as you can see, there are two integers after the length integer, so we then calculate the total amount of bytes in the packet (after the length integer) and set the length integer to that.
Note that everytime a client connects to your server, your server should first send a packet containing the session ID.
This is the form of the session ID packet, which is valid for all 3 servers:
Code:
5E
08 00 00 00
00 00 00 00
[int] Session ID
Some tips about reversing
As you already saw, we need to reverse numbers before we add them to the packet.
This is how I reverse numbers. The following is for integers only:
I take a number to reverse (for example: 560). I convert it to an hexadecimal string (would result in 230) then I left-pad the string with 0's to total size of 8: 00000230. Then, I split it into 4 substrings, each one containing 2 characters which together represent a byte, so this would split it into 4 bytes (as strings, of course), so set #1=00, set #2=00, set #3=02 and set #4=30.
I then convert the 4 substrings into real byte values, and add them to the packet in this order:
set #4 then set #3 then set #2 then set #1
This will successfully add an integer to the packet.
You can do the same for int16 (short) and int64 (long) variables.
This is all for now.
I might have spelling errors or whatever, I am writing this guide at 6:50am after staying up the whole night.
Last edited: