Setting Up a Web Game: Part 2

Webgame screenshotThis is the second in a series about setting up an online multiplayer game called webgame, where I share my insights into architectural, business and technical decisions. You can read the first in the series at: The venture begins.

Share suggestions for game development in the comment sections below.

Technology Stack

This is the technology that powers the game. It’s an architecture which has three tiers.

  1. Front End- HTML5 JQuery/JavaScript/HTML/CSS/PHP.
  2. Database. I chose PostgreSQL but any database will do.
  3. Game Processing Engine. Written in C#.

Most php webgames only need the first two tiers, yet having a Game Processing Engine allows games to be much more complicated. I’m comfortable with C# but there’s no reason why Java wouldn’t do, or NodeJS (Server side JavaScript), Python, etc. You should use what you are comfortable with.

You can’t run your own software on a shared server since there’s too high a chance you’ll crash the server and many other websites. That’s why this game needs to run on a dedicated server or in my case a cheaper VPS (Virtual Private Server). A VPS looks like a dedicated server but is just part of a computer. They typically cost half the monthly rental fee of a dedicated server.

The technologies chosen have the advantage that they can run on either Windows or Linux server. In my case the Windows 2008 R2 server hosting was cheaper than Linux (from the same company) but I’ve seen little technical difference between the two platforms otherwise.

Orders are entered on the website, stored in the database and periodically processed by the game engine that puts the results back in the database. It’s not real-time but it doesn’t need to be.

What is a Game Processing Engine?

Game servers (as in the software not the computer) that drive real-time games are sophicated and powerful programs that can deal with multiple clients at the same time. MMOs like Everqeest and World of Warcraft need those to work.

A Game Processing Engine (GPE) is a much simpler program that reads the data from the database, processes it and then updates the database. This program is run at regular intervals according to the game speed. The default I’ve chosen is two hours per turn so the engine runs once every two hours but it can be as short as one to five minutes for fast games. The time it takes to process a turn depends on the number of players. Good practice dictates that it should make a backup of the database before processing, in case anything goes wrong.

Running PHP on Windows?

Although PHP has been traditionally a Linux language, the VPS I use has Plesk to manage up to ten websites. Each can be configured to run ASP.NET, PHP or both on the same website. Not all versions of PHP are available but a recent upgrade added PHP 5.3.9 and that’s up to date. I could have used ASP.NET instead as the website server technology but I wanted the flexibility to switch to Linux VSP hosting, which is almost always just PHP.

The difference between PHP on Windows and Linux is really the difference between Microsoft’s IIS and Apache web servers. For example, there’s no .htaccess files with IIS, since these are an Apache feature. It’s a text file that provides local customizations such as search engine-friendly URLs. On Windows you have to configure PHP for SEO for friendly urls using an IIS feature called UrlRewrite.

To run a typical PHP script with a select query from a database and render a page on my VPS takes between 100 microseconds and 1 millisecond. This is dwarfed by the time needed to compress the page as it’s generated, send it to the browser and decompress it.

PostgreSQL? Why not use MySQL?

The VPS hosting came with a choice of both MySQL and SQL server databases as standard. However I ruled out SQL server as it wold prevent me moving to Linux and I’ve been wanting to try PostgreSQL for a while. There’s still a question mark over the open source future of MySQL after 2015 — Oracle has not revealed what will happen. Despite being older, more established and better featured, PostgreSQL has never had the success of MySQL, even though it’s just as powerful.

Multiple Databases v Multiple Tables?

A server like this can handle multiple games at the same time. Normally in games with many database tables, I’d create a separate database for each game and another database to manage player’s accounts. This allows one account with multiple games. In this game though there aren’t that many tables so it’s easier to add an extra column to every game table to hold the game number and everything in one database with one set of tables.

Game Workflow

Here’s the life-cycle of play.

  • Player visits site and joins up.
  • Player views the list of games waiting for enough players so they can begin. There can be up to ten games waiting to start. The list shows how many players each game has (6-50) and the game speed. If all ten slots aren’t full, then the player can start one of his own. Once a game is full, it can start. Everyone is emailed the game link.

Error checking

Any program should log any problems and the Processing Engine is no exception. It’s very important to keep customers informed of any downtime. If a turn can’t be processed then the website should be the first place to show an error message. You might also consider emailing every player to inform them and give them a link where they can check for news regarding when the game will be back. You should make this a site on a different server so if the entire server is down they can still see the status.

KPI should mean Keeping Players Informed as well as Key Performance Indicator!

Administration System

If you have more than a dozen players then you should invest the time to automate the management of the game. Functionality you might want to include:

  • Game Control. Stop/Start any game with messages. Update any game status.
  • Player Administration. Send message or even them suspend them, kick them out if they break the rules.
  • Player purge. With free games you will always get players who drop out. This can be a clear out their positions  to let someone else take over or automatically email them  a week after their last login. It’s not a bad idea to include a ‘On vacation flag’ so they can tell you when they’re away and not get kicked out.
  • Set a player up in a position.
  • View Player statistics

In the next episode I’ll look at setting up the game server.

Post a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>