Register for your free account! | Forgot your password?

You last visited: Today at 20:33

  • Please register to post and access all features, it's quick, easy and FREE!

Tutorial: Introduction to Packets

Old   #1
elite*gold: 12
Join Date: Jul 2011
Posts: 7,084
Received Thanks: 3,396
Tutorial: Introduction to Packets

Hello there, this is my third attempt at writing this. I assume you found this tutorial because you have an interest in programming with packets. Before we start, you should know a bit about the basics of programming in C#. If you're relatively new, that's okay. I'll spend a lot of my time in this tutorial reviewing concepts. In general, this is a really good place to start if you want to review on your own time: C# Programming Guide. If you have a question for me at any time, feel free to reply below and I'll do my best to answer or redirect you to a good article.

Before we talk about packets, let's talk about sockets. Sockets are a way for two applications to talk to one another over a network. You can think of this as a phone line, where each end is a phone (or socket). When the Conquer client is ready to talk to the game server, it dials it up. The game server is listening for that call from the client, and will accept the call once it comes in. How they talk are where packets and protocols come in. Protocols help us define how we talk over a network, while packets contain our actual message. Take a minute to review the video below about the internet, packets, and protocols.

In Conquer Online, we use TCP/IP to define how messages are exchanged between the client and server. IP defines how the packet routes to the server, while TCP defines how packets are broken down and reassembled in the right order (both shown in the video above). To us, however, we only see packets in full (for the most part). We don't have to worry about how it gets to the server; we only need to focus on what they say.

Byte Ordering
To understand how Conquer Online talks, we have to understand how it orders words (both in the figurative and literal sense). Messages are best represented as an array of bytes (bytes being the smallest addressable unit in programming). For example, in the string "Hello World" (assuming ASCII encoding), each character is one byte. So, the message "Hello World" would appear as the following packet:

 H  e  l  l  o     W  o  r  l  d
[48 65 6C 6C 6F 20 57 6F 72 6C 64]
If you're confused, the above is shown in hexadecimal. See this for converting characters to bytes. I used hexadecimal because the range of a byte in decimal is from 0 to 255. 255 is an ugly number to work with. In hexadecimal, the range is from 0 to FF. FF is an easier number to work with as a ceiling since it's the highest number it can be for two digits. It means that any number larger than FF or two digits can overflow nicely into the next byte of our message.

For numbers larger than 255, such as a word (ushort), double word (uint), or quad word (ulong), the value of that number overflows into the next bytes. For example, the word 1024 in hexadecimal is 400. This would be split across two bytes as 4 and 00. The problem is, in what order? It can either be written as [04 00] or [00 04]. This is called byte ordering, and is much like a dialect for speaking.

There are two types of byte orders: Little Endian and Big Endian. The goal of Big Endian is to store the most significant byte in the smallest address. This would mean that our hexadecimal number of 400 would appear as [04 00]. This is easy to read, as it reads from left to right. The goal of Little Endian is to store the least significant byte in the smallest address. This means our hexadecimal number of 400 would appear as [00 04]. This reads backwards, but the value in doing this is that a number such as 5 converted from a word to a byte wouldn't require changing the address. It would convert simply from [05 00] to just [05]. We didn't change the starting point of our array to do that, it just worked. Conquer Online uses Little Endian, and that's good because C# also uses Little Endian for bit conversions and streams. For help converting between decimal and hexadecimal, consider using the Windows Calculator in Programmer mode.

Now that we understand how Conquer Online orders words in messages, let's go over what Conquer Online is talking about. With every packet being sent, the client and server start with a header of two words. This header contains the length of the packet and the type of packet being sent. Here is an example: [18 00 15 27]. The first word is the length: 0018 (or 24 in decimal). The second word is the type: 2715 (10005 in decimal). This is the packet. Take a minute to look over the structure on the wiki. Each packet type has a different message that it sends. For example, the MsgWalk packet describes a step in the world, performed by a player or monster. Let's read the following packet dump for MsgWalk for patch 5517. The direction diagram below will also help.

