• Welcome to Valhalla Legends Archive.
 

Quick Packet Receiving Question

Started by Tuck, September 08, 2009, 09:18 AM

Previous topic - Next topic

Tuck

[RB] Packet Builder
[C#]Packet Buffer

If you don't want to help me, you don't have to. [If my grammar sucks to much let me know i'm not English :)]

I've searched for a hour now and only found these that doesn't quite answer my question, only made me a bit confused that i got more questions.

Question 1: Do i need BNLS/Hashes to make packets to send?

Question 2: Could anyone show me an example of what they do when they receive bytes from B.Net

Question 3: I'm pretty sure i saw something that if the byte array length equals to a x value it means something but i can't seem to find the topic again.

Question 4: LOGON SEQUENCES for Diablo II shows i would need to send Single DWORD's, also says some how it have to contain the login information, as i don't see how that works :/

MyndFyre

Quote from: Tuck on September 08, 2009, 09:18 AM
Question 1: Do i need BNLS/Hashes to make packets to send?
No.  However, at some point during the process of connecting to Battle.net, you will need one of those.

Quote from: Tuck on September 08, 2009, 09:18 AMQuestion 2: Could anyone show me an example of what they do when they receive bytes from B.Net
Kind of, although it's somewhat performance-optimized so it might be a little tough:
Receiving the data and selecting a parser and an example of actually handling a packet.

Quote from: Tuck on September 08, 2009, 09:18 AMQuestion 3: I'm pretty sure i saw something that if the byte array length equals to a x value it means something but i can't seem to find the topic again.
There are a couple things.  The packet header (the first four bytes) indicates how long the packet is supposed to be.  If the chunk of data you receive is shorter, you need to add in the next chunk of data you receive.  If it's longer, you need to look for the next packet as well in the chunk you just received.  The code to which I linked in the previous section bypasses that requirement though by never receiving more data than what it expects.

Quote from: Tuck on September 08, 2009, 09:18 AMQuestion 4: LOGON SEQUENCES for Diablo II shows i would need to send Single DWORD's, also says some how it have to contain the login information, as i don't see how that works :/
The site isn't currently coming up for me so I can't comment about what it says.  However, I'm not quite sure what you're asking either.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Tuck

#2
Quote from: MyndFyre on September 08, 2009, 10:23 AM
The site isn't currently coming up for me so I can't comment about what it says.  However, I'm not quite sure what you're asking either.

Starcraft/Broodwar/Diablo II/Lord of Destruction (X-Sha-1)

SEND -> SID_AUTH_INFO (0x50)
RECV <- SID_AUTH_CHECK (0x51)
RECV <- SID_LOGONRESPONSE (0x29)
RECV <- SID_UDPPINGRESPONSE (0x14) [SEXP/STAR/W2BN]
SEND -> SID_ENTERCHAT (0x0A)


And Thanks a lot for replying to my other questions i will be looking at the links and such when i get home :)

would the Stream.Read do the same as receive :/ I'm not 100%
{
    Stream.Read(Result, 0, (ushort)(Length - 4));
    Result = Receive(Data, 0, (ushort)(Length - 4));
}


if (length > BattleNetClientResources.IncomingBufferPool.BufferLength)
                            data = new byte[unchecked((ushort)length - 4)];
                        else
                            data = BattleNetClientResources.IncomingBufferPool.GetBuffer();

with BufferLength do you mean the Bytes.Length ? and if yes including 0 or counting from 1

MyndFyre

#3
You'll have to do some digging in my source code to understand what those pieces mean, but I can give you some insight.

BattleNetClient ultimately inherits from ConnectionBase.  It has a couple overloads of Receive, and the one you're looking at is Receive(byte[], int, int).  This method blocks until the specified length bytes have been read into the byte array and will not return until that condition has been completed (it may throw an exception if the connection becomes disconnected or something like that).  The documentation for something like NetworkStream indicates that the Read method returns an integer, specifying how many bytes were read, and that the value may not always be what was requested.  So, you might call Read(header, 0, 4) and get only one byte read into the buffer, in the event of high network latency, for example.

The BufferLength property is analogous to bytes.Length, but in this case, it's because I queue up free byte arrays to avoid memory fragmentation.  If a packet Battle.net sends is longer than what I usually queue, I simply create an extra byte[] buffer.

I'm sorry, I still don't understand what you're asking about the logon sequence.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Tuck

#4
Quote from: MyndFyre on September 08, 2009, 03:04 PM
You'll have to do some digging in my source code to understand what those pieces mean, but I can give you some insight.

BattleNetClient ultimately inherits from ConnectionBase.  It has a couple overloads of Receive, and the one you're looking at is Receive(byte[], int, int).  This method blocks until the specified length bytes have been read into the byte array and will not return until that condition has been completed (it may throw an exception if the connection becomes disconnected or something like that).  The documentation for something like NetworkStream indicates that the Read method returns an integer, specifying how many bytes were read, and that the value may not always be what was requested.  So, you might call Read(header, 0, 4) and get only one byte read into the buffer, in the event of high network latency, for example.

The BufferLength property is analogous to bytes.Length, but in this case, it's because I queue up free byte arrays to avoid memory fragmentation.  If a packet Battle.net sends is longer than what I usually queue, I simply create an extra byte[] buffer.

I'm sorry, I still don't understand what you're asking about the logon sequence.

I will do my best but I've never coded anything in C# but it looks similar to python witch I've played around with making plugins for games :P (Coding this in vb.net)

the login sequence show send that DWORD there then you receive another DWORD and blah blah like where is all stuff like product, country, login, cdkey :/


Edit: I've found Ringo's vb6 source codes so i don't think i would need more help when i can read the lines so easy now :P but thanks MyndFyre for the basics :)