Jump to content


Photo
- - - - -

Online Games List


  • Please log in to reply
48 replies to this topic

#1 Catan

Catan

    GMC Member

  • GMC Member
  • 273 posts

Posted 26 January 2010 - 09:37 AM

  • 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.

Posted Image

REQUIREMENTS
- 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.


USAGE

1.
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)
last_update (DATETIME)

2.
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

3.
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")

4.
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")

IMPORTANT INFO!
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:06 PM.

  • 2

#2 bennelsey

bennelsey

    GMC Member

  • GMC Member
  • 24 posts

Posted 26 January 2010 - 11:30 PM

This is *almost* exactly what i was looking, for DAYS.
Im stuck with an old GM7 copy so i can't get it to GM8 for free ^^
  • 0

#3 Catan

Catan

    GMC Member

  • GMC Member
  • 273 posts

Posted 27 January 2010 - 07:59 AM

This is *almost* exactly what i was looking, for DAYS.
Im stuck with an old GM7 copy so i can't get it to GM8 for free ^^


Now in the zip you can find a GM7 version :ph34r:
  • 0

#4 Dylijn

Dylijn

    GMC Member

  • New Member
  • 553 posts

Posted 27 January 2010 - 12:04 PM

Looking good, cant download though cuz Im not at home :ph34r:
  • 0

#5 Tuz

Tuz

    GMC Member

  • New Member
  • 106 posts

Posted 27 January 2010 - 01:34 PM

Does this check if players can actually join to the server? I mean if the person who hosts server is behind firewall or router the server is not displayed in the server list...
  • 0

#6 Catan

Catan

    GMC Member

  • GMC Member
  • 273 posts

Posted 27 January 2010 - 02:06 PM

Does this check if players can actually join to the server? I mean if the person who hosts server is behind firewall or router the server is not displayed in the server list...


No it doesn't, if the host is behind firewall his game will still appear in the list but players won't be able to join. I think it's outside the scope of this example in any case

Edited by Catan, 27 January 2010 - 03:20 PM.

  • 0

#7 Koning Stoma

Koning Stoma

    GMC Member

  • New Member
  • 128 posts

Posted 27 January 2010 - 04:15 PM

When the server starts you can let it check if the required ports are open. When the ports are open you let it appear on the list, when the ports are closed you give a warning.

here are 2 scripts that make this possible

Edited by Koning Stoma, 27 January 2010 - 04:16 PM.

  • 0

#8 irish7

irish7

    GMC Member

  • New Member
  • 1 posts

Posted 28 January 2010 - 09:06 AM

Finally I got what I was looking for. tnx to you...
Ill try this one!
  • 0

#9 2DLuis

2DLuis

    Graphic Designer

  • GMC Member
  • 2504 posts
  • Version:GM8

Posted 29 January 2010 - 12:14 AM