18 00 15 27 72 00 00 00 29 20 1A 00 00 00 00 00 
82 2D 3F 05 00 00 00 00 54 51 53 65 72 76 65 72
[Offset 04] 72 00 00 00 = 114: The direction of the player mod possible angles (8). 114 mod 8 = direction 2.
[Offset 08] 29 20 1A 00 = 1712169: The unique character ID making the step.
[Offset 12] 00 00 00 00 = 0: The type of movement being sent (walking).
[Offset 16] 82 2D 3F 05 = 88026498: Timestamp (current system tick).
[Offset 20] 00 00 00 00 = 0: Map ID (not always supplied).
[Offset 24] 54 51 53 65 72 76 65 72 = TQServer: The footer of the packet.

For Conquer Online patches greater than 5017, each packet from the game server ends with either "TQServer" or "TQClient", depending on where it is from. "TQServer" indicates that the packet is from the server, while "TQClient" indicates that the packet is from the client. The length of the footer is not included in offset 0 of the header (which is the length of the packet).

In Practice
Phew! I know that's a lot to take in, but now let's program this structure in C# (a lot easier). In this tutorial, I'll be using BitConverter to read the structure into C#. In the example below, I am not handling the packet footer. Instead, I ignore it (as I don't have a need for it - it's really only good for debugging the source of a packet over the network as a packet dump).

var length = BitConverter.ToUInt16(Packet, 0);
var typeid = BitConverter.ToUInt16(Packet, 2);
var direction = BitConverter.ToUInt32(Packet, 4) % 8;
var character = BitConverter.ToUInt32(Packet, 8);
var typemove = BitConverter.ToUInt32(Packet, 12);
var timestamp = BitConverter.ToUInt32(Packet, 16);
var mapid = BitConverter.ToUInt32(Packet, 20);
If you're using a public source, which I recommend you reference a few anyways to get the hang of programming for Conquer Online, look at how your server handles packet reading and writing. For better examples of a socket system and packet handling, check out my source: . It has its problems, but is fully documented and easy to learn from. I hope this guide has helped you understand a bit more about how networking and packets work with Conquer Online. If you have any questions, or requests for better explanations, please let me know. Cheers.

Spirited is offline  
10 Users
Old 11/07/2017, 08:58   #2
elite*gold: 0
Join Date: Sep 2016
Posts: 23
Received Thanks: 5
glad to see you guys still there lol
nice tutorial

felixanius is offline  
Old 11/18/2017, 13:25   #3
elite*gold: 0
Join Date: Jul 2007
Posts: 137
Received Thanks: 3
Congratulations dear, it will be of great help. Thanks for sharing
zakkwilde_17 is offline  
Old 11/18/2017, 13:37   #4
Im Ruhestand

elite*gold: 0
The Black Market: 405/0/0
Join Date: Aug 2014
Posts: 30,216
Received Thanks: 2,989

wshbr is offline  
1 User
Old 11/18/2017, 21:55   #5
elite*gold: 12
Join Date: Jul 2011
Posts: 7,084
Received Thanks: 3,396
Originally Posted by wshbr View Post
Thank you o:
Spirited is offline  
Old 05/17/2018, 02:04   #6
elite*gold: 0
Join Date: Dec 2010
Posts: 35
Received Thanks: 0
Could you explain how you get the offset value and what is an offset anyways
kiiD2NiCe is offline  
Old 05/17/2018, 02:12   #7
elite*gold: 12
Join Date: Jul 2011
Posts: 7,084
Received Thanks: 3,396
Originally Posted by kiiD2NiCe View Post
Could you explain how you get the offset value and what is an offset anyways
An offset is a position in the array, otherwise called an index. Arrays are indexed starting from 0. So, for the array { 1, 2, 3 }, offset 0's value is 1, offset 1's value is 2, and offset 2's value is 3. For more information on indexes / offsets for arrays, review arrays for C#:
Spirited is offline  
Old 05/24/2018, 13:17   #8
elite*gold: 0
Join Date: Dec 2012
Posts: 1,625
Received Thanks: 839
Originally Posted by Spirited View Post
An offset is a position in the array, otherwise called an index. Arrays are indexed starting from 0. So, for the array { 1, 2, 3 }, offset 0's value is 1, offset 1's value is 2, and offset 2's value is 3. For more information on indexes / offsets for arrays, review arrays for C#:
Please don't say array.

