- Title: Online games list
- Description: Avoids manually inserintg the ip address to connect client and host, by providing scripts to maintain an online available games list
- GM Version: GM 8 / GM 7
- Registered: Yes
- File Type: .gmk
- File Size: 1.3mb
- File Link: Download
This example provides a mix of php,mysql and gml that helps the developers of online games maintaining a list of available games waiting for players. The goal is to show to the player all the games he can join directly in game maker and avoid inserting manually the ip address to join them.
- Game Maker Pro
- The 39DLL Gex from bobistaken (any other version of the 39dll will do but you must update functions names in the gmk)
- A web space with php and mysql
HOW IT WORKS
In general the system is quite simple: you have a mysql database containing all the games information, game maker (using the 39DLL Gex) connects to some php pages on the server which extract or update the database data. The information required by the database is passed with a GET request to the php scripts.
The following php pages are provided with the example:
list.php: This page retrieves the list of available games, in textual format, with information divided by a separator character. It's up to the developer to split the resulting strings. If you access the page from a browser you can see the list in an html table.
insert.php: Allows to insert, update or keep alive a game in the server. It gets the game name and the player name as parameters. The IP of the host is kept in the database therefore calling this page when you already have a game results in updating it.
delete.php: Deletes a game from the server
config.php: Conrains the data needed to connect to the database
For security reasons, it's not possible to create more than a game per IP address.
First of all we need a table containing the games in the mysql database on the server. By default for this example you will need at least the following fields in a table called games:
ip (VARCHAR 255)
name (VARCHAR 255)
player (VARCHAR 255)
Edit locally the config.php file by adding the required information about your database like password, name, host etc... And upload the php files to the server
Open the example gmk and edit the create event of "controller_obj" by modifying the "host" variable. You need to insert the domain where you uploaded the php files (eg: "www.bestgameever.com")
Update the scripts get_list_scr, upload_scr, delete_scr. These files contain a line telling where the php files are stored in your server, edit this line to your needs (example: if you have list.php at www.bestgameever.com/game/list.php, you'll need to insert "/game/list.php")
When you create a game on the server, the date and the time is kept in the database. 15 seconds after the creation, the game will be deleted from the list (this is to remove inactive games not removed manually by the programmer). You are supposed to call upload_scr frequently to signal that your game is still alive and waiting for players (you can also change the name of the game in the process).
And that's it, I hope the example is clear enough, questions or suggestions are welcome.
Edited by Catan, 01 February 2010 - 06:20 PM.