Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: Arthas on September 29, 2003, 11:15 PM

Title: A question about the Warcraft III Clan System
Post by: Arthas on September 29, 2003, 11:15 PM
I connect my bot through BNLS... Connects 3RAW on just fine and dandy, but I do NOT recieve my clan's list in 0x65/0x7D.

I assume it has something to do with sending my 0x0a packet, but BNetDocs, or anywhere else dosn't specify anything about it.

I packetlogged my bot, and no luck getting anything. What's up here? I mean I don't recieve the packet at all =/

-Arthas
Title: Re:A question about the Warcraft III Clan System
Post by: SiMi on September 29, 2003, 11:32 PM
Well you could have if you didnt use CSB. Im not exactly sure whats wrong with it but i dont think it has to do with the 0x0A packet.
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on September 29, 2003, 11:36 PM
Pardon, here's my problem:

What do I send when I recieve 0x75? ;D

I'm confused, all I get is FF            , 10 chars long. My packet logger wont even pick it up...

-Arthas
Title: Re:A question about the Warcraft III Clan System
Post by: Spht on September 30, 2003, 10:12 AM
Quote from: Arthas on September 29, 2003, 11:36 PM
Pardon, here's my problem:

What do I send when I recieve 0x75? ;D

I'm confused, all I get is FF            , 10 chars long. My packet logger wont even pick it up...

-Arthas

You don't have to reply to that message. It's just there to let you know of what clan you're in and your position in that clan.
Title: Re:A question about the Warcraft III Clan System
Post by: UserLoser on September 30, 2003, 03:46 PM
Quote from: Arthas on September 29, 2003, 11:15 PM
I connect my bot through BNLS... Connects 3RAW on just fine and dandy, but I do NOT recieve my clan's list in 0x65/0x7D.

0x65 requests friends list, and server sends it back with friends list and each friends current info.
0x66 - a friend update, such as joining/exiting Battle.net.
0x67 - friend added to friends' list
0x68 - friend removed
0x69 - promoted/demoted

I only havn't fully supported those yet, so I'm not going to give any information on it (I could be wrong on some info)

As for clan packets, all i know of is 0x72 is you have been invited to a clan.
:)
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on September 30, 2003, 05:12 PM
Okay, so what do I send in 0x65?

I'm confused because my packet logger cant packet log war3 :-P I'm using WPE Pro ALpha.

I also have ethreal but I dont have a clue what to put in the "Interface" box.

They should have these packets in bnetdocs :D
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on September 30, 2003, 06:16 PM
Thanks!
Title: Re:A question about the Warcraft III Clan System
Post by: iago on September 30, 2003, 06:27 PM
Quote from: Arthas on September 30, 2003, 05:12 PM
Okay, so what do I send in 0x65?

I'm confused because my packet logger cant packet log war3 :-P I'm using WPE Pro ALpha.

I also have ethreal but I dont have a clue what to put in the "Interface" box.

They should have these packets in bnetdocs :D

If you have a NIC card, interface will be autofilled, just select your card.

Otherwise, I don't think you can use ethereal.
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on September 30, 2003, 06:54 PM
K, my question is yet to be answered, what do I send to recieve my clan list?
Title: Re:A question about the Warcraft III Clan System
Post by: Spht on September 30, 2003, 07:39 PM
Quote from: Arthas on September 30, 2003, 05:12 PM
Okay, so what do I send in 0x65?

0x65 has no content.

Quote from: Arthas on September 30, 2003, 06:54 PM
K, my question is yet to be answered, what do I send to recieve my clan list?

Send 0x7d to request your clan's member list. The format is basic for this one: it is one DWORD which is the "cookie" (query value). The server's response is pretty straight forward.
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on September 30, 2003, 07:45 PM
Cookie? Query value?

You mean what I recieve in 0x75?... Right?
Title: Re:A question about the Warcraft III Clan System
Post by: Spht on September 30, 2003, 07:46 PM
Quote from: Arthas on September 30, 2003, 07:45 PM
Cookie? Query value?

You mean what I recieve in 0x75?... Right?

Huh? I already told you about 0x75 - read up.
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on September 30, 2003, 07:50 PM
Yes, sorry, but what do you mean by Query Value?
Title: Re:A question about the Warcraft III Clan System
Post by: Spht on September 30, 2003, 07:55 PM
Quote from: Arthas on September 30, 2003, 07:50 PM
Yes, sorry, but what do you mean by Query Value?