An offset is more than just a position in an array.

An offset is the position of data within a data segment such as an array, but it could also be a pointer.

And since this topic is about packets then you really shouldn't, since it may not always be an array or a backed buffer.

Conquer's packet layout can be streamed which will at most only have temporary buffers used by the networking protocol and no further down the chain. They could theoretically be completely converted to a data structure such as a struct, in which case the offset will not even be an index, but the position of the struct's memory the data will remain in.

Ex. for an offset 5


[1,      2,      3,      4,      5,      6]
Result: 6


0x00000001 a
0x00000002 b
0x00000003 c
0x00000004 d
0x00000005 e
0x00000006 f
0x00000007 g
0x00000008 h
0x00000009 i
0x00000010 j
0x00000011 k


{0x00000005} (Pointer to 0x00000005)

0 e
1 f
2 g
3 h
4 i
5 j
Result: j


struct Foo
    byte a; // = 1
    byte b; // = 2
    byte c; // = 3
    byte d; // = 4
    byte e; // = 5
    byte f; // = 6
    byte g; // = 7
    byte h; // = 8
    byte i; // = 9
    byte j; // = 10


{ 1, 2, 3, 4, 5, 6, 7, 8, 9 ,10 }
Result: Foo.f which is 6


Indentation is messed up so for some reason it won't point to the correct members.

It should point to 6 for arrays and 6 for struct.

Cba to fix it.
Super Aids is offline  
Old 05/24/2018, 17:29   #9
elite*gold: 12
Join Date: Jul 2011
Posts: 7,084
Received Thanks: 3,396
Uuuhhh.... I was more just trying to keep it simple. From my understanding, an offset is the distance from the base address of an array or data structure, and requires that all elements in that structure be the same size. In conquer, we work in terms of bytes since that's the smallest addressable unit. The simplest explanation of that is a byte array. If I added that to my tutorial, would that be sufficient?

Edit: I could go into stream encoding / decoding using their byte ordering rules if you'd like, which would utilize that definition.

Spirited is offline  

« working guide to multi client | Chat Packet »

Similar Threads
[Release] +5500 Packets structure , client/packets constants
10/07/2012 - CO2 PServer Guides & Releases - 10 Replies
edit : if u know nothing about packets go to this post first explaining what is packets , and explaining a packet with details and everything i start making my very own packet structure to use them on my new proxy but i thought of ripping them from the source so yeah the following packets is ripped of trinity base source right now im just providing the packets structure...
Packets packets packets...
10/06/2012 - CO2 PServer - Discussions / Questions - 13 Replies
I have been struggling to understand what is a Packet how could i create one with the data i want then send it to my server So please any one tell if as example i want to send some info from my client to my server, then handle them from the server how could i do that : i have my socket server, also i don't wanna copy and paste codes i want to UNDERSTAND. My PacketReader.cs
[REQUEST] packets send list , or anyway to sniff send packets
08/10/2012 - Kal Online - 16 Replies
hey everyone , as mentioned , i wanna know if anyone got a complete send packets lists or anyway i can sniff send packets , thanks in advance
[Packets] Wie änder ich flyff packets?
07/16/2011 - Flyff PServer - Discussions / Questions - 19 Replies
HeyHo, Ich würde sehr gerne wissen wie man die Flyff Packets ändert... ich denke mal Zahlen ändern werden nicht ausreichen oder?
[TUTORIAL] Starter friendly tutorial to searching for Nuke casting time [TUTORIAL]
02/09/2011 - 9Dragons - 12 Replies
If you already have Cheat Engine and know how to use it, skip to part 4 of the tutorial. 1. Introduction This forum has helped me quite a bit, so I decided to give something back :) Now I've noticed there are quite a few who ask for nuke casting time hacks / address', and I've also noticed, that there are quite a few who are REALLY annoyed with these questions, so I decided to write this so both sides can benefit from it. 2. Getting started First off, you need to have Cheat Engine...

All times are GMT +1. The time now is 20:33.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Abuse
Copyright ©2018 elitepvpers All Rights Reserved.