Before you continue, you must have a background in data types (signed and unsigned bytes, shorts, ints, longs, etc) and understand the amount of space they take up in a byte array. A background in byte arrays would be highly recommended before continuing this tutorial. You can find more information about byte arrays on MSDN. You must know how to make a new chat command in your source.
The Concept:
In Microsoft's Visual C# language, data is a collection of bytes that forms information in sequence. Sequence is very important when dealing with data because computers read instructions in sequence. On your computer, data is stored and accessed separately within each program; however, internet applications need to rely on data from elsewhere - sometimes from across the world. For an internet application (the client) to work on your computer, it must connect to the data provider (the server). Once the client establishes a connection with the server, the server tells the client to begin accepting data transactions. These data transactions form a line that connects the two computers together (each computer being an endpoint on this line). The endpoints contain a listener and system to handle data transactions. Like a radio antenna, the listener listens for incoming transmissions from the data source (our server). This system of listening for, handling, receiving, and sending data is called a Socket system. The two socket systems on each endpoint create an inter-process communication flow (in other words, a sequential flow of data). The data groups being sent across the flow (or stream) are formatted using common structures known by both the server and client. These groups of structured data being sent across the stream are called packets. Take this time to watch this video about packets:
. Like everything else relating to data structures in Computer Science, packets are constructed in sequence. This means that as you construct packets, you must add data in order (like structuring a house). This would mean completely reconstructing packets as variables (our building materials) change. Although packets must be sent in sequence, we can avoid reconstructing them every time a variable in the packet changes by using Object Oriented Programming (OOP). Visual C# is an OOP language, thus we can create an array of bytes at any time as an object. Visual C# uses byte arrays to send packets to and receive packets from the stream.
Packet Structures:
Like a blueprint for a house, packets have blueprints called packet structures. Each step of the structure relates to a position in the byte array. For example, in the first four bytes of every packet in Conquer Online, the client and server write a common header containing the length (the first 2 bytes / first unsigned short) and the packet identity (the second 2 bytes / unsigned short). Positionally, that would mean that at index 0 of the array, the client or server would write the packet length. At index 2, the packet identity. Here's a picture representation of positions in arrays:
. These storage index numbers / positions in the array are called offsets. Take this time to review the structure of some of the packets on the
or review the few I have on my
. I suggest you review
. It's the one we'll be using as an example.If you review
, you'll notice that elements being written to the array aren't byte sized. They exceed the size of a byte. Using a packet writer (found in Impulse's sources) or pointers, you can write large numbers as multiple bytes to an array. Strings may also be easily written to a byte array by writing each ASCII character as a byte in the array. Values can be read from arrays using BitConverter, which combines bytes in a byte array to form larger numbers, or Encoding.ASCII.GetString, which reads bytes as ASCII characters to create a string. The computer doesn't know what values are at what offsets, thus without packet structures, packet bodies would be meaningless. That's where you come in. Let's make a packet using a packet structure as an example. Example:
Let's create a packet to send to the Conquer Online client. Make a new command called "packettest". In this command, we're going to make a skill adding packet (that adds a skill to the client's interface). I chose this packet because the structure has never changed and it's simple. The only expectation is that this packet will display the skill in the interface. Handlers come later. Don't cheat by looking at the skill packet's constructor in your source. Let's start by making the byte array. We'll define it to be of length 20: 4 bytes for the body's header (the length and identity of the packet), 8 bytes for the body's data (the experience, skill id, and skill level), and another 8 bytes for the "TQServer" ASCII character stamp (which I'll talk about in a minute). To write values to the offsets in the array, we're going to use Impulse's packet writer class. If requested, I'll explain how that works in another tutorial. To start, we're going to look at the packet structure:
. You'll notice two things: the static id is at offset 8, and the length is 12. The length written to the packet does not include the length of the "TQServer" stamp that is written to the end of the packet. The static ids for skills can be found on my
and
. Using Impulse's packet writer is fairly simple. To write an unsigned short, we're going to use WriteUInt16; unsigned int, WriteUInt32. To use the packet writer, we assign the following parameters: Value, Offset, Array. Here's an example of writing the packet using the packet writer:
. To send the constructed packet to yourself, you're going to use the client's send method which encrypts and sends the packet to the client. In Impulse's send method, he writes "TQServer" to the end of the packet. In patch 5018, TQ introduced this addition with Blowfish. If your source is below patch 5018, then your array length is the packet body length.Practice:
Ok, now that you have the weapon skill working, erase it. Practice your new background in Conquer Online packet structures to write this packet structure to an array:
. This packet updates the experience of a weapon skill. Good luck!The Assumptions Made in this Tutorial:
This tutorial assumes that the inter-process communication flow is using the TCP/IP protocol. The video provided assumes that the internet is linear when it's really a web or net (thus why the internet is called the World Wide Web).
My Approach:
The main problem (to my understanding and from my experience) is the concept behind packets. I remember having difficulty with the concept; but once I got it, packets were easy. There's a lot of documentation on packet structures, but none on C# inter-process communications in Conquer Online private servers, specifically packets and how they interact with the server. Anyways, that's why I chose this approach. Hopefully this helps a few people get started.






