Gnet alternative opinions

Blitz3D Forums/Blitz3D Programming/Gnet alternative opinions

RifRaf(Posted 2009) [#1]
Can I get some honest opinions on this. I didnt want to use Gnet because I really want servers running full speed without lag spikes contacting the gnet front end.

So what im doing is this. I have a php set up that server admins can load up and input the server name, ip, port, ect. When they submit that it adds the server to a list (plain text atm).

The client on startup (and if the user hits refresh) will download the list and display all the servers. The way im keeping the inactive servers off the list is this: I run a ping bot on my local machine that will download the list, and ping everyone on it every so often. if it cannot contact the server it modifies the list and reuploads it for the clients, if a server cannot be contacted for more than a few days its removed from the list permanently.(server admin can always resubmit the listing)

This prevents each server from having to contact a database, but still only lists the active servers for the client. I was thinking I would have the pingbot go through the list once every 20 minutes.

What do you think of this approach ? I am open for alternative ideas, or improvements to this one.

Thanks


Mahan(Posted 2009) [#2]
Just a little side thought about the pings (to see if servers are available): Note that many internet routers don't answer ping. (i.e. they are often configured that way by default in the internal firewall)

If you write the ping so that it's actually a special package that the game servers respond to with an ACK you achieve two things:
1) You know that the actual server software is running on the other end. (and not a router that happens to respond to ping)
2) The routers that happen to block ping, must either way be configured to "forward" packages or connections to the internal server from the outside (to be available online) and therefore will always respond to your "custom ping".

As usual I highly recommend Enet for the networking from Blitz* as I think that it's the best networking solution, but that is just my personal opinion :-)


