Valhalla Legends Forums Archive | Battle.net Bot Development | Battle.net For Dummies

AuthorMessageTime
shadypalm88
This is a conversation I started with a friend of mine who wanted to learn more about Battle.net programming.  I'll post it here in case someone wants to see if I'm oversimplifying and giving false information, or if someone else might possibly get use of it.  :P

[color=lime]Eric[/color]: just what do you know about sending data across the Internet?
[color=cyan]Gabe[/color]: you send and receive packets
[color=cyan]Gabe[/color]: it's like talking
[color=cyan]Gabe[/color]: packets contain information in them
[color=cyan]Gabe[/color]: maybe you would be better off to ask me specific questions.. i probably know more
[color=lime]Eric[/color]: no that's really good enough
[color=lime]Eric[/color]: ok
[color=lime]Eric[/color]: right then
[color=lime]Eric[/color]: yeah, talking is actually a good metaphor
[color=lime]Eric[/color]: I'll try that for a while
[color=lime]Eric[/color]: network programming is based on layers
[color=lime]Eric[/color]: really there are only two that you need to know about, unless you're writing an operating system
[color=lime]Eric[/color]: the application layer
[color=lime]Eric[/color]: and the "shit I don't need to really understand" layer
[color=cyan]Gabe[/color]: do you understand that layer?
[color=lime]Eric[/color]: really there are more layers, I understand parts of some
[color=lime]Eric[/color]: the voodoo layer
[color=lime]Eric[/color]: is like
[color=lime]Eric[/color]: your ears and vocal cords
[color=lime]Eric[/color]: really this includes your network card and the basic Internet protocols (TCP, UDP, IP) that carry your message across
[color=lime]Eric[/color]: you don't need to know how they work in order to use them
[color=cyan]Gabe[/color]: yeh
[color=lime]Eric[/color]: the application layer, then
[color=lime]Eric[/color]: would be human languages
[color=lime]Eric[/color]: it's this that actually carries your message
[color=lime]Eric[/color]: your data
[color=cyan]Gabe[/color]: yeh
[color=lime]Eric[/color]: weirdly enough you can group the common human languages into two basic groups
[color=lime]Eric[/color]: European and Asian languages
[color=lime]Eric[/color]: I say weirdly because you can group protocols (app layer) into two basic groups too
[color=lime]Eric[/color]: text and binary
[color=lime]Eric[/color]: European languages are easy
[color=lime]Eric[/color]: you don't have to worry about your tone of voice when you say a word
[color=lime]Eric[/color]: and the writing system is very simple
[color=lime]Eric[/color]: 26 letters (in the Latin alphabet) and accent marks
[color=lime]Eric[/color]: even if you don't really know the language
[color=lime]Eric[/color]: if you know another European language
[color=lime]Eric[/color]: you can look at the words and kind of figure out how to say them
[color=lime]Eric[/color]: and some are cognates
[color=lime]Eric[/color]: like if you see the
[color=lime]Eric[/color]: French word
[color=lime]Eric[/color]: interresant
[color=lime]Eric[/color]: you can figure out that it means interesting
[color=lime]Eric[/color]: these are the text based protocols
[color=cyan]Gabe[/color]: binary however.. is difficult
[color=lime]Eric[/color]: here's a pretty basic HTTP request
[color=lime]Eric[/color]: GET /index.php HTTP/1.1
User-Agent: Mozilla Firefox
Host: www.bnetweb.com
[color=lime]Eric[/color]: you can figure out that this is getting the page index.php from www.bnetweb.com
[color=lime]Eric[/color]: and that I'm using Firefox
[color=lime]Eric[/color]: the response, and the boundary between HTTP's talk and the actual page body
[color=lime]Eric[/color]: is also very easy to figure out
[color=lime]Eric[/color]: even if you've never worked with HTTP before
[color=lime]Eric[/color]: and I certainly didn't need to pull up
[color=lime]Eric[/color]: "HTTPDocs"
[color=lime]Eric[/color]: to come up with that example
[color=cyan]Gabe[/color]: lol
[color=lime]Eric[/color]: just like I don't need a dictionary at all times to speak English or French
[color=lime]Eric[/color]: now those Asian languages on the other hand
[color=lime]Eric[/color]: say, Mandarin
[color=lime]Eric[/color]: many rants have been written about why they suck
[color=lime]Eric[/color]: in both the traditional (hong kong, taiwan) and simplified (mainland China) chinese writing systems
[color=lime]Eric[/color]: every goddamn word has its own symbol
[color=lime]Eric[/color]: worse, there is really no good connection between
[color=lime]Eric[/color]: the symbol
[color=lime]Eric[/color]: and how the word is actually pronounced
[color=lime]Eric[/color]: even native speakers will sometimes completely forget how to write a fairly common word
[color=lime]Eric[/color]: like knee
[color=lime]Eric[/color]: it's crazy and I'm never going anywhere near it... I value my sanity too much
[color=lime]Eric[/color]: these kind of equate to binary protocols
[color=lime]Eric[/color]: first of all you can't read them directly at all
[color=lime]Eric[/color]: you need to use a hex dump
[color=lime]Eric[/color]: the meaning of the packets aren't obvious just by looking at it
[color=lime]Eric[/color]: I mean, FF 50 24 00 ...
[color=lime]Eric[/color]: what the fuck is that?!
[color=cyan]Gabe[/color]: yeh
[color=lime]Eric[/color]: Battle.net obviously is a binary protocl
[color=lime]Eric[/color]: luckily for you
[color=lime]Eric[/color]: the task of figuring out what FF 50 24 00 ... is
[color=lime]Eric[/color]: has already been done
[color=cyan]Gabe[/color]: how did they do that.. btw
[color=cyan]Gabe[/color]: just guess?
[color=cyan]Gabe[/color]: and keep guessing..
[color=lime]Eric[/color]: a combination of educated guesses
[color=lime]Eric[/color]: and disassembling the games
[color=lime]Eric[/color]: now
[color=lime]Eric[/color]: you could say that there's a kind of grammar
[color=lime]Eric[/color]: that applies to the messages used on battle.net
[color=lime]Eric[/color]: each packet is like a sentence
[color=cyan]Gabe[/color]: yeh
[color=lime]Eric[/color]: it expresses a complete thought
[color=lime]Eric[/color]: but it's a very limited and very rigid grammar
[color=lime]Eric[/color]: there are only certain sentences you can say that are valid
[color=lime]Eric[/color]: you have to have those parts of a sentence in exactly the same order
[color=lime]Eric[/color]: or Battle.net will tell you to fuck off
[color=cyan]Gabe[/color]: that would be
[color=lime]Eric[/color]: each sentence/packet starts the same way
[color=cyan]Gabe[/color]: the logon sequence
[color=cyan]Gabe[/color]: right?
[color=lime]Eric[/color]: nope
[color=lime]Eric[/color]: that's just the rule for each packet
[color=lime]Eric[/color]: no matter what
[color=cyan]Gabe[/color]: oh.. you mean which dword to send first
[color=lime]Eric[/color]: I'll get to the order they're said/sent in a bit
[color=cyan]Gabe[/color]: etc..?
[color=lime]Eric[/color]: yes
[color=cyan]Gabe[/color]: ok
[color=lime]Eric[/color]: now each sentence/packet starts the same way: with a header
[color=lime]Eric[/color]: first there's the byte 0xFF (255)
[color=lime]Eric[/color]: with a little stretch of the imagination
[color=lime]Eric[/color]: this is like a period/question mark/etc at the end of a sentence, only b.net puts it at the beginning
[color=lime]Eric[/color]: in English you need the period at the end to know where the sentence ends
[color=lime]Eric[/color]: but since you can only send certain packets of a rigid format to Battle.net
[color=lime]Eric[/color]: it's not necessary
[color=lime]Eric[/color]: the end is self-evident
[color=lime]Eric[/color]: this is a double-check
[color=lime]Eric[/color]: if where battle.net expects a new packet to start
[color=lime]Eric[/color]: the next byte is _not_ 0xFF
[color=lime]Eric[/color]: it knows that something got messed up somewhere
[color=lime]Eric[/color]: and it should bail out
[color=lime]Eric[/color]: make sense?
[color=cyan]Gabe[/color]: yes
[color=lime]Eric[/color]: ok
[color=lime]Eric[/color]: the next byte is the packet ID
[color=lime]Eric[/color]: it identifies what this sentence is
[color=lime]Eric[/color]: whether it's going to say
[color=lime]Eric[/color]: "here's my username and password"
[color=lime]Eric[/color]: or "here's a message I'm sending to people in my channel"
[color=lime]Eric[/color]: battle.net doesn't use grammar like an actual spoken language
[color=lime]Eric[/color]: or even like a text-based protocol
[color=lime]Eric[/color]: the ID is the only thing that explains to the server and the client
[color=lime]Eric[/color]: how the rest of the packet (the "payload") should be interpreted
[color=lime]Eric[/color]: ok?
[color=cyan]Gabe[/color]: yeh
[color=lime]Eric[/color]: the ID is followed by the length of the packet
[color=lime]Eric[/color]: this is needed so that you can wait
[color=lime]Eric[/color]: until you've received the entire thing
[color=lime]Eric[/color]: before you start going through it
[color=lime]Eric[/color]: after that is the payload: whatever else this particular packet needs to contain
[color=lime]Eric[/color]: (which could be nothing at all)
[color=cyan]Gabe[/color]: yeh
[color=cyan]Gabe[/color]: that's what the Keepalive is
[color=cyan]Gabe[/color]: right?
[color=cyan]Gabe[/color]: null
[color=lime]Eric[/color]: yeah
[color=lime]Eric[/color]: that has an empty payload
[color=cyan]Gabe[/color]: it's just to tell them that you're still there
[color=lime]Eric[/color]: actually
[color=lime]Eric[/color]: SID_NULL (0x00) is for YOU to see if the SERVER is still there
[color=lime]Eric[/color]: if it fails to send, you know you've been disconnected
[color=lime]Eric[/color]: b.net servers totally ignore it
[color=cyan]Gabe[/color]: yeh
[color=lime]Eric[/color]: but anyway
[color=lime]Eric[/color]: there are certain types of information that get sent back and forth between your bot and Battle.net
[color=lime]Eric[/color]: and this is where the human language metaphor stops being relevant
[color=lime]Eric[/color]: basically there are numbers
[color=lime]Eric[/color]: and there are strings
[color=cyan]Gabe[/color]: numbers as in bytes and words and dwords
[color=cyan]Gabe[/color]: and all that good stuff
[color=lime]Eric[/color]: correct
[color=lime]Eric[/color]: b.net uses three different sizes of numbers at different types
[color=lime]Eric[/color]: either a single byte, or what people call a WORD (two bytes), or what people call a DWORD (four bytes)
[color=lime]Eric[/color]: (DWORD = Double word)
[color=cyan]Gabe[/color]: yeh
[color=cyan]Gabe[/color]: i remember that
[color=lime]Eric[/color]: this convention is adopted from how the Microsoft Windows API's refer to numbers of those sizes
[color=lime]Eric[/color]: as far as I know, they're not used much outside battle.net, so watch out
[color=lime]Eric[/color]: (the terms for them, not bytes/words/dwords themselves)
[color=lime]Eric[/color]: anyway
[color=lime]Eric[/color]: and then there are strings
[color=lime]Eric[/color]: (text)
[color=lime]Eric[/color]: the problem with sending text
[color=lime]Eric[/color]: (and admittedly it's a simple problem)
[color=lime]Eric[/color]: has to do with length
[color=lime]Eric[/color]: each byte, word, and dword takes up the same number of bytes
[color=lime]Eric[/color]: no matter what number they're holding
[color=lime]Eric[/color]: be it 12 or 12,345
[color=lime]Eric[/color]: but obviously
[color=lime]Eric[/color]: not all strings will
[color=lime]Eric[/color]: k?
[color=cyan]Gabe[/color]: yeh
[color=lime]Eric[/color]: the first common solution
[color=lime]Eric[/color]: is to include, say
[color=lime]Eric[/color]: a WORD
[color=lime]Eric[/color]: before each string
[color=lime]Eric[/color]: giving its length
[color=lime]Eric[/color]: the second is to use a null byte at the end of each string to indicate where the end is
[color=lime]Eric[/color]: (called a "null terminator")
[color=lime]Eric[/color]: b.net uses null terminators
[color=lime]Eric[/color]: you keep scanning through the payload until you hit a null byte
[color=lime]Eric[/color]: and when you do, you stop
[color=lime]Eric[/color]: that's all there is to it
[color=cyan]Gabe[/color]: yeh
[color=lime]Eric[/color]: now, your problem is that you wanted to write a packet buffer, and reader too, I think
[color=lime]Eric[/color]: although the real problem is actually that you need it done in Visual Basic 6
[color=cyan]Gabe[/color]: i have class at 5:45 :-\
[color=lime]Eric[/color]: well go to it
[color=lime]Eric[/color]: lol
[color=cyan]Gabe[/color]: i feel like skipping it lol
[color=cyan]Gabe[/color]: you're not in the moods to teach too often
[color=cyan]Gabe[/color]: :-P
[color=lime]Eric[/color]: lol
[color=lime]Eric[/color]: I'll finish this later
August 30, 2006, 9:44 PM
JoeTheOdd
Metaphors.. woah, headache.

Nice!
September 10, 2006, 8:56 PM

Search