This looks phenomenal, finally, a serverlist, which link is active!
Good MYSQL/PHP info included too, basic things :(

Nice clean GUI too!
  • 0

#10 ghkdudgk

ghkdudgk

    GMC Member

  • GMC Member
  • 111 posts
  • Version:Unknown

Posted 30 January 2010 - 06:22 AM

wow. nice example.

how would i separate the string that's returned from the php into separate strings consisting of the name, the ip, etc.
cause as far as i can see of the code, it returns 1 long string with name, player, and ip all in 1 string.
  • 0

#11 Catan

Catan

    GMC Member

  • GMC Member
  • 273 posts

Posted 30 January 2010 - 09:38 AM

wow. nice example.

how would i separate the string that's returned from the php into separate strings consisting of the name, the ip, etc.
cause as far as i can see of the code, it returns 1 long string with name, player, and ip all in 1 string.


I didn't separate the string for simplicity, but you can use one of the many scripts available on the forum or other websites. Here's one: http://www.gmlscript...pt/string_parse
  • 0

#12 PrimuS

PrimuS

    GMC Member

  • GMC Member
  • 101 posts
  • Version:GM8.1

Posted 21 February 2010 - 04:24 PM

Nice example. I was looking for something like that for about two years :)
But gives a PHP error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in list.php on line 8.
Here's lines 1-8 of list.php:
include('config.php');

	$query = "SELECT ip,name,player FROM games WHERE last_update >= NOW() - INTERVAL 15 SECOND"; 
	$result=mysql_query($query);

	if($_GET['ingame'] == '1') {
		while($row = mysql_fetch_array($result)){

BTW, host has PHP5 and MySQL Server v3.23.32.

Edited by PrimuS, 21 February 2010 - 04:31 PM.

  • 0

#13 Catan

Catan

    GMC Member

  • GMC Member
  • 273 posts

Posted 22 February 2010 - 07:02 AM

Nice example. I was looking for something like that for about two years :D
But gives a PHP error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in list.php on line 8.
Here's lines 1-8 of list.php:
include('config.php');

	$query = "SELECT ip,name,player FROM games WHERE last_update >= NOW() - INTERVAL 15 SECOND"; 
	$result=mysql_query($query);

	if($_GET['ingame'] == '1') {
		while($row = mysql_fetch_array($result)){

BTW, host has PHP5 and MySQL Server v3.23.32.


Your mysql version is very old, probably that's the source of your problem, or you have some problems connecting to the database.

Try modifying the query line like this: $result=mysql_query($query); or die(mysql_error());

and adding quotes to the table and fields like this: SELECT `ip`,`name`,`player` FROM `games` WHERE `last_update` >= NOW() - INTERVAL 15 SECOND
  • 0

#14 Invero

Invero

    GMC Member

  • GMC Member
  • 212 posts

Posted 23 February 2010 - 05:49 PM

I am using GM7 Pro And have GM8 Pro

Looks amazing but I am having trouble with it I installed in the .Gex from the link provided and I get this GM7 Error:
___________________________________________
COMPILATION ERROR in Script: get_list_scr
Error in code at line 1:
//Description: Gets the list of available games from the server//Arguments: nonevar sock_id,new_line,listening,headers,game;ds_list_cl
ear(games_list);sock_id = dll39_tcp_connect(host,80,0);if (!sock_id) { show_message("Impossibile connettersi al server"); exit;}dll39_set_format(sock_id,dll39_format_text,c
hr(13) + chr(10));new_line = chr(13) + chr(10);dll39_buffer_clear(0);//Edit the following line to reflect where your php file is on your serverdll39_write_chars("GET /gm/gameserver/list.php?ingame=1 HTTP/1.0" + new_line,0);dll39_write_chars("Host: " + host + new_line,0);dll39_message_send(sock_id,0,0,0); listening = true;while(listening) { dll39_message_receive(sock_id,0,0); headers = dll39_read_sep(" ",0); if(headers == "") { listening = false; break; }}dll39_set_format(sock_id,dll39_format_none,'');result = "";size = dll39_message_receive(sock_id,10000,0);while(true) { game = dll39_read_sep(chr(10),0); if(game == "") {break;} ds_list_add(games_list,string_replace_all(game,"|", " | "));}dll39_socket_close(sock_id);

at position 167: Unknown function or script: dll39_tcp_connect

-------------------------------------------------------------------------------

As for GM8 I am getting this Error:
___________________________________________
COMPILATION ERROR in Script: upload_scr
Error in code at line 17:
sock_id = dll39_tcp_connect(host,80,0);
^
at position 12: Unknown function or script: dll39_tcp_connect
  • 0

#15 Catan

Catan

    GMC Member

  • GMC Member
  • 273 posts

Posted 23 February 2010 - 09:24 PM

Have you activated the gex for the example gmk, after installing it? It may sound stupid but that's the only thing I can think of after seeing the error

Edited by Catan, 23 February 2010 - 09:24 PM.

  • 0

#16 nbeerbower

nbeerbower

    GMC Member

  • GMC Member
  • 467 posts

Posted 21 May 2010 - 02:25 AM

I know I'm digging things up here a little bit, but this is great!

I just got it working and hopefully it will make multiplayer on my games a lot more playable. Thanks a ton, man!
  • 0

#17 Noritox

Noritox

    GMC Member

  • GMC Member
  • 279 posts
  • Version:GM:Studio

Posted 21 May 2010 - 07:24 AM

Awesome, implemented it into my game and it works fine. Thanks for this! Do you have a logo I can put in my credits?
  • 0

#18 guppylover

guppylover

    GMC Member

  • New Member
  • 112 posts

Posted 21 May 2010 - 02:36 PM

i could kiss you oh wait i can :)
i was just about to start making somthing like this but youve save a few day's work thanks
cheers, thanks a bundle, you a legend, thank you from the bottom of my heart!!!!!!!!!!!!!!!
  • 0

#19 Noritox

Noritox

    GMC Member

  • GMC Member
  • 279 posts
  • Version:GM:Studio

Posted 21 May 2010 - 07:43 PM

Ah crap I thought I had it working, I'm a tad bit confused. What's the variable that holds the IP address?
  • 0

#20 guppylover

guppylover

    GMC Member

  • New Member
  • 112 posts

Posted 21 May 2010 - 08:39 PM

um im having probs it wont retrive any data!!!? waaaaaah
and to q above in the data base the php or gml?

Edited by guppylover, 21 May 2010 - 08:39 PM.

  • 0

#21 nbeerbower

nbeerbower

    GMC Member

  • GMC Member
  • 467 posts

Posted 21 May 2010 - 10:18 PM

@Noritox
Only one string is sent, you need to separate the IP from the rest of the string.
See: http://www.gmlscript...pt/string_parse

@guppylover
No errors? Navigate to the list.php's location and check. Make sure you have the table set up in your MySQL database too.
  • 0

#22 Noritox

Noritox

    GMC Member

  • GMC Member
  • 279 posts
  • Version:GM:Studio

Posted 21 May 2010 - 11:15 PM

Ah I see, thanks for the info that helps!
  • 0

#23 guppylover

guppylover

    GMC Member

  • New Member
  • 112 posts

Posted 22 May 2010 - 10:22 AM

i have data base up an location seems ok
it finds files it just dosn't use em
  • 0

#24 Catan

Catan

    GMC Member

  • GMC Member
  • 273 posts

Posted 22 May 2010 - 07:25 PM

i have data base up an location seems ok
it finds files it just dosn't use em

Can you be a little bit more specific? It's difficult to help you with so little information

Edited by Catan, 22 May 2010 - 07:25 PM.

  • 0

#25 guppylover

guppylover

    GMC Member

  • New Member
  • 112 posts

Posted 22 May 2010 - 07:37 PM

ill try it again just now
EDIT: got it working thanks
it was a host error i made it save whatever data it recived in a txt file and server was sending tracking data but disabled now

Edited by guppylover, 22 May 2010 - 08:14 PM.

  • 0

#26 Catan

Catan

    GMC Member

  • GMC Member
  • 273 posts

Posted 23 May 2010 - 08:08 PM

Awesome, implemented it into my game and it works fine. Thanks for this! Do you have a logo I can put in my credits?


You don't need to credit me for this, but it would be nice to know which games use it :) . Just drop me a note if you publish the complete game somewhere.
  • 0

#27 Jucarave

Jucarave

    GMC Member

  • GMC Member
  • 18 posts

Posted 24 May 2010 - 03:50 PM

Awesome, this is exactly what i was looking for.

Thanks.
  • 0

#28 Noritox

Noritox

    GMC Member

  • GMC Member
  • 279 posts
  • Version:GM:Studio

Posted 03 June 2010 - 12:19 AM

Could someone please explain how exactly I'm to implement the string_parse code?


Any info can help. If someone explains what to do, I'll post this example with the string_parse code added in this thread to help others :blink:

I've read everything i can read about lists, and I can't figure this thing out for some reason

Edited by Noritox, 04 June 2010 - 02:38 AM.

  • 0

#29 Catan

Catan

    GMC Member

  • GMC Member
  • 273 posts

Posted 04 June 2010 - 09:43 AM

Could someone please explain how exactly I'm to implement the string_parse code?

Any info can help. If someone explains what to do, I'll post this example with the string_parse code added in this thread to help others :wacko:

I've read everything i can read about lists, and I can't figure this thing out for some reason


You don't really need to program it yourself, there are a lot of ready to be used scripts on the net like this one http://www.gmlscript...pt/string_parse
  • 0

#30 Noritox

Noritox

    GMC Member

  • GMC Member
  • 279 posts
  • Version:GM:Studio

Posted 06 June 2010 - 01:39 AM

Right, but what exactly do I put in these fields?

string_parse(str,token,ignore_null)

I tried this, and it's not working
string_parse(ds_list_find_value(games_list,selected_game), "|", true);

Edited by Noritox, 06 June 2010 - 01:40 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users