• Welcome to Valhalla Legends Archive.
 

Battle.net For Dummies

Started by shadypalm88, August 30, 2006, 04:44 PM

Previous topic - Next topic

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

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

Joe[x86]

Metaphors.. woah, headache.

Nice!
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.