Valhalla Legends Forums Archive | Battle.net Bot Development | Quick Packet Receiving Question

AuthorMessageTime
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 :/
September 8, 2009, 2:18 PM
Myndfyr
[quote author=Tuck link=topic=18055.msg183342#msg183342 date=1252419502]
Question 1: Do i need BNLS/Hashes to make packets to send?
[/quote]
No.  However, at some point during the process of connecting to Battle.net, you will need one of those.

[quote author=Tuck link=topic=18055.msg183342#msg183342 date=1252419502]Question 2: Could anyone show me an example of what they do when they receive bytes from B.Net[/quote]
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 author=Tuck link=topic=18055.msg183342#msg183342 date=1252419502]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.[/quote]
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 author=Tuck link=topic=18055.msg183342#msg183342 date=1252419502]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 :/
[/quote]
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.
September 8, 2009, 3:23 PM
Tuck
[quote author=MyndFyre link=topic=18055.msg183343#msg183343 date=1252423434]
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.[/quote]

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%
[code]{
    Stream.Read(Result, 0, (ushort)(Length - 4));
    Result = Receive(Data, 0, (ushort)(Length - 4));
}[/code]

[code]if (length > BattleNetClientResources.IncomingBufferPool.BufferLength)
                            data = new byte[unchecked((ushort)length - 4)];
                        else
                            data = BattleNetClientResources.IncomingBufferPool.GetBuffer();[/code]
with BufferLength do you mean the Bytes.Length ? and if yes including 0 or counting from 1
September 8, 2009, 3:26 PM
Myndfyr
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.
September 8, 2009, 8:04 PM
Tuck
[quote author=MyndFyre link=topic=18055.msg183345#msg183345 date=1252440262]
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.
[/quote]

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 :)
September 9, 2009, 10:31 AM

Search