Under the Hood: World of Warcraft – Logging In

Welcome to the first of many planned ‘Under the Hood’ articles. This article series will take you inside a program and explain how things work – and sometimes how to expand on them to add functionality to their existing code base.

This time, we’ll be looking at World of Warcraft version 2.4.3 (Which is far from the newest version, for obvious reasons). If you’re familiar with the game, you’re no doubt aware that it’s filled with playable elves, ogres, trolls, and even punt-able gnomes. What you may not know is what goes on behind the scenes during the process of logging on, selecting a realm to play on, creating a character, and finally logging on to that character to play the game.

World of Warcraft's Logon Screen

The first thing you see when you start the game is the log-on screen, so we’ll first examine that. This is referred to as a “GLUE Screen” in the code and MPQ files (MoPaQ – a custom archive format used by Blizzard in their games). As you may have noticed when starting the game, the background on the log-on screen is animated – this is because it’s a 3D model. For enUS, the file itself is located in “World of Warcraft\Data\enUS\expansion-locale-enUS.MPQ” under “Interface\GLUES\MODELS\UI_MainMenu_BurningCrusade\UI_MainMenu_BurningCrusade.m2” as referenced in the below lua code as ‘mdx’ – both of which are valid as far as World of Warcraft is concerned.

You’re probably fully aware that World of Warcraft utilizes lua, but what you may not know is the extent to which it utilizes it. All GUI interactions are handled by lua – including the login, take this code for example.

This code will execute when the ‘Login’ button is clicked. The important part of this code is the line with ‘DefaultServerLogin’ – this command is the code that will actually parse the login information and send it to the server. Before we continue I’d like to point out for those of you who are not familiar with implementing lua into a program, or have no programming experience at all – lua is basically just a set of callbacks, the underlying code for that is all in your main program. This means that while all GUI elements may be handled by lua, it all eventually goes back to Wow.exe.

I’ve taken the time to go through Wow.exe a little, and below is the assembly version of the DefaultServerLogin lua callback.

Below, I have roughly translated it into C.

The interesting thing to note about this code is that it only has one argument, not two like you may assume – but if you look further in the code you’ll see that the argument is being used in order to grab the account name and password (both to make sure they exist, and to grab their actual values), this argument could very well be ‘GUI’, or ‘form’. All the function ‘AttemptLogin’ does is make sure that the username and password both exist, and are not empty – it then will make all the letters of the username uppercase, and call ‘AttemptLogin2’. Now.. ‘AttemptLogin2’ is a little more complicated (and is also the core of the login, I’d say), so I enlisted the help of a de-compiler that put the resulting code in a C-like Pseudo-code.

The important part of this function begins at “if ( *(decorateAccountName + 40) )”, You can usually tell if a variable is a structure based on whether or not it’s dereferrenced after adding a value to it – this indicates that it’s accessing a sub-value of the structure, and since we do not know the structure format, we rely on how many bytes past the initial pointer it’s looking. One of the variables the client is able to set (or that the user can, if they launch the game with -console) is “decorateAccountName”, and while this seemingly does nothing to the user, it changes how the account name is presented in the actual protocol. Although it may seem backwards, when disabled it will append the users region to their account name – this region is highly based off the locale setting in your Config.wtf file which is located in “World of Warcraft\WTF\”.

After the client has finished preparing the login data to submit to the server, it’s finally able to send it – this is called the “Challenge”. To us, this would look like a ton of gobbledygook with our account name in it – The server however, parses each byte sent, analyzes the information, and if everything is successful will move on to the “Proofing” stage in which the login is finally validated. Below are the opcodes that you can receive during the login process.

  1. Success – You proceed to the realm selection screen.
  2. Unable to Connect – You receive a popup saying that you are Unable to connect.
  3. Account Closed – You receive a popup saying “This account has been closed and is no longer in service — Please check the registered email address of this account for further information.”
  4. No Account – Generally, you receive this when you entered the wrong account name or password.
  5. Account in use – World of Warcraft does not allow two people to play on the same account at once.
  6. Time limit – The server can disallow you to login for a period of time, this is what this opcode is for.
  7. Server full – We’ve all seen this horrible opcode far too often..
  8. Wrong Build Number – You receive a popup saying “Unable to validate game version. This may be caused by file corruption or the interference of another program.”
  9. Update Client – the server will initiate a patch download to update your client to the newest version.
  10. Account Frozen – for whatever reason (canceling your account, no money, etc), your account is not accessible right now.

If everything went well, you should now either proceed to the character selection screen, or the realm selection screen depending on whether or not you have a preferred realm set in your Config.wtf file.

I hope that was somewhat enlightening! I’m debating where to go next with this, it will either be the innards of the client itself, or how it communicates with the server as you chat, switch characters, die, etc. Where do you think I should take this?

2 Responses

  1. Randhil says:

    Great hammer of Thor, that is powruelfly helpful!

  2. Jiinx says:

    Nice article!

    I would say the innards of the client before “how it communicates” so we can understand what its trying to do 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.