Developing the Battle.net Emulator BNETD
Pages: 1, 2
Wen: What have you learned interesting technically about Battle.net through developing BNETD?
Crittenden: Fortunately for us, they have a pretty nice network protocol. It consists of a fixed-sized header that contains the command to execute and the length of the remaining data for that command. This makes it very easy to add new command support to the server; you just need to figure out what the command is trying to do (start game, list games, log in, etc.) and then code appropriately.
The protocol itself isn't encrypted at all, just individual packets within them (like a modified SHA-1 hash on the password). Just looking at a packet dump of a login provides great insight into how the protocol works -- it's fairly obvious.
Combs: The protocol wasn't designed to be portable from the beginning. The packet structures are all Intel-sized, packed, and little-endian. That's not exactly bad, but I really suspect they were just send()ing and recv()ing raw structures.
They also use things which we call "tags." They are a lot like the Macintosh resource types in that they appear to be strings, but they are always four characters and aren't NUL terminated. I suspect they are just constants stored in an integer since some compilers support an initialization syntax like:
int mytag = 'abcd';
/* equivalent to ('a'<<24) + ('b'<<16) + ('c'<<8) + ('d') */
Which is, of course, non-portable in several ways, and it ends up making the string look backwards if [you read it] a character at a time on little-endian systems. For example, the StarCraft client identifies itself as "RATS" ("STAR" backwards).
We also found several of the more mysterious values the client sends are just copies of values from Windows, specifically the 64-bit timestamps on files and the language/locale information.
Overcoming the Technical Difficulties
Wen: Describe the biggest technical challenges you have dealt with in developing BNETD.
Combs: The first big task was adding persistent storage for accounts. I wanted to make the storage easy to parse and edit with tools or by hand. I settled on a flat-file key, value format like such: "key"="value." Many people have criticized this decision (they would prefer a binary format and/or a database), but I believe it has been more beneficial than not.
64-bit timestamp values are used in several places. I had never seen them before, and I had a lot of difficulty writing a conversion routine that obtained the correct values down to the second. After writing a linear regression routine and feeding in a whole bunch of sample points (yes, I did need more than two since rounding was involved), I figured out the offset and slope.
Probably the most daunting task was figuring out any part of the protocol that involved encryption. Thankfully, the server works without supporting any of those packet types. But that meant going without passwords on the player accounts. Not having passwords was OK for LAN parties and systems behind firewalls, but some people wanted to allow logins from the Internet. Once we implemented account profiles, it became even more important so that players couldn't destroy each other's ratings.
Thankfully, the hash size was the same as SHA1 and [we were] sent an example hashing function. The hashed password was sent in the plain to the server where it was stored for later logins. We figured out that the login hash used the session key and a random value (actually a timestamp), plus that hashed password, and then hashed it again.
The server performs the same operation and compares the results. It's not the greatest scheme (knowledge of single-hashed password is the same value as knowing the password), but it was good enough for a game server. There was some further complication because the hash is performed in an endian-dependent way and it doesn't use the standard initialization or padding.
I spoke about the packet format a bit above. Even though it was very tempting to just import and export raw structures, we tried to do this in a portable way [and] mostly succeeded. I created a set of types and functions called bn_type which implements these:
- bn_byte = single byte
- bn_short = two bytes
- bn_int = four bytes
- bn_long = eight bytes
[These] are stored as arrays of unsigned chars as they would be seen "on the wire." However, we rely on the compiler not adding padding between these elements in the packet structures. We use gcc extensions to keep gcc from doing this, but everyone uses gcc. I don't know of any compiler that adds padding to arrays of unsigned chars, so we are safe until we run into that.
These types are used to build up structures which match the packets sent and received by the server. There is a union of all these packet types, and a character array which allows the network code to read and write them without conversion.
Crittenden: Their ladder support took quite a bit of time as well. They use an extended Elo rating system. This computes a probability to win, and then assigns points based upon that probability and the outcome of the game. The number of possible points decreases as a player advances. There are some pretty complicated formulas for calculating these probabilities, and as the number of players in a game increases, so does the complexity of the calculations. Ross worked a way to figure out the various permutations for 2-5 players, and we quickly added support for that.
While the packets are fairly straightforward, there were endian issues to deal with, and fetching the data out of the packet was a bit tricky. Ross devised a clever system of function calls to fetch 1, 2, 4 or 8 bytes of data from the "packet" at a time, which made programming much simpler. We built upon this base and made a bunch of "helper" functions to fetch string contacts, integers, whatever.
Wen: What other technical challenges do you anticipate will come up for BNETD?
Crittenden: It appears that Blizzard is actively patching their games to not work on non-Battle.net servers. This is really a shame, and I doubt there is much on the server side we can do to prevent this.
Combs: One area of BNETD which has never been completed is our server-interconnection protocol. This was originally designed to hook servers together into a kind of cluster. This is much more difficult to write than a stand-alone server, since it will involve locking and cache coherency. Currently, it allows sharing of games and channels, but there are some bugs.
I suspect Blizzard will be moving toward more encryption and more heavily involved servers. Currently, most of the logic is on the client side. Moving things to the server allows Blizzard more control over the environment.
Taking Legal Precautions
Wen: Do you have legal advice for others taking part in open source projects that deal with reverse engineering?
Combs: The current environment is not just the fault of special interests. We, the citizens of the U.S., have allowed it to get to this point. We should make an effort to stay informed and get involved. Anyone implementing a clone or work-alike should remember the DMCA. Try to think of every possible way that any interested party might claim you are bypassing copy or access controls. If there is any question, you should contact the EFF.
When reverse engineering, stick with 'exposed' interfaces and communications. If you decide you need to de-compile code or inspect others' implementations, it's best to talk with a lawyer so that proper 'clean room' techniques can be used.
Wen: What other important legal lessons can you share?
Combs: The first is to clearly and prominently state your goals and intentions on the front page of your site. Too many people made assumptions about our group. Most of the assumptions could have been easily dispelled. Let me list a few here: We are not a new group; we have been around since 1998. We do not encourage or condone piracy. [Editor's note: Unlike Battle.net, the BNETD server software does not check whether a game client connected to it is a legal or pirated copy.] We don't write hacks and/or cracks for use on our servers or on Battle.net. We don't modify any client-side executables or libraries.
Another lesson is to get legal advice sooner rather than later. I learned that the DMCA is more than a theoretical problem. While reading about Eric Corley, Dmitry Sklyarov, and others, I didn't realize that I might be in a similar situation someday.
Crittenden: We probably should have talked to a lawyer years ago to get an opinion on whether what we were doing was legal or not. I'm not sure how much it would have helped in this case. But it might have gotten us into a conversation with Blizzard much earlier, and perhaps in a less confrontational way.
Howard Wen is a freelance writer who has contributed frequently to O'Reilly Network and written for Salon.com, Playboy.com, and Wired, among others.
Return to the ONLamp.com.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 10 of 10.
-
More monopolistic trash....
2003-07-31 09:47:04 anonymous2 [Reply | View]
It's just Blizzard's pathetic attempt to hold a monopoly over online gaming services.
BnetD getting popular could potentially mean lots of players not on Battle.net.
Lots of users not on Battle.net might take Blizzard out of the #1 online game service spot.
They lose the #1 spot and their ad rates flop to nothing, and they lose a huge edge when releasing new games.
All in all, Battle.net is a SERVICE. Something Blizzard whines and cries about a lot - they want to make sure everyone understands Battle.net is NOT Blizzard and that it is a free SERVICE to Blizzard customers. I don't understand how it's legal for Blizzard to REQUIRE things that prevent fair and clear competition in a corporate environment. IE: They made the game to ensure consumers had NO CHOICE where to play. And they're going to use the DMCA and bogus copyright claims with regards to cd-key checks to protect those interests.
It's amazing to me. I really don't see how what BnetD did was illegal. I also don't understand how what Blizzard is doing could NOT be ILLegal.
-
If you don't do it, let someone else do it
2003-06-15 07:41:18 anonymous2 [Reply | View]
Blizzard don't have eny small server fort download that you can use on your private LAN and I think that they have por support for Local multiplayer in Diablo 2. When they don't have any server for download that you can use on your private LAN, so you can get better multiplayer support for Diablo 2 or have laddergames when when you are on a LAN that don't have any connection to the internet, then they should allow others to make. BnetD is on server that I give me some real multiplayer support when I am on a private LAN, and it tells me and my friends who really whas the winner after a few days when we have played Starcraft: Broodwar.
So I they don't give people a free saerver to play with on private LAN:s then they should allow other to make the server instead.
//Stiggan -
If you don't do it, let someone else do it
2003-07-30 21:21:48 anonymous2 [Reply | View]
I think you got what you deserve by getting sued you wrongfully took for granted that battle net was your personal playground and its not. you may have had good intentions but when you say stuff like needing a new place to play thats lag free well if there wasn't ppl like you creating game crashes on the server by hacking and probing around maybe it would run smothly. Actually i got no sympothy for this you are ovbiously well educated if you can hack into battle.net then that tells me you no right from wrong. If you where really concerned with the lag you would have built your own servers and offered to hoast for battle.net instead of stealing there technology out from under there feet.
Ive also played on Kali its free trial version time and i did not like the idear that you pay for a service that is low class and yet can play these games free by there providers your only benifit is a non ploiced realm meaning you can play modded games and that breaks the games copy rights. -
If you don't do it, let someone else do it
2003-10-03 18:15:59 anonymous2 [Reply | View]
You must have read worng, TCP dumping has nothing to do with hacking the server, you just watch what the server sends to your computer. No hacking involved.
I do it all the time, it does nothing to the server or you or other computers/clients.
--Get the facts strait before you post a message.
>Modulus
-
If you don't do it, let someone else do it
2003-06-15 07:41:04 anonymous2 [Reply | View]
Blizzard don't have eny small server fort download that you can use on your private LAN and I think that they have por support for Local multiplayer in Diablo 2. When they don't have any server for download that you can use on your private LAN, so you can get better multiplayer support for Diablo 2 or have laddergames when when you are on a LAN that don't have any connection to the internet, then they should allow others to make. BnetD is on server that I give me some real multiplayer support when I am on a private LAN, and it tells me and my friends who really whas the winner after a few days when we have played Starcraft: Broodwar.
So I they don't give people a free saerver to play with on private LAN:s then they should allow other to make the server instead.
//Stiggan
-
Blizzard can stuff it
2003-04-29 21:59:22 anonymous2 [Reply | View]
as the subject says, blizzard can stuff it. they should either welcome 3rd party servers or better them selves. "why better thy self when i can stomp the compeditor?" and all that, its just not right. honestly there is no real threat by you to blizzard, and you shudnt make one. so allow a few hundred ppl to get a lagless @$$holeless enviroment to play in.
-
Correction
2002-05-14 17:43:31 markb [Reply | View]
I would like to point out that Bnetd was *never* known as StarHack. It was called Bnetd since its inception, in April, 1998.
Mark Baysinger
-
BNETD is not the first nor only Battle.net emulator
2002-05-13 21:10:25 peter4jc [Reply | View]
What Blizzard is doing seems to me personally like a contradiction.
Because first, way back in Warcraft 2, they added support (by releasing a file) to their game to connect to Kali, the famous gaming network. Which does basically the same stuff BNETD only differently. You get on, find friends, and play a game. No CDKEY checking.
And now they sue these guys?
And lets not forget other Battle.net server emulators, like broodwar.com's emulator, FSGS, GameI, GamePDS amd GameBugs servers.
As a matter of fact, when you log onto Game-I, the very very first line that will popup on the secreen is:
Game-I Battle.net emulator.
Yes, emulator!
How come Blizzard only comes down on one group of people and not the rest around the world?
I dont know, but IMO, these guys are just coming down on them becase they get incredibly mad due to the fact that everyone got a taste of Warcraft 3 via BNETD. But it's not BNETD's fault, its the beta testers who willingly gave out pirated copies of the game.
So yes, I do believe that Blizzard is really trying to pull of something excessivly lame.







They want total control over the online gaming community so they can implement their own rules and regulations at a administrative level, and therefor, unquestionable.
At one point in time, there was a rumour that for any Battle.net user there would be a monthly fee attached. They are just preying on the fact there are legions of dedicated users who basically have electronic lives within Battle.net, whether they are gaming or not.
From my perspective as an accomplished C++/ASM programmer, Battle.net haven't really done that must of a fantastic job developing their server, and certainly a lower level of server maintainence.
An emulation of the server done by experienced programmers (Such as I beleive the BNETD crew are) will end up being just as good and no doubt better than the 'legit' Battle.net server.
Anyway, they're my thoughts.
Regards,
Matt,
ICE CASH/iTech - Programming Director