GNET php coding / Alt-Tab

Blitz3D Forums/Blitz3D Programming/GNET php coding / Alt-Tab

Banshee(Posted 2006) [#1]
I have modified my GNET to incude a string holding the number of players on the server and it works very well, but i'd also like to include the total servers/players on my web page, infact I already am but it does not quite work right.

http://sailing.bansheestudios.com/

Current the information isn't cleared and it's showing 1 server and 4 players from my last test, this is ok I am sure I can figure that bit out. However the count seems to break when I have more than 1 server, although this is hard to test as I need more than one IP to do it!

Also I would like to make the check detect what the game is, as currently I am working on two games with GNET and the servers/players reported shows both games total.

This is my current script (I have removed database login details)

	$_server = "";
	$_dbname = "";
	$_usname = "";
	$_paswrd = "";
	$_conect = mysql_connect($_server, $_usname, $_paswrd) or die( mysql_error() );
	mysql_select_db($_dbname, $_conect);

	//return a list of all servers
	function list_servers(){
		$res=mysql_query( "select players from gnet_servers order by t_time desc" );

		//Debug content of row
		while( $row=mysql_fetch_row($res) ){
			$totalPlayers=$totalPlayers+$row[0];
			//$totalPlayers=$totalPlayers+sum($row[0]);
			//$totalPlayers=$totalPlayers+$_GET["players"]
		}

		$totalServers=count($row);
		echo( "Servers: " );
		echo( $totalServers );
		echo( "<br>" );
		echo( "Players: ");
		echo( $totalPlayers );

		exit();
	}



	//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"] : "";

	//$players=array_key_exists("players",$_GET) ? $_GET["players"] : "";

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

	//begin header...
	header( "content-type: text/html; cache-control: no-cache" );

	switch( $opt ){
		case "list": 
			list_servers() ;
			break ;
		default:
			list_servers();
			break;
	}

	exit();


Also whilst i'm at it i've searched through the forums and found lots of stuff on disabling alt-tab, but I would like to make alt-tab work with one of my programs, it's a mod for the sim LiveForSpeed which runs full screen and can flip into windowed mode (and back again), my mod stays in a window in the background but on some systems when you flip LFS into windowed mode my app just shows a black screen.

How can I detect if i've lost my spot on the graphics card RAM and what do I have to do to reinitialise everything please?


Ricky Smith(Posted 2006) [#2]
Maybe adding a 'where' clause like:
select players from gnet_servers where server=$myserver and game=$mygame order by t_time desc

And then looping the query for each server.
Of course the fields 'server' and 'game' would have to exist in the table. You could hardcode these values as parameters or they could be read from another table(s).


Banshee(Posted 2006) [#3]
Thanks smiff, that looks like it's what I need to sort out the game selection. Is my method of reporting the total player and server count correct? It's hard to test without multiple IP addresses (GNET culls any duplicate servers I make) but I think it doesn't work right.

Does anyone have any ideas how to make Alt-Tab work rather than just blocking it from working? I need to detect when the display has blacked out and I dont know how :/

Thanks.


Ricky Smith(Posted 2006) [#4]

Is my method of reporting the total player and server count correct?


I find using "select count(*) from tablename where (condition)" works better for me to get this type of info .
Haven't a clue re: the Alt-Tab sorry.


BlackJumper(Posted 2006) [#5]
The next version of StickyKeys will have the option of querying the dll to find what has been blocked. Unfortunately, I have zero time for coding available atm, so don't hold your breath. I may get some time towards the end of October... but no promises ;-)

I guess you could check to see if Alt-TAB has been pressed and then force the system to refresh all graphics - not sure exactly how this would work, but I do seem to recall a solution for this about a year ago (I think it might be in the Bugs forum.)


Banshee(Posted 2006) [#6]
I found a solution :)

user32.decls
.lib "user32.dll"
api_GetActiveWindow% () : "GetActiveWindow"

Function DetectMinimise()
	window=api_GetActiveWindow()
	If window<>myWindow
		If Not minimised
			minimised=True
		EndIf
	Else
		If minimised
			minimised=0
			FreeImage menu
			Delay 250
			Graphics 640,480,0,2
			menu=LoadImage("ui\menu.jpg")
			For b=1 To 6
				button(b)=LoadImage("ui\button"+b+".tga")
			Next
		EndIf
	EndIf
End Function


Now I just need to make it store and restore the window position, which i've not quite managed yet.