Any unique value chosen by you which you can assign to requests so that you can identify them when they are received (since there is no promise that you'll get them in the order you requested them).

If you are only going to request member list once, it may not matter what you use as your query value.
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on September 30, 2003, 08:06 PM
Quote from: Spht on September 30, 2003, 07:55 PM
Any unique value chosen by you which you can assign to requests so that you can identify them when they are received (since there is no promise that you'll get them in the order you requested them).

If you are only going to request member list once, it may not matter what you use as your query value.

Okay, so I can insert any dword I want? EG: InsertDWORD 615
Nevertheless, I dont get a response from BNet when I send that.
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on September 30, 2003, 09:41 PM
Here is what I send... yet I get no reply. This is right after I send 0x46 btw.


               pBuffer.InsertDWORD 41
               pBuffer.SendPacket sckBnet, &H7D


I got it working once before using that code, but it all of a sudden just stopped sending me it... o_O I'm confused.
Title: Re:A question about the Warcraft III Clan System
Post by: Stealth on September 30, 2003, 10:00 PM

pBuffer.InsertDWORD &H1
pBuffer.SendPacket &H7D


I'm using a value of 1 based off of a packetlog I ran at one point, it's been working great. Could the server be ignoring your request because your cookie isn't.. right somehow? Try sending 1.
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on September 30, 2003, 10:18 PM
Thanks stealth, but this is really *FUCKED* up now. Pardon my language...

Here's the scoop, now my Select Case PacketID isnt recognizing the packet unless I get a msgbox to show me the packetid's.

Here's the code:

Where PacketID = Asc(Mid(data, 2, 1))

Working:(Uncommented MsgBox)

   MsgBox hex(PacketID)
   
   Select Case PacketID
       Case &H0


Not working:(Commented MsgBox)

   'MsgBox hex(PacketID)
   
   Select Case PacketID
       Case &H0


Help. O_O
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on September 30, 2003, 10:50 PM
It's as if I need a little delay somewhere... Though BNet still sends me the packet my bot wont recieve it.
Title: Re:A question about the Warcraft III Clan System
Post by: SiMi on October 01, 2003, 12:07 AM
Maybe some of the data recived from the winsock_dataarrival got filtered out through that sub? Best of all; try debugging!

Quote from: Arthas on September 30, 2003, 10:50 PM
It's as if I need a little delay somewhere... Though BNet still sends me the packet my bot wont recieve it.
How would you know if bnet sends you the packet if you dont get it?  :-X
Title: Re:A question about the Warcraft III Clan System
Post by: Zakath on October 01, 2003, 12:24 AM
Quote from: Simi on October 01, 2003, 12:07 AM
How would you know if bnet sends you the packet if you dont get it?

A packet log, of course. You mean to tell me you've never used one in the process of writing a bot? I used mine all the time when I was first getting my packet handling set up, plus I needed it quite a bit when I was first adding support for D2 realms.
Title: Re:A question about the Warcraft III Clan System
Post by: Spht on October 01, 2003, 09:02 AM
Quote from: St0rm.iD on October 01, 2003, 05:55 AM
Quote from: iago on September 30, 2003, 07:34 PM
Quote from: St0rm.iD on September 30, 2003, 06:33 PM
WHAT THE FUCK WHY WAS MY POST DELETED

It was oviously useless or offtopic, much like that one.  I would suggest also deleting that one and mine.

No, it was a link to wiki.ik0ns.com, with documentation for the packets he was inquiring about.

Maybe next time you should copy the necessary content into your post as a formulated answer, instead of just pasting a link to another server.
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on October 01, 2003, 05:03 PM
Here here Zakath, WPE has been my best friend ;D

Anyways, I'm still stuck. It seems I have to pause for a while when recieving 0x46(BNet News Packet) in order to "recieve" 0x7d. I've looked at my recieve 0x46 code, and there's nothing up that would trigger a sudden loss of packet recieving. Though there is a loop in my recieve 0x46 code, maybe that would do it?
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on October 01, 2003, 06:10 PM
Nvm...... My entire program just needs to pause for some retarded reason.
Title: Re:A question about the Warcraft III Clan System
Post by: SiMi on October 01, 2003, 08:47 PM
Quote from: Zakath on October 01, 2003, 12:24 AM
Quote from: Simi on October 01, 2003, 12:07 AM
How would you know if bnet sends you the packet if you dont get it?

A packet log, of course. You mean to tell me you've never used one in the process of writing a bot? I used mine all the time when I was first getting my packet handling set up, plus I needed it quite a bit when I was first adding support for D2 realms.
No, thats not what i meant.... I meant if bnet sends the packet but you never get it on your client (they sent it but you never got it).
Title: Re:A question about the Warcraft III Clan System
Post by: UserLoser on October 02, 2003, 03:40 PM
This would be helpful in your case: DebugOutput (http://botdev.valhallalegends.com/documents/vbdebugoutput.html) by Grok
Title: Re:A question about the Warcraft III Clan System
Post by: Arta on October 02, 2003, 07:19 PM
Quote from: Simi on October 01, 2003, 08:47 PM
Quote from: Zakath on October 01, 2003, 12:24 AM
Quote from: Simi on October 01, 2003, 12:07 AM
How would you know if bnet sends you the packet if you dont get it?

A packet log, of course. You mean to tell me you've never used one in the process of writing a bot? I used mine all the time when I was first getting my packet handling set up, plus I needed it quite a bit when I was first adding support for D2 realms.
No, thats not what i meant.... I meant if bnet sends the packet but you never get it on your client (they sent it but you never got it).

That would never happen. If it does, it's your program's fault. TCP/IP guarantees delivery.
Title: Re:A question about the Warcraft III Clan System
Post by: MyndFyre on October 02, 2003, 08:14 PM
Something that happened to me (that might be happening to you), which could explain that sometimes you get a packet and sometimes you don't, is that bnet is lumping more than one packet into a single Send() call.

So if you're getting a load of data from the server, make sure the data length is equivalent to the packet length.  IF NOT - copy the data from data(packetLength) to data(receivedDataLength) into a new array and parse THAT.  Then repeat.  Careful - this can emulate a directly recursive method depending on how you implemented it (mine was not implemented such that it would be recursive, but it still entered an endless loop.

As Arta pointed out, TCP/IP is a reliable transport service - if a packet fails to send, the sender is notified (I think that's called a NACK) and the packet is re-sent.  A failed packet is not reported to your program.
Title: Re:A question about the Warcraft III Clan System
Post by: Adron on October 02, 2003, 08:22 PM
Note that you'll get a half packet too.
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on October 03, 2003, 12:59 AM
The case: If I dont pause, my bot dosnt recieve the packet. I packet logged 5 times to be certain, and when my bot dosnt recieve the packet... The packet is still packaged into it's own independant packet and sent to ME because my computer picks it up. I use WPE, I target my bot, packet log, the packet logger catches the packet, yet my bot dosnt.

If I pause however... I ALWAYS catch the packet. I'm going to try this Debug Output thing. Thanks for the help, but I'd appreciate some more:)
Title: Re:A question about the Warcraft III Clan System
Post by: Banana fanna fo fanna on October 04, 2003, 05:31 PM
Sounds like a race condition to me.
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on October 04, 2003, 11:49 PM
Race condition? BTW, DebugOutput didnt do anything for me
Title: Re:A question about the Warcraft III Clan System
Post by: UserLoser on October 04, 2003, 11:55 PM
Quote from: Arthas on October 04, 2003, 11:49 PM
Race condition? BTW, DebugOutput didnt do anything for me

If you just put that on your DataArrival/Recieve, you won't need a packet logger, and you'll see all incoming data to your bot
Title: Re:A question about the Warcraft III Clan System
Post by: Adron on October 05, 2003, 06:50 AM
If it's that function grok or someone posted, you'll have to print it too. It's really just bin2hexdump.
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on October 05, 2003, 03:40 PM
I fixed it, I found out wtf was going on.....................

Thanks for the help all, but I once again, am full of questions!

BNet splits a packet in 2 if it is to big, eg, a clan packet. How do I merge the two together?
Title: Re:A question about the Warcraft III Clan System
Post by: Soul Taker on October 05, 2003, 03:44 PM
http://forum.valhallalegends.com/phpbbs/index.php?board=17;action=display;threadid=2912;start=0 (http://forum.valhallalegends.com/phpbbs/index.php?board=17;action=display;threadid=2912;start=0)
Believe that kinda thing was discussed there.
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on October 05, 2003, 05:43 PM
Still, I'm stumped as to WHY I'd have to pause my entire program for the packets to merge by themselves... o_O
Title: Re:A question about the Warcraft III Clan System
Post by: Zakath on October 05, 2003, 06:02 PM
When a Windows socket receives data, it's placed into an internal buffer. When you (or the built-in Winsock controller VB uses) issue a recv call on the socket, whatever data is there is copied into the buffer you supply (so you can manipulate it). If you always call recv the instant new data arrives, you'll always receive packets that get cut into pieces as they are: in pieces. By sleeping, I would guess you're causing your program to wait long enough before issuing the recv that both halves of the packet are received and buffered internally, so then the subsequent call can grab the whole packet at once.

However, you generally do want to issue recv as soon as data is received, so...you need to add support for constructing packets when they get split in pieces. :)
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on October 05, 2003, 09:39 PM
Call me a newb, but this works quite well...

In my Data Arrival function:

       lngLen = Val("&H" & StrToHex(StrReverse(Mid(strBuffer, 3, 2))))
       If Not Mid(StrToHex(strBuffer), 1, 2) = "FF" Then
           strBuffer = p1 + strBuffer
           p1 = ""
           Parse (Left(strBuffer, lngLen))
       End If
       
       If Len(strBuffer) < lngLen Then
           p1 = strBuffer
           Exit Sub
       End If


It just waits until I recieve the last parts of the packet, then constructs them, think that should do the trick for everything I'll encounter regarding Bnet?
Title: Re:A question about the Warcraft III Clan System
Post by: Arta on October 05, 2003, 10:00 PM
No. I'm not a VB programmer but if I understand your post properly, it's demonstrating a fundamental lack of understanding about data, how it's stored, represented and used - you should read up on it. For example, the first line looks like it's taking the (numeric) length field of a packet, converting it into a string, concatenating it with "&H", and converting it back into a number - that's silly. Perhaps you're suffering from a common misconception: data is not sent as 'hex'. Data is just that - data - a bunch of bytes. Hex (Or more rightly, hexadecimal) is just a way of formatting that data to make it easier to read. Converting a length field - or any other numeric field - to it's hex representation and then back to a number is silly because the data is already a number to begin with.

Checking to see if the first byte of the buffer is FF is a good idea, and something that most people do, but your code here doesn't look very robust. What happens when new data arrives if the buffer contains a half-packet? Is it put onto the end of the buffer? If so, where are you storing the length of the buffer? How are you updating the buffer after you process a packet so that the packet you dealt with is removed properly? What happens when you get two packets in one go? Will it process the first one and then ignore the second? Without seeing the rest of your code I can't tell but there are probably quite a few improvements you could make.


HTH.
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on October 05, 2003, 11:47 PM
How do I get bytes from a string?

EG: ÿh to bytes

I always dealt with my common misconception as fact for my bot, though now this should help me much if you could tell me...
Title: Re:A question about the Warcraft III Clan System
Post by: Arta on October 06, 2003, 06:52 AM
They're bytes already. AFAIK, you can just use Mid() to extract a string. I don't know about numbers - As I said, I'm not a VB programmer. If no one who is feels like replying on this thread, I'd suggest finding an open source packet buffer (I think BotDev (http://botdev.valhallalegends.com) has one). You should be able to read through the source and figure out what functions like GetDWORD() (or equivalent) do. Incidentally, it's a great deal easier, in my experience, to use a packet class that provides easy methods for retrieving data from packets. It simplifies your packet processing functions and makes your code much more readable.

If you find something in there you can't make sense of, post it here and I'll do my best to help.
Title: Re:A question about the Warcraft III Clan System
Post by: Soul Taker on October 06, 2003, 07:53 AM
I use CopyMemory to change such things to a long (check MSDN).
Title: Re:A question about the Warcraft III Clan System
Post by: Adron on October 06, 2003, 11:21 AM
Quote from: Arta[vL] on October 06, 2003, 06:52 AM
They're bytes already. AFAIK, you can just use Mid() to extract a string. I don't know about numbers - As I said, I'm not a VB programmer. If no one who is feels like replying on this thread, I'd suggest finding an open source packet buffer (I think BotDev (http://botdev.valhallalegends.com) has one). You should be able to read through the source and figure out what functions like GetDWORD() (or equivalent) do. Incidentally, it's a great deal easier, in my experience, to use a packet class that provides easy methods for retrieving data from packets. It simplifies your packet processing functions and makes your code much more readable.

If you find something in there you can't make sense of, post it here and I'll do my best to help.


Typically, the GetDWORD function will do pretty much what he did. Could also turn his


lngLen = Val("&H" & StrToHex(StrReverse(Mid(strBuffer, 3, 2))))


into


lngLen = Asc(Mid(strBuffer, 3, 1)) + Asc(Mid(strBuffer, 4, 1)) * 256

Title: Re:A question about the Warcraft III Clan System
Post by: Banana fanna fo fanna on October 06, 2003, 02:15 PM
Let me explain in pseudo:

Define two procedures:
on_data: called when raw data is received. This procedure should store it in a global/instance buffer. Basically, just append the data on the end of it. Then, call dispatch_message.

dispatch_message: this procedure is responsible for dispatching packets to their appropriate handler method. You should follow this algorithm:

1. If length of buffer is less than 4, return
2. If buffer doesn't start with 0xff, throw error
3. If we've made it to here, it looks like a complete battle.net packet header. Grab the 2nd byte in the buffer. We'll call it cmd
4. Convert the 3rd and 4th bytes in the buffer to a little-endian dword (n).
5. If length of buffer is less than n, return, we didn't get a full packet.
6. Otherwise, take the first n bytes from the front of the buffer (msg) and remove them from the buffer.
7. Using a select case/switch/cond/etc logic structure, decide what procedure should handle data for packet type cmd.
8. Pass msg to cmd
9. Go back to step one. You can use a goto, loop, or recursive call. Recursive call is easiest but does have a very very slight risk of a call stack overflow if someone spams the hell out of you

This could be optimized by saving the length of the buffer in a variable so we don't have to count it each time. Could also cache the 3rd and 4th byte dword.

I hope you enjoyed today's algorithm. Stay tuned.

Wait a minute, you probably didn't even read this post. Why did I even bother typing it?
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on October 06, 2003, 04:41 PM
Storm, I read it, and that helped a little bit, mostly on the edition of some new knowledge into my packet handling functions, thanks for that.

On a second note, my uber newbie skills pile up even more.

In the 0x68 packet(Remove Friend), it's just the index, my code works until it hits 10, which is all of a sudden "A", 11 "B", 12 "C", ect. I'm confused, should I make a function that turns A into 10, B into 12, C into 13, or is there a better way of going about this?

EG:

Index = Mid(data, len(data), 2)

Index can be anything in between 0 and 9, after that it starts to be letters(Last I checked letters weren't numbers...).

So, that's why I ask how do I change hex into bytes.

To my knowledge, 2 digits in hex = 1 byte. Now in 0x68, 0D isnt a number, though the index is still 13. You probably know all this and get the question anyways... Help! :)
Title: Re:A question about the Warcraft III Clan System
Post by: Skywing on October 06, 2003, 05:35 PM
Quote from: Arthas on October 06, 2003, 04:41 PM
Storm, I read it, and that helped a little bit, mostly on the edition of some new knowledge into my packet handling functions, thanks for that.

On a second note, my uber newbie skills pile up even more.

In the 0x68 packet(Remove Friend), it's just the index, my code works until it hits 10, which is all of a sudden "A", 11 "B", 12 "C", ect. I'm confused, should I make a function that turns A into 10, B into 12, C into 13, or is there a better way of going about this?

EG:

Index = Mid(data, len(data), 2)

Index can be anything in between 0 and 9, after that it starts to be letters(Last I checked letters weren't numbers...).

So, that's why I ask how do I change hex into bytes.

To my knowledge, 2 digits in hex = 1 byte. Now in 0x68, 0D isnt a number, though the index is still 13. You probably know all this and get the question anyways... Help! :)
What datatype is Index?
Title: Re:A question about the Warcraft III Clan System
Post by: Zakath on October 06, 2003, 05:43 PM
Yes, if it's a numerical type, most (all?) programming languages supply a means for dealing with hexadecimal numbers. For instance, in C and C++, adding "0x" to the front of the number prompts the compiler that it's in hex.
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on October 06, 2003, 05:45 PM
Quote from: Skywing on October 06, 2003, 05:35 PM
What datatype is Index?

Index is a byte, what exactly do you mean by datatype besides that?
Title: Re:A question about the Warcraft III Clan System
Post by: Skywing on October 06, 2003, 05:54 PM
Quote from: Arthas on October 06, 2003, 05:45 PM
Quote from: Skywing on October 06, 2003, 05:35 PM
What datatype is Index?

Index is a byte, what exactly do you mean by datatype besides that?
You are storing it in an integral type, then.  You can print it out using hex or decimal, but the internal representation (and thus the value) of the variable are independant of which base you use to display it.
Title: Re:A question about the Warcraft III Clan System
Post by: Arthas on October 06, 2003, 09:44 PM
Thanks, I got it all working right
Title: Re:A question about the Warcraft III Clan System
Post by: Kp on October 07, 2003, 10:55 AM
Quote from: Arthas on October 06, 2003, 04:41 PM
Storm, I read it
Someone actually took $t0rm's advice!  It's the end of the world!
Title: Re:A question about the Warcraft III Clan System
Post by: Banana fanna fo fanna on October 07, 2003, 02:20 PM
I think he was just saying that to prove he read my post, not neccessarily used it or anything.