Thursday, October 16, 2008

My Journey Through Multiplayer Flash Game Development Land Part 1

And it begins.

For a semester-long independent-study project, I've decided to create an online, multiplayer, flash-based game. The original proposal is now on google docs; reading it will be helpful in understanding what the following posts are talking about. What I hope to collect here is a record of all the different components I've researched and the process I've gone through to progress on this relatively new endeavor. I've done a bunch of Flash programming before, but none involving network play. Another brand new challenge is the use of Flex. But more on that later...

Given that I've got a semester, I naturally went for a huge challenge (apparently, it's what I do). In addition to the large amount of original content that will need to be produced, this project also involves large technical components. In the original proposal, I broke the game down into the following components: backend database, player creation editing saving, main gameplay (composed of basic chess + additions and "encounter mode"), and online network play.

Knowing this, I began to research how to use Flash to access a database, since from the beginning I wanted player data to be centralized. My findings were that it can be tedious and slow (development-wise) using "vanilla flash". I thought for sure that I would be using the basic web design concept of throwing data at a URL (a php script) that would query the database, and send things back. The third to last tutorial on Ahmet Gyger's site was very helpful in demonstrating how this process would work. For basic data this would be fine, but imagine how difficult it would be to grab an array of results from a database, encode them in a URL, then decode them in Flash! Perhaps not difficult, but definitely tedious and probably involving custom classes built just for that.

The next possibility I found was actually two different instances of the same concept, with slightly different names: ASSQL and ASQL. These ActionScript libraries allow the use of SQL directly from ActionScript! This is similar to how asp.net works (and PHP), in that you set up a connection, and then run a query, not having to worry about how the query is sent, or how the connection is made. At last, my savior! Within a night of discovering ASQL (I found that one first), I had my Flash game connected to a remote mysql database, accepting user/password credentials, and loading up basic character data.

But it was not meant to be.

As I soon discovered, this method is not very secure, due to two problems. The first is that all the data is sent as clear text (and not encrypted using SSL). This isn't a huge issue for me, since I'm making this game as a learning experience, and I'm not that concerned about making it hacker-proof right now due to time constraints. The second is that if someone decompiles your swf file, all your SQL statements and login information are right there in plain text! 

Even this wasn't that big of a deal, but part of me said to myself, "If you're going to do it, you might as well do it well." So I began looking into SWF obfuscators. I found SWF Encrypt 5.0  and thought my troubles could be over.

If I were not making an online multiplayer game, I think this is the route I would have taken. However...

Soon after beginning my research into network Flash programming, I discovered that if I wanted to have the game be multiplayer, it would be best to program it from the perspective of a network game from the beginning. Originally, I thought creating a two-player game (on one computer) would be a good start, and then add network play later. I realized that there would be major code rewriting unless my focus was on network play immediately, especially if I was already planning on the data being database-driven.

Let the great socket server hunt begin!