How to Produce Dynamic Mulitplayer Games With PHP

It’s relatively easy to set up a Web-based massively multiplayer game (MMO), though realistically you probably won’t have more than a few hundred players. I’ve chosen World of Phaos (WoP), which you can access from the SourceForge.net, an excellent site for open source projects.

WoP is a PHP, MySQL game and can run on a shared server, VPS or dedicated server. Shared servers are cheaper and are just fine for most games, but will generally limit you to running PHP/MySQL and Linux Crontab, which is also handy for general maintenance. If you need more facilities, then you’ll have to look to a VPS or dedicated server.

WoP was developed by Zeke Walker. His code is under a General Public License (GPL), which means that if you develop anything from his work, you have to publish your source code. If you choose this route, check out GNU’s operation system for details.

Setup Your Tasks

For many Linux, Apache, MySQL and PHP (LAMP) applications, including games and WoP, the database has to be set up before it can be used. There may be SQL scripts provided to run this, or one may be embedded in PHP code. To start the process, you’ll usually have to modify a config file with the user, password, database, etc.

After downloading the game archive file and unzipping it into a folder, look for a readme.txt or instructions on how to install. If you’re lucky there will be an install.php. WoP has a friendly installation guide and a small text file in the /installation_help folder. It may be a bit baffling to someone with little or no MySQL or PHP experience but this will eventually boil down to your creating the database.

The admin Web interface on the shared server that I use is called cPanel (another popular one is Plesk). I prefer it because it’s easy to use and makes managing the website relatively simple. If you are a Linux Guru then you probably don’t need the assist, but the rest of us do! My cPanel has neat features like optimizing website (which means everything that’s sent out is gzipped), plus anti-spam if you want to use the email component.

In shared servers, you’re often given access to a local SQL Web client such as phpMyAdmin and you can use it to access, modify  and insert, edit or view table contents on the database. If you’re unable to, then you can most likely configure the MySQL server for remote access by providing your IP. Once again cPanel is a good bet, as it configures remote access. It also allows a wild card address for your home, or work IP address. Unfortunately, one of the drawbacks to open MySQL ports includes being scanned by hackers’ scripts. You may want to avoid the wildcard IP and either use your IP address, or nothing at all.

If your database is setup by a PHP script then you should upload all the PHP to the server first. FTP is the normal method to upload files. To make it even easier, use WordPress; it downloads zip files and then unzips itself.

With WoP, the MySQL settings are in a file called config_settings.php. That means you have to create a user, then add them to the database and put the login details in the PHP file. Once again, cPanel has the one-step remedy, providing a page to create the database, add users, etc. If you’re not using cPanel, you’ll have to brush up on MySQL and run the commands in phpMyAdmin, or whatever remote client you use.

I usually add two users. One is for my admin and has a name like claque_sa.  On my shared server with a domain like claque, all databases and users that I create are prefixed by claque_. This admin login is given a very secure password, full capabilities and is the one I use remotely. The game user claque_usr is only allowed to run insert, delete, update and select SQL statements.

After creating the users, I use phpMyAdmin to run structures.sql. You’ll find it in the import folder. This task created the 34 tables I use in the game. The last step is the slightly tedious job of running the 18 SQL files (data_1.sql, data_2.sql up to data_18.sql) in order to populate the game tables. Once that’s done, you should be ready to roll.

Related Links

Comments

  1. Pingback: 4 Things Making Life Easier for PHP Developers - Dice News

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>