GNET on your own server

Blitz3D Forums/Blitz3D Programming/GNET on your own server

JoshK(Posted 2005) [#1]
Anyone know how to make this work? I edited the bb file and uploaded gnet.php, but it fails to create a server.


SurreaL(Posted 2005) [#2]
Have you created a MySql database with the appropriate configuration for it?


JoshK(Posted 2005) [#3]
I don't know what that is.


KuRiX(Posted 2005) [#4]
Halo you need to create the mysql database that the php uses, and of course have the mysql installed in the server, to access it via php.

Look in the mysql_query statemente to know the database structure.

Any question, ask me!


jfk EO-11110(Posted 2005) [#5]
As far as I see there are the following fields required:

game
server
ip
t_time

in a table named "gnet_servers"

I guess they are all TEXT fields, but the t_time field that may be a DATETIME field.

But what the heck is "count(*)" ?

Of course, since you have the php file you can change this.

Halo - download EasyPHP and install it on a local machine, then copy the phpMyAdmin folder into the www folder, then run EasyPHP and browse to 127.0.0.1.

there must be a zillion of PHP and MySql Tutorials, byside the php.com and mysql.com references.


JoshK(Posted 2005) [#6]
You guys are talking another language.


jfk EO-11110(Posted 2005) [#7]
Well I have the gnet.php file that is part of the gnet_v1.zip right in front of me. MySql is a Database that can be contacted using some kind of a very limited Sythax. So you send a MySql Command String from within PHP, that is the webservers script language. Things like SELECT fieldname1,fieldname2, fieldname3... FROM tablename WHERE condition SORTING ORDER.

Halo, it's about time for PHP and MySql. It's cool. RTFM.


Techlord(Posted 2005) [#8]
halo,

If you dont have PHP and MySQL installed on your server, GNET will not work - period!

Note: this statement in the gnet.php module
//Assumes DB already open.


If you confirm you have PHP and MySQL installed on your server, then all you need to do is connect to the database from within the Gnet.php by adding the connect string.
$conn = mysql_connect('localhost','database_username','database_password') or die("Could not connect : " . mysql_error());

mysql_select_db("your_database") Or die("Could not select database");
which is called prior to
$res=mysql_query( "select game,server,ip from gnet_servers order by t_time desc" );


I have devised my own versions of gnet.


JoshK(Posted 2005) [#9]
I am running minibb, so I must have that.

What the hell are database_username and database_password?


Techlord(Posted 2005) [#10]
What the hell are database_username and database_password?
The username and password needed to open a connection to your database.


JoshK(Posted 2005) [#11]
How do you find them? Is it just your FTP login name?


Techlord(Posted 2005) [#12]
Are you hosting the server from your home or a service. If from a service, they should provided you with them or allowed you to select them when setting it up. If from your home, you can set it through whatever mysql managment client you use. I use MYSQL-Front which is no longer available for free.


JoshK(Posted 2005) [#13]
Okay, if I use the same username and password my forum is using, will it screw it up? I mean, is a 'database' something you have one of, or do I have to create a separate one.


Techlord(Posted 2005) [#14]
Assuming that username and password will give you access to the database, you will have to create a table with SQL. This is where the database management client comes into play. -OR- webbased management client provided by hosting service.

Heres the SQL I used to create a gnet_servers table
# MySQL-Front Dump 2.5
#
# Host: softbullets.no-ip.com   Database: gnet
# --------------------------------------------------------
# Server version 4.0.12-nt

USE gnet;


#
# Table structure for table 'gnet_servers'
#

DROP TABLE IF EXISTS `gnet_servers`;
CREATE TABLE `gnet_servers` (
  `id` tinyint(3) unsigned NOT NULL default '0',
  `t_time` timestamp(14) NOT NULL,
  `game` text,
  `server` text,
  `ip` text,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `id` (`id`)
) TYPE=MyISAM;



#
# Dumping data for table 'gnet_servers'
#



JoshK(Posted 2005) [#15]
Oh god.


I will email Ben.

Thanks anyways.


Techlord(Posted 2005) [#16]
Dont let the SQL scare ya, thats produced by the database management client. Anyways. If you ever connect to your database, the connection snippet above should do the trick.


RepeatUntil(Posted 2005) [#17]
While you are working on it, and as you want to put gnet on your server, then take the (free) version of gnet written by Surreal for BlitzPlay. It's solving the problem of the server which freezes for a second when refreshing gnet...


Warren(Posted 2005) [#18]
It's MySQL, it isn't rocket science. FFS...


JoshK(Posted 2005) [#19]
What does FFS mean?


{cYan|de}(Posted 2005) [#20]
hey NOOOOOOOOOB:P


KuRiX(Posted 2005) [#21]
SQL was originally developed by Oracle. It is a database language for querying, modifing, adding and consulting records.

If you do not know it then it is better to learn SQL first.

Count(*) tells you the number of total different records from the database. When you use a "Select" statement you use the fields you want to retrieve. For example Select name from clients will tell you the name of every client in the database.

"Select * from clients" will tell you every field of every client in the database.

"Select count(*) from clients" will tell you the number of total records.

"Select count(name) from clients" will tell you the total different names in database.

Hope it helps.


Jeroen(Posted 2005) [#22]
Hi Halo,

I recommend PHPMyAdmin, which is a set of PHP scripts that can run online. With this piece of software you can create, modify and maintain the MySQL databases/tables on your server.

MySQL reference can be found on www.mysql.org.


BlackJumper(Posted 2005) [#23]
Do you think that rocket scientists sit around mixing LOX balances and polishing launch gantries, saying "Geez, its only rocket science, it's not like it's Cartography Shop coding!"


JoshK(Posted 2005) [#24]
I found a thing my web host has, and it was actually pretty easy to create a new database, a new user, and grant permissions for the user to access the database.

database=leadwerk_gnet
user=leadwerk_gnet

Here is my connection code:
$conn = mysql_connect("localhost","leadwerk_gnet","<PASSWORD>") or die("Could not connect : " . mysql_error());
mysql_select_db("leadwerk_gnet") Or die("Could not select database");

The rest of the php file is unmodified.

I got past the 'could not connect' and 'could not select database' errors. But now I get this error:



Techlord(Posted 2005) [#25]
halo,

I'm at work. If you dont have the resolved later. I'll assist.


JoshK(Posted 2005) [#26]
Danke.


Warren(Posted 2005) [#27]
What does FFS mean?

Think back to any conversation you've had in the last week. I'm sure you've heard the full version several times.


Jeremy Alessi(Posted 2005) [#28]
Here's mine Halo ... works for me on the Leadfoot server ... Make sure you have phpMyAdmin and that the table is set up correctly. The t_time field must be of type datetime and the other fields should be varchars.

<?php

//Assumes DB already open.

function ping(){
	global $ip;

	echo "$ip\n";
	exit();
}

//return a list of all servers
function list_servers(){

	$res=mysql_query( "select game,server,ip from gnet_servers order by t_time desc" );
	while( $row=mysql_fetch_row($res) ){
		echo( "$row[0]\n" );
		echo( "$row[1]\n" );
		echo( "$row[2]\n" );
	}
	echo "\n";
	exit();
}

//add a server
function add_server(){
	global $ip,$game,$server;

	$err="ERROR\n";
	if( $game ){
		if( !$server ) $server="$game@$ip";
		$res=mysql_query( "select count(*) from gnet_servers where game='$game' and ip='$ip'" );
		$row=mysql_fetch_row( $res );
		if( $row[0]==0 ){
			mysql_query( "insert into gnet_servers (game,server,ip,t_time) values ('$game','$server','$ip',now())" );
			$err="OK\n";
		}
	}
	echo $err;
	exit();
}

//refresh a server
function ref_server(){
	global $ip,$game,$server;

	$err="ERROR\n";
	if( $game ){
		if( !$server ) $server="$game@$ip";
		$res=mysql_query( "select count(*) from gnet_servers where game='$game' and ip='$ip'" );
		$row=mysql_fetch_row( $res );
		if( $row[0]==1 ){
			mysql_query( "update gnet_servers set server='$server',t_time=now() where game='$game' and ip='$ip'" );
			$err="OK\n";
		}
	}
	echo $err;
	exit();
}

//remove a server
function rem_server(){
	global $ip,$game,$server;

	$err="ERROR\n";
	if( $game ){
		if( !$server ) $server="$game@$ip";
		$res=mysql_query( "select count(*) from gnet_servers where game='$game' and ip='$ip'" );
		$row=mysql_fetch_row( $res );
		if( $row[0]==1 ){
			mysql_query( "delete from gnet_servers where game='$game' and ip='$ip'" );
			$err="OK\n";
		}
	}
	echo $err;
	exit();
}


$link = mysql_connect("mysql.fatcow.com", "name", "password");

$db_selected = mysql_select_db("name", $link); 

//setup some useful globals
$ip=$_SERVER["REMOTE_ADDR"];
$opt=array_key_exists("opt",$_GET) ? $_GET["opt"] : "";
$game=array_key_exists("game",$_GET) ? $_GET["game"] : "";
$server=array_key_exists("server",$_GET) ? $_GET["server"] : "";

//delete 'old' servers
mysql_query( "delete from gnet_servers where time_to_sec(now())-time_to_sec(t_time)>300" );

//begin header...(not sure about the no-cache bit!)
header( "content-type: text/html\ncache-control: no-cache\n\n" );

switch( $opt ){
case "add":add_server();break;
case "ref":ref_server();break;
case "rem":rem_server();break;
case "list":list_servers();break;
case "ping":ping();break;
default:echo "ERROR\n";
}

exit();

?>



jfk EO-11110(Posted 2005) [#29]
KuRiX - thanks for the "count()" description. Never used this yet. But of course, while asking here I also could search for it at mysql.com :)

BTW. to create a new Database using SQL Commands you need Admin rights. Usually you don't have them unless you have a dedicated webserver or something. Sometimes you need to write a Mail to your Webspace provider and tell him to add the database. If the database is once added, most providers have PhpMyAdmin pre-installed, all you need to know is the username and password, usually given to you by the provider as well, sometimes the same as the FTP settings, sometimes not.


gameproducer(Posted 2005) [#30]
We are also using GNET... so if you need any help just ask :)


_PJ_(Posted 2005) [#31]
{ i need to use sql at work - i hate it. it's simple enough, but gets so annoying with all these outer joins and decodes for everything because all our data is in stupid reference numbers }


JoshK(Posted 2005) [#32]
Indiepath.J or Frank Taylor, are you guys on MSN?


Techlord(Posted 2005) [#33]
MSN: frankie_taylor@...


JoshK(Posted 2005) [#34]
Thanks Frank.


erbbysam(Posted 2005) [#35]
yaaaa thank you guys soooo much... I knew I had to get the server open instead of assume that it's open but I had no idea had to do it...Thanks!


Boiled Sweets(Posted 2005) [#36]
Federation of Funky Soulbrothers?
Filosofiska Fakulteternas Studentkår?

Ho hum


jfk EO-11110(Posted 2005) [#37]
fast food syndrom?

BTW RepeatUntil or Surreal - where can I get Surreals GNet modified version ?


jfk EO-11110(Posted 2005) [#38]
I have yet another GNET question:

I did some tests with the fpsnet example by jeremy.

Everything works nicely, but when a host quits and a client becomes the new host, I can no more login with further clients. Although the former client is now listed as a host, but the new client waits forever when I hit Enter to join the highlighted host. Is host-takeover supported at all?
thanks.

(BTW I am testing this with mutliple windows on one desktop)


jfk EO-11110(Posted 2005) [#39]
I can't believe nobody knows this.