RifRaf(Posted 2009) [#3]
Mahan,

Thats what I currently do, the ping is actually a packet, the server is set up to reply with current map and player information when it receives the special ping packet.

I've not used Enet before, I use BlitzPlay Pro right now.


GIB3D(Posted 2009) [#4]
Hey RifRaf, I incorporated eNet into BlitzPlay, http://www.blitzbasic.com/codearcs/codearcs.php?code=2586

I haven't coded it to work with the update of eNet (even though it still works) but it probably would just take a few seconds/minutes to do. Here's what you would need to change http://www.blitzbasic.com/Community/posts.php?topic=49076#987012


RifRaf(Posted 2009) [#5]
I saw that when you did it, grats on a job well done. But BplayPro has everything I need right now. I may look into other network libs when I move over to bmax, or perhaps just convert Bpplay Pro over to that as well , sure wouldnt be hard to do.


RepeatUntil(Posted 2009) [#6]
Can I get some honest opinions on this. I didnt want to use Gnet because I really want servers running full speed without lag spikes contacting the gnet front end.


RifRaf, ETNA was developped exactly in this idea: avoid lag when contacting the server (by mean of thread). And ETNA has a version of gnet which does exactly what you need. Get ETNA (free) from my sig. You can see the modified gnet directly from this link.


RifRaf(Posted 2009) [#7]
RepeatUntil,

Thanks, im afraid for this project im already up to my eyeballs in BlitzPlay Pro, sitting at about 25k lines of code that is deeply dependent on Bplay. Ill keep my eyes on ETNA for my next project though.

edit: hm I may have jumped the gun, I thought ETNA was a network comms lib. Ill look into it more, thanks!


RifRaf(Posted 2009) [#8]
I know nothing about php & mysql . Has anyone written up the steps to get gnet working on another site aside fom bb.com ?


Mahan(Posted 2009) [#9]
Yeah, I'm a bit curious about this too. I have installed mysql numerous times on both *nix and Windows, and I have gotten .PHP to run as a plugin in apache a few times.

Is this what is required to get ETNA running?


RepeatUntil(Posted 2009) [#10]
Yes, RifRaf, ETNA runs perfectly with BlitzPlay!!! This could be ran in parallel, no problem at all. I did that for my game in the past in Blitz3D.

To test gnet, there is 2 steps: first you use the server from blitzbasic.com to test that this is working. Use the example from the "Gnet" directory in Etna. Just run gnet_test.bb and that should work: check in the gnet tab on this site and you should see your "game".

Then the second step, if you need it (ie if you need an extended gnet with your own version), is to install the php and the mysql table on your own server. For this, use the files gnet.php and gnet.mysql (that you can find in the same directory in Etna) and install them on your server. I won't explain you how to create a mysql table, but really, this is very simple if you read help about this on the internet.

There is a little help on this page: http://repeatuntil.online.fr/Etna/Etna_lib.html

I hope it helps...


Mahan(Posted 2009) [#11]

I won't explain you how to create a mysql table, but really, this is very simple if you read help about this on the internet.



Agreed that simply creating a table in MySQL is trivial, but to have a working stack with Webserver, PHP (integrated in the webserver) and MySQL with all the small tweaking in configuration-files to make them working together takes some time if you aren't used to it (even though it can be done in one evening by googling around alot)

So to clarify my previous question, is this what is needed if you want ETNA running on a home-server?

In that case I would like to recommend the install-tool XAMPP that help exactly with setting up the Apache-PHP-MySQL stack (+ several other things if needed, that can optionally be added by XAMPP):

http://www.apachefriends.org/en/xampp.html

Also, Rifraf: If you install all this "crap" on your homecomputer, it will install as services/daemons and will (normally) be run all the time when your computer is started. If you want to keep your computer clean you could think about using virtualization (i.e. create a virtual computer inside your actual computer) with these servers installed. That way you can decide for yourself when to start/stop the server and when it's not running your real computer will not be cluttered down with running processes:

check http://www.virtualbox.org/ for virtualization of the server,if you're interested.


RifRaf(Posted 2009) [#12]
Thanks guys,
ill look into all of this


RepeatUntil(Posted 2009) [#13]
Yes, for ETNA, you need to have php + mysql on the server (it was already installed by my provider, so that was easy for me!). On my local computer, I have installed easyphp (http://www.easyphp.org/) and this is very simple to install and run.


RifRaf(Posted 2009) [#14]
RepeatUntil, -(or anyone else )

hm.. i cant seem to connect. Does the database have to have a primary key set ?
I created the DB and set it up though an applet my hosting provider has on thier website, using the fields you listed

database is ttusers, username is ttuser
the connection bit is
//connect
$conn = mysql_connect("localhost","ttuser","<password>") or die("Could not connect : " . mysql_error());
mysql_select_db("ttusers") Or die("Could not select database");


a shot of the setup page, i have game set as a primary key. but I have tried it with and without this and it ETNA still reports failure to submit a server in the example bb



and this is the entire php unmodified aside from the connection bit added at the end.

Any ideas what I may be doing wrong?

<?php
// Code by Mark Sibly

//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();
}
//connect
$conn = mysql_connect("localhost","ttuser","<password>") or die("Could not connect : " . mysql_error());
mysql_select_db("ttusers") Or die("Could not select database");

//setup some useful globals
if ($_SERVER["HTTP_X_FORWARDED_FOR"]) {
	$ip   = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else {
	$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();

?>




RepeatUntil(Posted 2009) [#15]
Hi RifRaf,
sorry, just see your message now. Do you still have the problem? This does not related to ETNA. To check this, run the command by hand in your internet browser (eg http://mysite.com/myscript.php?get=1) and see if this works. Probably not, you will have to see what is wrong in your php or mysql files. Don't be afraid to put print messages in the php to see where is the problem....


RifRaf(Posted 2009) [#16]
Thaks, loading the php in my IE it runs the final line

default:echo "ERROR\n";
and simply echos error in the browser.


RepeatUntil(Posted 2009) [#17]
OK, could you give us the exact command you ran in IE? Apparently, you forgot to have a "opt" option in your command.
In the php, you have:
$opt=array_key_exists("opt",$_GET) ? $_GET["opt"] : "";

and if opt is not provided in the command, then you arrive here:
switch( $opt ){
...
default:echo "ERROR\n";
}

So this error has nothing to do with ETNA or even mySQL. You should make this work first, check your command...